Skip to content

Commit 4552f50

Browse files
committed
added a version of into_variant
1 parent d7edc9b commit 4552f50

10 files changed

+472
-2
lines changed

docs/questions.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ likely observable.
2424
- [exec.just] Otherwise after p2.3 is missing <ts...>
2525
- [exec.run.loop.types] p9.1: "refers remains" -> "refers to remains"
2626
- [exec.run.loop.types] p9.2: "get_stop_token(REC(o))": REC is a receiver, any
27-
environment would be attached to get_env(REC(o)).
27+
environment would be attached to get_env(REC(o)).
28+
- [exec.into.variant] p2: the sender argument to into_variant really needs to
29+
have completion_signatures defined - should the constaint be sender_in
30+
instead of sender? oh, actually, only the result of transform_sender needs
31+
to be a sender_in!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// include/beman/execution26/detail/child_type.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_CHILD_TYPE
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_CHILD_TYPE
6+
7+
#include <cstddef>
8+
#include <type_traits>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace beman::execution26::detail
13+
{
14+
template <typename Sender, ::std::size_t I = 0u>
15+
using child_type = decltype(::std::declval<Sender>().template get<I + 2>());
16+
}
17+
18+
// ----------------------------------------------------------------------------
19+
20+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// include/beman/execution26/detail/into_variant.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_INTO_VARIANT
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_INTO_VARIANT
6+
7+
#include <beman/execution26/detail/child_type.hpp>
8+
#include <beman/execution26/detail/completion_signatures_for.hpp>
9+
#include <beman/execution26/detail/default_impls.hpp>
10+
#include <beman/execution26/detail/decayed_tuple.hpp>
11+
#include <beman/execution26/detail/env_of_t.hpp>
12+
#include <beman/execution26/detail/error_types_of_t.hpp>
13+
#include <beman/execution26/detail/get_domain_early.hpp>
14+
#include <beman/execution26/detail/impls_for.hpp>
15+
#include <beman/execution26/detail/make_sender.hpp>
16+
#include <beman/execution26/detail/meta_combine.hpp>
17+
#include <beman/execution26/detail/sender.hpp>
18+
#include <beman/execution26/detail/sender_in.hpp>
19+
#include <beman/execution26/detail/sends_stopped.hpp>
20+
#include <beman/execution26/detail/set_error.hpp>
21+
#include <beman/execution26/detail/set_value.hpp>
22+
#include <beman/execution26/detail/transform_sender.hpp>
23+
#include <beman/execution26/detail/value_types_of_t.hpp>
24+
25+
#include <concepts>
26+
#include <exception>
27+
#include <type_traits>
28+
#include <utility>
29+
30+
// ----------------------------------------------------------------------------
31+
32+
namespace beman::execution26::detail
33+
{
34+
struct into_variant_t
35+
{
36+
template <::beman::execution26::sender Sender>
37+
auto operator()(Sender&& sender) const
38+
{
39+
auto domain{::beman::execution26::detail::get_domain_early(sender)};
40+
(void)domain;
41+
return
42+
::beman::execution26::detail::make_sender(*this, {}, ::std::forward<Sender>(sender))
43+
;
44+
//return ::beman::execution26::transform_sender(
45+
// ::std::move(domain),
46+
// ::beman::execution26::detail::make_sender(*this, {}, ::std::forward<Sender>(sender))
47+
//);
48+
}
49+
};
50+
51+
template<>
52+
struct impls_for<::beman::execution26::detail::into_variant_t>
53+
: ::beman::execution26::detail::default_impls
54+
{
55+
static constexpr auto get_state
56+
= []<typename Sender, typename Receiver>(Sender&&, Receiver&&) noexcept
57+
-> ::std::type_identity<
58+
::beman::execution26::value_types_of_t<
59+
::beman::execution26::detail::child_type<Sender>,
60+
::beman::execution26::env_of_t<Receiver>
61+
>
62+
>
63+
{
64+
return {};
65+
};
66+
static constexpr auto complete
67+
= []<typename State, typename Tag, typename... Args>
68+
(auto, State, auto& receiver, Tag, Args&&... args) noexcept
69+
-> void
70+
{
71+
if constexpr (::std::same_as<Tag, ::beman::execution26::set_value_t>)
72+
{
73+
using variant_type = typename State::type;
74+
using tuple_type = ::beman::execution26::detail::decayed_tuple<Args...>;
75+
try
76+
{
77+
if constexpr (sizeof...(Args) == 0u)
78+
::beman::execution26::set_value(
79+
::std::move(receiver)
80+
);
81+
else
82+
::beman::execution26::set_value(
83+
::std::move(receiver),
84+
variant_type(tuple_type{::std::forward<Args>(args)...})
85+
);
86+
}
87+
catch(...)
88+
{
89+
::beman::execution26::set_error(
90+
::std::move(receiver),
91+
::std::current_exception()
92+
);
93+
}
94+
95+
}
96+
else
97+
{
98+
Tag()(::std::move(receiver), ::std::forward<Args>(args)...);
99+
}
100+
};
101+
};
102+
103+
template <typename Sender, typename State, typename Env>
104+
struct completion_signatures_for_impl<
105+
::beman::execution26::detail::basic_sender<
106+
::beman::execution26::detail::into_variant_t,
107+
State,
108+
Sender
109+
>,
110+
Env
111+
>
112+
{
113+
using variant_type = ::beman::execution26::value_types_of_t<Sender, Env>;
114+
using value_types = ::std::conditional_t<
115+
::std::same_as<variant_type, ::beman::execution26::detail::empty_variant>,
116+
::beman::execution26::completion_signatures<>,
117+
::beman::execution26::completion_signatures<
118+
::beman::execution26::set_value_t(variant_type)
119+
>
120+
>;
121+
template <typename... E>
122+
using make_error_types
123+
= ::beman::execution26::completion_signatures<::beman::execution26::set_error_t(E)...>;
124+
125+
using error_types
126+
= ::beman::execution26::error_types_of_t<
127+
Sender,
128+
Env,
129+
make_error_types
130+
>;
131+
using stopped_types
132+
= ::std::conditional_t<
133+
::beman::execution26::sends_stopped<Sender, Env>,
134+
::beman::execution26::completion_signatures<::beman::execution26::set_stopped_t()>,
135+
::beman::execution26::completion_signatures<>
136+
>;
137+
using type = ::beman::execution26::detail::meta::combine<
138+
value_types,
139+
::beman::execution26::detail::meta::combine<error_types, stopped_types>
140+
>;
141+
};
142+
}
143+
144+
namespace beman::execution26
145+
{
146+
using into_variant_t = ::beman::execution26::detail::into_variant_t;
147+
inline constexpr into_variant_t into_variant{};
148+
}
149+
150+
// ----------------------------------------------------------------------------
151+
152+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// include/beman/execution26/detail/meta_combine.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_META_COMBINE
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_META_COMBINE
6+
7+
#include <beman/execution26/detail/type_list.hpp>
8+
#include <type_traits>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace beman::execution26::detail::meta::detail
13+
{
14+
template <typename, typename> struct combine;
15+
16+
template <template <typename...> class L0, typename... T0,
17+
template <typename...> class L1, typename... T1>
18+
struct combine<L0<T0...>, L1<T1...>>
19+
{
20+
using type = L0<T0..., T1...>;
21+
};
22+
}
23+
24+
namespace beman::execution26::detail::meta
25+
{
26+
template <typename L0, typename L1>
27+
using combine
28+
= ::beman::execution26::detail::meta::detail::combine<L0, L1>::type;
29+
}
30+
31+
// ----------------------------------------------------------------------------
32+
33+
#endif

include/beman/execution26/detail/product_type.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace beman::execution26::detail
3838
static auto element_get(
3939
::beman::execution26::detail::product_type_element<J, S>&& self)
4040
noexcept
41-
-> S&&
41+
-> S
4242
{
4343
return ::std::move(self.value);
4444
}

src/beman/execution26/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ target_sources(${TARGET_LIBRARY}
3131
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/call_result_t.hpp
3232
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/callable.hpp
3333
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/check_type_alias_exist.hpp
34+
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/child_type.hpp
3435
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/common.hpp
3536
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/completion_domain.hpp
3637
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/completion_signature.hpp
@@ -71,11 +72,13 @@ target_sources(${TARGET_LIBRARY}
7172
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/indices_for.hpp
7273
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/indirect_meta_apply.hpp
7374
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/inplace_stop_source.hpp
75+
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/into_variant.hpp
7476
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/join_env.hpp
7577
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/just.hpp
7678
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/make_env.hpp
7779
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/make_sender.hpp
7880
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/matching_sig.hpp
81+
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_combine.hpp
7982
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_contains.hpp
8083
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_filter.hpp
8184
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_prepend.hpp

src/beman/execution26/tests/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
list(APPEND execution_tests
5+
meta-combine.pass
6+
exec-into-variant.pass
57
exec-run-loop-types.pass
68
exec-run-loop-general.pass
79
exec-just.pass

0 commit comments

Comments
 (0)