-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathinto_variant.hpp
More file actions
149 lines (136 loc) · 6.54 KB
/
into_variant.hpp
File metadata and controls
149 lines (136 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// include/beman/execution/detail/into_variant.hpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_INTO_VARIANT
#define INCLUDED_BEMAN_EXECUTION_DETAIL_INTO_VARIANT
#include <beman/execution/detail/common.hpp>
#ifdef BEMAN_HAS_IMPORT_STD
import std;
#else
#include <concepts>
#include <exception>
#include <type_traits>
#include <utility>
#endif
#ifdef BEMAN_HAS_MODULES
import beman.execution.detail.basic_sender;
import beman.execution.detail.child_type;
import beman.execution.detail.completion_signatures;
import beman.execution.detail.completion_signatures_for;
import beman.execution.detail.decayed_tuple;
import beman.execution.detail.default_impls;
import beman.execution.detail.env_of_t;
import beman.execution.detail.error_types_of_t;
import beman.execution.detail.get_domain_early;
import beman.execution.detail.impls_for;
import beman.execution.detail.make_sender;
import beman.execution.detail.meta.combine;
import beman.execution.detail.sender;
import beman.execution.detail.sends_stopped;
import beman.execution.detail.set_error;
import beman.execution.detail.set_stopped;
import beman.execution.detail.set_value;
import beman.execution.detail.transform_sender;
import beman.execution.detail.value_types_of_t;
import beman.execution.detail.variant_or_empty;
#else
#include <beman/execution/detail/child_type.hpp>
#include <beman/execution/detail/completion_signatures_for.hpp>
#include <beman/execution/detail/decayed_tuple.hpp>
#include <beman/execution/detail/default_impls.hpp>
#include <beman/execution/detail/env_of_t.hpp>
#include <beman/execution/detail/error_types_of_t.hpp>
#include <beman/execution/detail/get_domain_early.hpp>
#include <beman/execution/detail/impls_for.hpp>
#include <beman/execution/detail/make_sender.hpp>
#include <beman/execution/detail/meta_combine.hpp>
#include <beman/execution/detail/sender.hpp>
#include <beman/execution/detail/sends_stopped.hpp>
#include <beman/execution/detail/set_error.hpp>
#include <beman/execution/detail/set_value.hpp>
#include <beman/execution/detail/transform_sender.hpp>
#include <beman/execution/detail/value_types_of_t.hpp>
#endif
// ----------------------------------------------------------------------------
namespace beman::execution::detail {
struct into_variant_t {
template <::beman::execution::sender Sender>
auto operator()(Sender&& sender) const {
// auto domain{::beman::execution::detail::get_domain_early(sender)};
//(void)domain;
return ::beman::execution::detail::make_sender(*this, {}, ::std::forward<Sender>(sender));
// return ::beman::execution::transform_sender(
// ::std::move(domain),
// ::beman::execution::detail::make_sender(*this, {}, ::std::forward<Sender>(sender))
//);
}
private:
template <typename... E>
using make_error_types = ::beman::execution::completion_signatures<::beman::execution::set_error_t(E)...>;
private:
template <typename, typename>
struct get_signatures;
template <::beman::execution::sender Child, typename State, typename Env>
struct get_signatures<
::beman::execution::detail::basic_sender<::beman::execution::detail::into_variant_t, State, Child>,
Env> {
static consteval auto get() {
using variant_type = ::beman::execution::value_types_of_t<Child, Env>;
using value_types = ::std::conditional_t<
::std::same_as<variant_type, ::beman::execution::detail::empty_variant>,
::beman::execution::completion_signatures<>,
::beman::execution::completion_signatures<::beman::execution::set_value_t(variant_type)>>;
using error_types = ::beman::execution::error_types_of_t<Child, Env, make_error_types>;
using stopped_types =
::std::conditional_t<::beman::execution::sends_stopped<Child, Env>,
::beman::execution::completion_signatures<::beman::execution::set_stopped_t()>,
::beman::execution::completion_signatures<>>;
using type = ::beman::execution::detail::meta::
combine<value_types, ::beman::execution::detail::meta::combine<error_types, stopped_types>>;
return type{};
}
};
public:
template <::beman::execution::sender Sender, typename Env>
static consteval auto get_completion_signatures() {
return get_signatures<::std::remove_cvref_t<Sender>, Env>::get();
}
struct impls_for : ::beman::execution::detail::default_impls {
struct get_state_impl {
template <typename Sender, typename Receiver>
auto operator()(Sender&&, Receiver&&) const noexcept -> ::std::type_identity<
::beman::execution::value_types_of_t<::beman::execution::detail::child_type<Sender>,
::beman::execution::env_of_t<Receiver>>> {
return {};
}
};
static constexpr auto get_state{get_state_impl{}};
struct complete_impl {
template <typename State, typename Tag, typename... Args>
auto operator()(auto, State, auto& receiver, Tag, Args&&... args) const noexcept -> void {
if constexpr (::std::same_as<Tag, ::beman::execution::set_value_t>) {
using variant_type = typename State::type;
using tuple_type = ::beman::execution::detail::decayed_tuple<Args...>;
try {
if constexpr (sizeof...(Args) == 0u)
::beman::execution::set_value(::std::move(receiver));
else
::beman::execution::set_value(::std::move(receiver),
variant_type(tuple_type{::std::forward<Args>(args)...}));
} catch (...) {
::beman::execution::set_error(::std::move(receiver), ::std::current_exception());
}
} else {
Tag()(::std::move(receiver), ::std::forward<Args>(args)...);
}
}
};
static constexpr auto complete{complete_impl{}};
};
};
} // namespace beman::execution::detail
namespace beman::execution {
using into_variant_t = ::beman::execution::detail::into_variant_t;
inline constexpr into_variant_t into_variant{};
} // namespace beman::execution
// ----------------------------------------------------------------------------
#endif // INCLUDED_BEMAN_EXECUTION_DETAIL_INTO_VARIANT