|
23 | 23 | // ---------------------------------------------------------------------------- |
24 | 24 |
|
25 | 25 | namespace beman::execution::detail { |
26 | | - template <typename> struct non_throwing_args_copy; |
27 | | - template <typename Rc, typename... A> struct non_throwing_args_copy<Rc(A...)> { |
28 | | - static constexpr bool value = (true && ... && ::std::is_nothrow_constructible_v<::std::decay_t<A>, A> ); |
29 | | - }; |
30 | | - template <typename S> inline constexpr bool non_throwing_args_copy_v{non_throwing_args_copy<S>::value}; |
| 26 | +template <typename> |
| 27 | +struct non_throwing_args_copy; |
| 28 | +template <typename Rc, typename... A> |
| 29 | +struct non_throwing_args_copy<Rc(A...)> { |
| 30 | + static constexpr bool value = (true && ... && ::std::is_nothrow_constructible_v<::std::decay_t<A>, A>); |
| 31 | +}; |
| 32 | +template <typename S> |
| 33 | +inline constexpr bool non_throwing_args_copy_v{non_throwing_args_copy<S>::value}; |
31 | 34 |
|
32 | | - template <typename Completions> struct spawn_future_state_base; |
33 | | - template <typename... Sigs> |
34 | | - struct spawn_future_state_base<::beman::execution::completion_signatures<Sigs...>> { |
35 | | - static constexpr bool has_non_throwing_args_copy = (true && ... && non_throwing_args_copy_v<Sigs>); |
36 | | - using variant_t = ::beman::execution::detail::meta::unique< |
37 | | - ::std::conditional_t< |
38 | | - has_non_throwing_args_copy, |
39 | | - ::std::variant<::std::monostate, ::beman::execution::detail::as_tuple_t<Sigs>...>, |
40 | | - ::std::variant<::std::monostate, ::std::tuple<::beman::execution::set_error_t, ::std::exception_ptr>, ::beman::execution::detail::as_tuple_t<Sigs>...> |
41 | | - > |
42 | | - >; |
| 35 | +template <typename Completions> |
| 36 | +struct spawn_future_state_base; |
| 37 | +template <typename... Sigs> |
| 38 | +struct spawn_future_state_base<::beman::execution::completion_signatures<Sigs...>> { |
| 39 | + static constexpr bool has_non_throwing_args_copy = (true && ... && non_throwing_args_copy_v<Sigs>); |
| 40 | + using variant_t = ::beman::execution::detail::meta::unique< |
| 41 | + ::std::conditional_t<has_non_throwing_args_copy, |
| 42 | + ::std::variant<::std::monostate, ::beman::execution::detail::as_tuple_t<Sigs>...>, |
| 43 | + ::std::variant<::std::monostate, |
| 44 | + ::std::tuple<::beman::execution::set_error_t, ::std::exception_ptr>, |
| 45 | + ::beman::execution::detail::as_tuple_t<Sigs>...>>>; |
43 | 46 |
|
44 | | - variant_t result{}; |
45 | | - virtual ~spawn_future_state_base() = default; |
46 | | - virtual auto complete() noexcept -> void = 0; |
47 | | - }; |
| 47 | + variant_t result{}; |
| 48 | + virtual ~spawn_future_state_base() = default; |
| 49 | + virtual auto complete() noexcept -> void = 0; |
| 50 | +}; |
48 | 51 |
|
49 | | - template <typename Completions> |
50 | | - struct spawn_future_receiver { |
51 | | - using receiver_concept = ::beman::execution::receiver_t; |
52 | | - using state_t = ::beman::execution::detail::spawn_future_state_base<Completions>; |
| 52 | +template <typename Completions> |
| 53 | +struct spawn_future_receiver { |
| 54 | + using receiver_concept = ::beman::execution::receiver_t; |
| 55 | + using state_t = ::beman::execution::detail::spawn_future_state_base<Completions>; |
53 | 56 |
|
54 | | - state_t* state{}; |
| 57 | + state_t* state{}; |
55 | 58 |
|
56 | | - template <typename... A> |
57 | | - auto set_value(A&&... a) && noexcept -> void { |
58 | | - this->set_complete<::beman::execution::set_value_t>(::std::forward<A>(a)...); |
59 | | - } |
60 | | - template <typename E> |
61 | | - auto set_error(E&& e) && noexcept -> void { |
62 | | - this->set_complete<::beman::execution::set_error_t>(::std::forward<E>(e)); |
63 | | - } |
64 | | - auto set_stopped() && noexcept -> void { |
65 | | - this->set_complete<::beman::execution::set_stopped_t>(); |
66 | | - } |
| 59 | + template <typename... A> |
| 60 | + auto set_value(A&&... a) && noexcept -> void { |
| 61 | + this->set_complete<::beman::execution::set_value_t>(::std::forward<A>(a)...); |
| 62 | + } |
| 63 | + template <typename E> |
| 64 | + auto set_error(E&& e) && noexcept -> void { |
| 65 | + this->set_complete<::beman::execution::set_error_t>(::std::forward<E>(e)); |
| 66 | + } |
| 67 | + auto set_stopped() && noexcept -> void { this->set_complete<::beman::execution::set_stopped_t>(); } |
67 | 68 |
|
68 | | - template <typename Tag, typename... T> |
69 | | - auto set_complete(T&&... t) noexcept { |
70 | | - try { |
71 | | - this->state->result.template emplace<::beman::execution::detail::decayed_tuple<Tag, T...>>(Tag(), ::std::forward<T>(t)...); |
| 69 | + template <typename Tag, typename... T> |
| 70 | + auto set_complete(T&&... t) noexcept { |
| 71 | + try { |
| 72 | + this->state->result.template emplace<::beman::execution::detail::decayed_tuple<Tag, T...>>( |
| 73 | + Tag(), ::std::forward<T>(t)...); |
| 74 | + } catch (...) { |
| 75 | + if constexpr (!state_t::has_non_throwing_args_copy) { |
| 76 | + this->state->result |
| 77 | + .template emplace<::std::tuple<::beman::execution::set_error_t, ::std::exception_ptr>>( |
| 78 | + ::beman::execution::set_error_t{}, ::std::current_exception()); |
72 | 79 | } |
73 | | - catch (...) { |
74 | | - if constexpr (!state_t::has_non_throwing_args_copy) { |
75 | | - this->state->result.template emplace<::std::tuple<::beman::execution::set_error_t, ::std::exception_ptr>>(::beman::execution::set_error_t{}, ::std::current_exception()); |
76 | | - } |
77 | | - } |
78 | | - this->state->complete(); |
79 | 80 | } |
80 | | - }; |
| 81 | + this->state->complete(); |
| 82 | + } |
| 83 | +}; |
81 | 84 |
|
82 | | - class spawn_future_t { |
83 | | - public: |
84 | | - template <::beman::execution::sender Sndr, ::beman::execution::async_scope_token Tok, typename Env> |
85 | | - requires ::beman::execution::detail::queryable<::std::remove_cvref_t<Env>> |
86 | | - auto operator()(Sndr&&, Tok&&, Env&&) const { |
87 | | - } |
88 | | - template <::beman::execution::sender Sndr, ::beman::execution::async_scope_token Tok> |
89 | | - auto operator()(Sndr&& sndr, Tok&& tok) const { |
90 | | - return (*this)(::std::forward<Sndr>(sndr), ::std::forward<Tok>(tok), ::beman::execution::empty_env{}); |
91 | | - } |
92 | | - }; |
93 | | -} |
| 85 | +class spawn_future_t { |
| 86 | + public: |
| 87 | + template <::beman::execution::sender Sndr, ::beman::execution::async_scope_token Tok, typename Env> |
| 88 | + requires ::beman::execution::detail::queryable<::std::remove_cvref_t<Env>> |
| 89 | + auto operator()(Sndr&&, Tok&&, Env&&) const {} |
| 90 | + template <::beman::execution::sender Sndr, ::beman::execution::async_scope_token Tok> |
| 91 | + auto operator()(Sndr&& sndr, Tok&& tok) const { |
| 92 | + return (*this)(::std::forward<Sndr>(sndr), ::std::forward<Tok>(tok), ::beman::execution::empty_env{}); |
| 93 | + } |
| 94 | +}; |
| 95 | +} // namespace beman::execution::detail |
94 | 96 |
|
95 | 97 | namespace beman::execution { |
96 | | - using spawn_future_t = ::beman::execution::detail::spawn_future_t; |
97 | | - inline constexpr spawn_future_t spawn_future{}; |
98 | | -} |
| 98 | +using spawn_future_t = ::beman::execution::detail::spawn_future_t; |
| 99 | +inline constexpr spawn_future_t spawn_future{}; |
| 100 | +} // namespace beman::execution |
99 | 101 |
|
100 | 102 | // ---------------------------------------------------------------------------- |
101 | 103 |
|
|
0 commit comments