diff options
author | Determinant <[email protected]> | 2018-06-25 20:41:08 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2018-06-25 20:41:08 -0400 |
commit | 304f38ec4e602c81b45b35e5e9734124bcf6fdcf (patch) | |
tree | 0d1cf3eae4d101cd31958e23e3cbfc833b69fc93 | |
parent | d97769fc2b9b54c6fe8235b0fcd0cd4a0b7e1fa7 (diff) |
add constructor with no args and operator=
-rw-r--r-- | promise.hpp | 20 |
1 files 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<typename PList> friend promise_t all(const PList &promise_list); template<typename PList> friend promise_t race(const PList &promise_list); - promise_t() = delete; - promise_t &operator=(const promise_t &other) = delete; + inline promise_t(); template<typename Func> 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; |