From 9da19de63af8876e8cfaed4abe5a9a6f957986a7 Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 7 Feb 2018 20:42:39 -0500 Subject: ... --- promise.hpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/promise.hpp b/promise.hpp index 97a1400..7831a1c 100644 --- a/promise.hpp +++ b/promise.hpp @@ -121,11 +121,13 @@ namespace promise { ArgType>::value>; class Promise; - class promise_t: std::shared_ptr { + class promise_t: public std::shared_ptr { public: friend Promise; template friend promise_t all(PList promise_list); template friend promise_t race(PList promise_list); + + promise_t() = delete; template promise_t(Func callback): std::shared_ptr(std::make_shared()) { @@ -384,11 +386,11 @@ namespace promise { } }; - template promise_t all(PList promise_list) { - return promise_t([promise_list] (promise_t npm) { + template promise_t all(const PList &promise_list) { + return promise_t([&promise_list] (promise_t npm) { auto size = std::make_shared(promise_list.size()); auto results = std::make_shared(); - if (!size) PROMISE_ERR_MISMATCH_TYPE; + if (!*size) PROMISE_ERR_MISMATCH_TYPE; results->resize(*size); size_t idx = 0; for (const auto &pm: promise_list) { @@ -404,8 +406,8 @@ namespace promise { }); } - template promise_t race(PList promise_list) { - return promise_t([promise_list] (promise_t npm) { + template promise_t race(const PList &promise_list) { + return promise_t([&promise_list] (promise_t npm) { for (const auto &pm: promise_list) { pm->then([npm](pm_any_t result) {npm->resolve(result);}, [npm](pm_any_t reason) {npm->reject(reason);}); @@ -448,7 +450,6 @@ namespace promise { typename enable_if_return::type * = nullptr, typename function_traits::non_empty_arg * = nullptr> constexpr auto gen_any_callback(Func f) { - using func_t = callback_types; return [f](pm_any_t v) mutable {f(v);}; } -- cgit v1.2.3-70-g09d2