Skip to content

Commit c2ef806

Browse files
committed
fixed the completion signatures for spawn_future
1 parent 15e99d6 commit c2ef806

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// include/beman/execution/detail/meta_contain_same.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_META_CONTAIN_SAME
5+
#define INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_META_CONTAIN_SAME
6+
7+
#include <beman/execution/detail/meta_contains.hpp>
8+
9+
// ----------------------------------------------------------------------------
10+
11+
namespace beman::execution::detail::meta {
12+
template <typename, typename>
13+
struct contain_same_t;
14+
template <template <typename...> class L0, typename... M0, template <typename...> class L1, typename... M1>
15+
struct contain_same_t<L0<M0...>, L1<M1...>> {
16+
static constexpr bool value =
17+
((sizeof...(M0) == sizeof...(M1)) && ... && ::beman::execution::detail::meta::contains<M0, M1...>);
18+
};
19+
20+
template <typename S0, typename S1>
21+
inline constexpr bool contain_same = contain_same_t<S0, S1>::value;
22+
23+
} // namespace beman::execution::detail::meta
24+
25+
// ----------------------------------------------------------------------------
26+
27+
#endif

include/beman/execution/detail/spawn_future.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,21 @@ using future_spawned_sender = decltype(::beman::execution::write_env(
105105
::std::declval<::beman::execution::inplace_stop_token>()),
106106
::std::declval<Env>()));
107107

108+
template <::beman::execution::sender Sndr, typename Env>
109+
using spawn_future_sigs = ::beman::execution::detail::meta::unique<::beman::execution::detail::meta::prepend<
110+
::beman::execution::set_stopped_t(),
111+
::beman::execution::completion_signatures_of_t<::beman::execution::detail::future_spawned_sender<Sndr, Env>>>>;
112+
108113
template <typename Allocator,
109114
::beman::execution::async_scope_token Token,
110115
::beman::execution::sender Sndr,
111116
typename Env>
112117
struct spawn_future_state
113-
: ::beman::execution::detail::spawn_future_state_base<::beman::execution::completion_signatures_of_t<
114-
::beman::execution::detail::future_spawned_sender<Sndr, Env>>> {
118+
: ::beman::execution::detail::spawn_future_state_base<::beman::execution::detail::spawn_future_sigs<Sndr, Env>> {
115119
using alloc_t = typename ::std::allocator_traits<Allocator>::template rebind_alloc<spawn_future_state>;
116120
using traits_t = ::std::allocator_traits<alloc_t>;
117121
using spawned_sender_t = ::beman::execution::detail::future_spawned_sender<Sndr, Env>;
118-
using sigs_t = ::beman::execution::completion_signatures_of_t<spawned_sender_t>;
122+
using sigs_t = ::beman::execution::detail::spawn_future_sigs<Sndr, Env>;
119123
using receiver_t = ::beman::execution::detail::spawn_future_receiver<sigs_t>;
120124
static_assert(::beman::execution::sender<spawned_sender_t>);
121125
static_assert(::beman::execution::receiver<receiver_t>);
@@ -259,6 +263,14 @@ class spawn_future_t {
259263
}
260264
};
261265

266+
template <typename State, typename Deleter, typename Env>
267+
struct completion_signatures_for_impl<
268+
::beman::execution::detail::basic_sender<::beman::execution::detail::spawn_future_t,
269+
::std::unique_ptr<State, Deleter>>,
270+
Env> {
271+
using type = typename State::sigs_t;
272+
};
273+
262274
template <>
263275
struct impls_for<spawn_future_t> : ::beman::execution::detail::default_impls {
264276
static constexpr auto start{[](auto& state, auto& rcvr) noexcept -> void { state->consume(rcvr); }};

src/beman/execution/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ target_sources(
117117
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/make_sender.hpp
118118
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/matching_sig.hpp
119119
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/meta_combine.hpp
120+
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/meta_contain_same.hpp
120121
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/meta_contains.hpp
121122
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/meta_filter.hpp
122123
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/meta_prepend.hpp

tests/beman/execution/exec-spawn-future.test.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <beman/execution/detail/inplace_stop_source.hpp>
1414
#include <beman/execution/detail/just.hpp>
1515
#include <beman/execution/detail/then.hpp>
16+
#include <beman/execution/detail/get_completion_signatures.hpp>
17+
#include <beman/execution/detail/meta_contain_same.hpp>
1618
#include <test/execution.hpp>
1719
#include <concepts>
1820

@@ -35,9 +37,8 @@ static_assert(not test_std::sender<non_sender>);
3537

3638
template <typename... T>
3739
struct sender {
38-
using sender_concept = test_std::sender_t;
39-
using completion_signatures =
40-
test_std::completion_signatures<test_std::set_value_t(T...), test_std::set_stopped_t()>;
40+
using sender_concept = test_std::sender_t;
41+
using completion_signatures = test_std::completion_signatures<test_std::set_value_t(T...)>;
4142

4243
struct state_base {
4344
virtual ~state_base() = default;
@@ -387,6 +388,19 @@ auto test_spawn_future() {
387388
ASSERT(count == 1u);
388389
ASSERT(handle != nullptr);
389390
ASSERT(result == 0);
391+
#if 0
392+
using type = typename beman::execution::detail::completion_signatures_for_impl<decltype(sndr), test_std::empty_env>::type;
393+
static_assert(std::same_as<test_std::completion_signatures<test_std::set_stopped_t(), test_std::set_value_t(int), test_std::set_error_t(std::exception_ptr)>, type>);
394+
static_assert(std::same_as<
395+
test_std::completion_signatures<test_std::set_stopped_t(), test_std::set_value_t(int), test_std::set_error_t(std::exception_ptr)>,
396+
decltype(test_std::get_completion_signatures(sndr, test_std::empty_env{}))
397+
>);
398+
#endif
399+
using exp_type = test_std::completion_signatures<test_std::set_stopped_t(),
400+
test_std::set_value_t(int),
401+
test_std::set_error_t(std::exception_ptr)>;
402+
using comp_type = decltype(test_std::get_completion_signatures(std::move(sndr), test_std::empty_env{}));
403+
static_assert(test_detail::meta::contain_same<exp_type, comp_type>);
390404

391405
handle->complete(17);
392406
ASSERT(result == 0);

0 commit comments

Comments
 (0)