diff --git a/include/continuable/detail/operations/split.hpp b/include/continuable/detail/operations/split.hpp index 07855d4..1d29a95 100644 --- a/include/continuable/detail/operations/split.hpp +++ b/include/continuable/detail/operations/split.hpp @@ -36,10 +36,27 @@ #include #include #include +#include namespace cti { namespace detail { namespace operations { +template +struct operator_bool_or { + template + static bool get(O&& /*obj*/) noexcept { + return Else; + } +}; +template +struct operator_bool_or()))>> { + template + static bool get(O&& obj) noexcept { + return bool(obj); + } +}; + template class split_promise { First first_; @@ -51,34 +68,22 @@ public: } template - void operator()(Args... args) && { + void operator()(Args&&... args) && { traverse_pack( [&](auto&& promise) mutable -> void { - if (promise) { + using accessor = + operator_bool_or, true>; + if (accessor::get(promise)) { std::forward(promise)(args...); } }, std::move(promises_)); - if (first_) { + if (operator_bool_or::get(first_)) { std::move(first_)(std::forward(args)...); } } - void operator()(exception_arg_t tag, exception_t exception) && { - traverse_pack( - [&](auto&& promise) mutable -> void { - if (promise) { - std::forward(promise)(tag, exception); - } - }, - std::move(promises_)); - - if (first_) { - std::move(first_)(tag, std::move(exception)); - } - } - template void set_value(Args... args) { std::move (*this)(std::move(args)...); @@ -89,10 +94,12 @@ public: } explicit operator bool() const noexcept { - bool is_valid = bool(first_); + bool is_valid = operator_bool_or::get(first_); traverse_pack( [&](auto&& promise) mutable -> void { - if (!is_valid && bool(promise)) { + using accessor = + operator_bool_or, true>; + if (!is_valid && accessor::get(promise)) { is_valid = true; } }, diff --git a/test/unit-test/multi/test-continuable-operations-split.cpp b/test/unit-test/multi/test-continuable-operations-split.cpp index b1b2720..e21472e 100644 --- a/test/unit-test/multi/test-continuable-operations-split.cpp +++ b/test/unit-test/multi/test-continuable-operations-split.cpp @@ -46,3 +46,17 @@ TYPED_TEST(single_dimension_tests, operations_split) { all.set_value(); ASSERT_TRUE(resolved); } + +TYPED_TEST(single_dimension_tests, operations_split_plain_callback) { + promise<> all; + bool resolved = false; + + all = split(std::move(all), [&](auto&&...) { + EXPECT_FALSE(resolved); + resolved = true; + }); + + ASSERT_FALSE(resolved); + all.set_value(); + ASSERT_TRUE(resolved); +}