From 304f38ec4e602c81b45b35e5e9734124bcf6fdcf Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 25 Jun 2018 20:41:08 -0400 Subject: add constructor with no args and operator= --- promise.hpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/promise.hpp b/promise.hpp index d3cc7df..9abd149 100644 --- a/promise.hpp +++ b/promise.hpp @@ -125,15 +125,23 @@ namespace promise { class promise_t { Promise *pm; size_t *ref_cnt; + inline void clear(); public: friend Promise; template friend promise_t all(const PList &promise_list); template friend promise_t race(const PList &promise_list); - promise_t() = delete; - promise_t &operator=(const promise_t &other) = delete; + inline promise_t(); template inline promise_t(Func callback); - inline ~promise_t(); + ~promise_t() { clear(); } + + promise_t &operator=(const promise_t &other) { + clear(); + pm = other.pm; + ref_cnt = other.ref_cnt; + ++*ref_cnt; + return *this; + } promise_t(const promise_t &other): pm(other.pm), @@ -439,7 +447,11 @@ namespace promise { callback(*this); } - inline promise_t::~promise_t() { + inline promise_t::promise_t(): + pm(new Promise()), + ref_cnt(new size_t(1)) {} + + inline void promise_t::clear() { if (pm) { if (--*ref_cnt) return; -- cgit v1.2.3