Iros
 
Loading...
Searching...
No Matches
any_sender.h
Go to the documentation of this file.
1#pragma once
2
9#include "di/any/types/this.h"
28#include "di/meta/algorithm.h"
29#include "di/meta/core.h"
30#include "di/meta/language.h"
31#include "di/meta/operations.h"
32#include "di/meta/util.h"
34#include "di/util/declval.h"
36#include "di/util/move.h"
40
41namespace di::execution {
42namespace detail {
43 template<typename Rec, typename Op, typename Env>
45}
46
47template<typename Sigs, typename Env, typename Storage, typename VTablePolicy, typename Op, typename Rec>
48struct AnySenderT {
49 class Type : public Any<detail::AnySenderInterface<Rec, Op, Env>, Storage, VTablePolicy> {
50 using Base = Any<detail::AnySenderInterface<Rec, Op, Env>, Storage, VTablePolicy>;
51
53 "Receiver must be able to receive all completion signatures.");
54
55 public:
56 using is_sender = void;
57
58 using OperationState = Op;
59 using Receiver = Rec;
60
62
63 Type(Type const&) = delete;
64 auto operator=(Type const&) -> Type& = delete;
65
66 Type(Type&&) = default;
67 auto operator=(Type&&) -> Type& = default;
68
69 template<typename E>
71 Type(vocab::Unexpected<E>&& error) : Type(just_error(vocab::Error(util::move(error).error()))) {}
72
73 template<typename S, typename T = meta::RemoveCVRef<S>>
75 Type(S&& sender) {
77 this->emplace(util::forward<S>(sender));
78 } else {
79 auto result = this->emplace(util::forward<S>(sender));
80 if (!result) {
81 using ErrorSender = decltype(execution::just_error(util::declval<vocab::Error>()));
82
84 "Type-erased sender must have a large enough internal capacity to store the "
85 "error sender without allocating.");
86
87 this->emplace(execution::just_error(vocab::Error(util::move(result).error())));
88 }
89 }
90 }
91 };
92};
93
94template<concepts::ValidCompletionSignatures Sigs, typename Env = void,
98
99template<typename T>
101 class Type
102 : public AnySender<types::CompletionSignatures<meta::AsLanguageFunction<
103 SetValue, meta::Conditional<concepts::LanguageVoid<T>, meta::List<>, meta::List<T>>>>> {
104 private:
107
108 public:
109 using Base::Base;
110 using Base::operator=;
111
113
116 : Base(execution::just()) {}
117
118 template<typename U>
120 Type(U&& value) : Base(execution::just(T(util::forward<U>(value)))) {}
121
122 template<typename U, typename E>
124 Type(vocab::Expected<U, E>&& value) : Base(execution::just_or_error(util::move(value))) {}
125 };
126};
127
128template<typename T = void>
130
131namespace detail {
132 template<concepts::Sender Send, concepts::Method M,
136 auto tag_invoke(detail::ConnectFunction, M, Send&& sender, meta::TypeIdentity<Rec&&> receiver) -> R {
137 auto operation_state = R();
138
140
141 using Storage = typename R::AnyStorage;
143 operation_state.emplace(in_place_type<Op>, util::DeferConstruct([&] {
144 return execution::connect(util::forward<Send>(sender),
145 util::forward<Rec>(receiver));
146 }));
147 } else {
148 auto result = operation_state.emplace(in_place_type<Op>, util::DeferConstruct([&] {
149 return execution::connect(util::forward<Send>(sender),
150 util::forward<Rec>(receiver));
151 }));
152 if (!result) {
153 using ErrorSender = decltype(execution::just_error(util::declval<vocab::Error>()));
155
157 "Type-erased operation state must have a large enough internal capacity to store the "
158 "error operation state without allocating.");
159
160 operation_state.emplace(in_place_type<OpError>, util::DeferConstruct([&] {
161 return execution::connect(
162 execution::just_error(vocab::Error(util::move(result).error())),
163 util::forward<Rec>(receiver));
164 }));
165 }
166 }
167
168 return operation_state;
169 }
170}
171}
172
173namespace di {
176}
execution::Lazy< T >::promise_type promise_type
Definition any_sender.h:112
Type()
Definition any_sender.h:114
Type(vocab::Expected< U, E > &&value)
Definition any_sender.h:124
Type(U &&value)
Definition any_sender.h:120
Rec Receiver
Definition any_sender.h:59
detail::AnySigs< Sigs > CompletionSignatures
Definition any_sender.h:61
Type(S &&sender)
Definition any_sender.h:75
auto operator=(Type const &) -> Type &=delete
auto operator=(Type &&) -> Type &=default
Type(Type const &)=delete
void is_sender
Definition any_sender.h:56
Op OperationState
Definition any_sender.h:58
Type(vocab::Unexpected< E > &&error)
Definition any_sender.h:71
Promise promise_type
Definition lazy.h:136
Definition defer_construct.h:8
Definition expected_forward_declaration.h:8
Definition unexpected.h:14
Definition any_storable_infallibly.h:11
Definition any_storage.h:11
Definition operations.h:11
Definition operations.h:114
Definition core.h:128
Definition method.h:8
Definition operation_state.h:9
Definition receiver_of.h:25
Definition receiver.h:10
Definition sender_to.h:11
Definition sender.h:11
Definition valid_completion_signatures.h:8
meta::Type< AnyT< UserInterface, Storage, VTablePolicy > > Any
Definition any.h:294
Definition read.h:70
meta::AsTemplate< types::CompletionSignatures, meta::PushFront< meta::PushFront< meta::AsList< Sigs >, SetError(vocab::Error)>, SetStopped()> > AnySigs
Definition any_receiver.h:29
meta::List< types::Method< detail::ConnectFunction, Op(types::This &&, Rec)> > AnySenderInterface
Definition any_sender.h:44
Definition bulk.h:30
meta::Type< AnySenderT< Sigs, Env, Storage, VTablePolicy, Op, Rec > > AnySender
Definition any_sender.h:97
Any< InterfaceWithEnv< meta::List< types::Tag< execution::start > >, Env >, Storage, VTablePolicy > AnyOperationState
Definition any_operation_state.h:18
constexpr auto just_error
Definition just.h:87
constexpr auto just_or_error
Definition just_or_error.h:86
constexpr auto connect
Definition connect.h:42
meta::Type< AnySenderOfT< T > > AnySenderOf
Definition any_sender.h:129
meta::Type< AnyReceiverT< Sigs, Env, Storage, VTablePolicy > > AnyReceiver
Definition any_receiver.h:63
constexpr auto just
Definition just.h:86
typename T::template At< index > At
Definition list.h:110
detail::ConditionalHelper< value, T, U >::Type Conditional
Definition core.h:88
Type< TypeConstant< T > > TypeIdentity
This is a helper template to prevent C++ from deducing the type of template argument.
Definition core.h:32
T::Type Type
Definition core.h:26
Type< detail::LanguageFunctionReturnHelper< Fun > > LanguageFunctionReturn
Definition language.h:77
Type< detail::AsLanguageFunction< R, T > > AsLanguageFunction
Definition algorithm.h:31
decltype(execution::connect(util::declval< Send >(), util::declval< Rec >())) ConnectResult
Definition connect_result.h:7
Definition vocab.h:96
auto declval() -> meta::AddRValueReference< T >
Definition declval.h:8
StatusCode< Erased< long > > Error
Definition error.h:8
Definition zstring_parser.h:9
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
constexpr auto in_place_type
Definition in_place_type.h:12
Definition hybrid_storage.h:40
Definition maybe_inline_vtable.h:9
Definition any_sender.h:100
Definition any_sender.h:48
Definition set_value.h:6
Definition core.h:5
Definition completion_signuatures.h:7
Definition method.h:7
Definition this.h:4