Iros
 
Loading...
Searching...
No Matches
bulk.h
Go to the documentation of this file.
1#pragma once
2
18#include "di/function/invoke.h"
20#include "di/meta/algorithm.h"
21#include "di/meta/core.h"
22#include "di/meta/language.h"
23#include "di/meta/util.h"
24#include "di/meta/vocab.h"
26#include "di/util/addressof.h"
27#include "di/util/immovable.h"
28#include "di/util/move.h"
29
30namespace di::execution {
31namespace bulk_ns {
32 template<typename Shape, typename Function, typename Rec>
33 struct DataT {
34 struct Type {
35 Shape shape;
36 [[no_unique_address]] Function function;
37 [[no_unique_address]] Rec receiver;
38 };
39 };
40
41 template<typename Shape, typename Function, typename Rec>
43
44 template<typename Shape, typename Function, typename Rec>
45 struct ReceiverT {
46 struct Type : ReceiverAdaptor<Type> {
47 private:
48 using Base = ReceiverAdaptor<Type>;
49 friend Base;
50
51 public:
52 explicit Type(Data<Shape, Function, Rec>* data) : m_data(data) {}
53
54 auto base() const& -> Rec const& { return m_data->receiver; }
55 auto base() && -> Rec&& { return util::move(m_data->receiver); }
56
57 private:
58 template<typename... Args>
59 requires(concepts::Invocable<Function&, Shape, Args&...>)
60 void set_value(Args&&... args) && {
61 for (auto i = Shape(); i != m_data->shape; ++i) {
62 if constexpr (concepts::Expected<meta::InvokeResult<Function&, Shape, Args&...>>) {
63 auto result = function::invoke(m_data->function, auto(i), args...);
64 if (!result) {
65 execution::set_error(util::move(*this).base(), util::move(result).error());
66 return;
67 }
68 } else {
69 (void) function::invoke(m_data->function, auto(i), args...);
70 }
71 }
72 execution::set_value(util::move(*this).base(), util::forward<Args>(args)...);
73 }
74
76 };
77 };
78
79 template<typename Shape, typename Function, typename Rec>
81
82 template<typename Send, typename Shape, typename Function, typename Rec>
85 public:
88
89 explicit Type(Send&& sender, Shape shape, Function&& function, Rec receiver)
90 : m_data(shape, util::forward<Function>(function), util::move(receiver))
91 , m_operation(connect(util::forward<Send>(sender), Rc(util::addressof(m_data)))) {}
92
93 private:
94 friend void tag_invoke(Tag<start>, Type& self) { start(self.m_operation); }
95
96 [[no_unique_address]] Data<Shape, Function, Rec> m_data;
98 };
99 };
100
101 template<typename Send, typename Shape, typename Function, typename Rec>
103
104 template<typename Function, typename Shape>
106 template<typename... Args>
107 using Invoke = meta::InvokeResult<Function&, Shape, Args&...>;
108 };
109
111 template<typename... Errors>
113 };
114
115 template<typename Sender, typename Env, typename Shape, typename Function>
121
122 template<typename Sender, typename Env, typename Shape, typename Function>
124
125 template<typename Send, typename Shape, typename Function>
126 struct SenderT {
127 struct Type {
128 using is_sender = void;
129
130 [[no_unique_address]] Send sender;
131 [[no_unique_address]] Shape shape;
132 [[no_unique_address]] Function function;
133
134 template<concepts::RemoveCVRefSameAs<Type> Self, typename Env>
136 friend auto tag_invoke(Tag<get_completion_signatures>, Self&&, Env&&)
137 -> Sigs<meta::Like<Self, Send>, Env, Shape, Function> {
138 return {};
139 }
140
141 template<concepts::RemoveCVRefSameAs<Type> Self, typename Rec>
144 friend auto tag_invoke(Tag<connect>, Self&& self, Rec receiver) {
146 util::forward_like<Self>(self.sender), self.shape, util::forward_like<Self>(self.function),
147 util::move(receiver));
148 }
149
150 friend auto tag_invoke(Tag<get_env>, Type const& self) { return make_env(get_env(self.sender)); }
151 };
152 };
153
154 template<typename Send, typename Shape, typename Function>
156
157 struct Function {
158 template<concepts::Sender Send, concepts::Integral Shape, concepts::MovableValue Fun>
159 constexpr auto operator()(Send&& sender, Shape shape, Fun&& function) const {
160 if constexpr (requires {
162 util::forward<Send>(sender), shape, util::forward<Fun>(function));
163 }) {
165 util::forward<Send>(sender), shape, util::forward<Fun>(function));
166 } else if constexpr (requires {
167 tag_invoke(*this, util::forward<Send>(sender), shape,
168 util::forward<Fun>(function));
169 }) {
170 return tag_invoke(*this, util::forward<Send>(sender), shape, util::forward<Fun>(function));
171 } else {
172 return Sender<Send, Shape, Fun> { util::forward<Send>(sender), shape, util::forward<Fun>(function) };
173 }
174 }
175 };
176}
177
199}
#define DI_IMMOVABLE_NO_UNIQUE_ADDRESS
Definition compiler.h:15
Definition vocab.h:30
Definition invoke.h:58
Definition receiver_of.h:25
Definition bulk.h:31
meta::Type< ReceiverT< meta::Decay< Shape >, meta::Decay< Function >, meta::Decay< Rec > > > Receiver
Definition bulk.h:80
meta::Type< SenderT< meta::RemoveCVRef< Send >, meta::Decay< Shape >, meta::Decay< Function > > > Sender
Definition bulk.h:155
meta::Type< DataT< meta::Decay< Shape >, meta::Decay< Function >, Rec > > Data
Definition bulk.h:42
meta::Type< OperationStateT< Send, Shape, Function, Rec > > OperationState
Definition bulk.h:102
meta::Apply< MakeErrorSigs, meta::Filter< meta::ValueTypesOf< Sender, MakeEnv< Env >, GetInvokeResult< Function, Shape >::template Invoke, meta::List >, meta::Not< meta::SameAs< void > > > > ErrorCompletions
Definition bulk.h:116
meta::MakeCompletionSignatures< Sender, MakeEnv< Env >, ErrorCompletions< Sender, Env, Shape, Function > > Sigs
Definition bulk.h:123
Definition bulk.h:30
constexpr auto set_error
Definition set_error.h:14
constexpr auto start
Definition start.h:20
constexpr auto make_env
Create an environment with overrides for queries.
Definition make_env.h:147
constexpr auto bulk
Bulk apply a function to a range of values.
Definition bulk.h:198
meta::Type< receiver_interface_ns::ReceiverAdaptor< Self, Base > > ReceiverAdaptor
Definition receiver_adaptor.h:236
constexpr auto get_completion_scheduler
Definition get_completion_scheduler.h:19
constexpr auto get_env
Definition get_env.h:27
constexpr auto connect
Definition connect.h:42
constexpr auto set_value
Definition set_value.h:14
Definition as_bool.h:8
constexpr auto invoke
Definition invoke.h:100
constexpr auto curry_back
Definition curry_back.h:141
T::Type Type
Definition core.h:26
Conditional< concepts::LanguageArray< RemoveReference< T > >, RemoveExtent< RemoveReference< T > > *, Conditional< concepts::LanguageFunction< RemoveReference< T > >, AddPointer< RemoveReference< T > >, RemoveCVRef< T > > > Decay
Definition language.h:574
Type< detail::LikeHelper< T, U > > Like
Definition language.h:468
meta::RemoveCVRef< T >::Error ExpectedError
Definition vocab.h:38
Fold< List, meta::List<>, detail::FilterReducer< Pred > > Filter
Definition algorithm.h:152
decltype(function::detail::invoke_impl(util::declval< Ts >()...)) InvokeResult
Definition invoke.h:64
Type< detail::MakeCompletionSignaturesHelper< ExtraSigs, meta::ValueTypesOf< Send, Env, SetValue, meta::List >, meta::Transform< meta::ErrorTypesOf< Send, Env, meta::List >, meta::Quote< SetError > >, meta::Conditional< meta::sends_stopped< Send, Env >, SetStopped, types::CompletionSignatures<> > > > MakeCompletionSignatures
Definition make_completion_signatures.h:36
Type< detail::ApplyHelper< F, T > > Apply
Definition function.h:55
decltype(execution::get_env(util::declval< T >())) EnvOf
Definition env_of.h:8
decltype(execution::connect(util::declval< Send >(), util::declval< Rec >())) ConnectResult
Definition connect_result.h:7
di::meta::Decay< decltype(T)> Tag
Definition tag_invoke.h:28
Definition vocab.h:96
constexpr auto forward_like(U &&value) -> decltype(auto)
Definition forward_like.h:8
constexpr tag_invoke_detail::TagInvokeFn tag_invoke
Definition tag_invoke.h:22
constexpr auto c_
A value of type Constexpr<val>.
Definition constexpr.h:252
constexpr auto data
Definition data.h:51
Definition set_error.h:6
Shape shape
Definition bulk.h:35
Rec receiver
Definition bulk.h:37
Function function
Definition bulk.h:36
Definition bulk.h:33
constexpr auto operator()(Send &&sender, Shape shape, Fun &&function) const
Definition bulk.h:159
meta::InvokeResult< Function &, Shape, Args &... > Invoke
Definition bulk.h:107
CompletionSignatures< SetError(meta::ExpectedError< Errors >)... > Invoke
Definition bulk.h:112
Type(Send &&sender, Shape shape, Function &&function, Rec receiver)
Definition bulk.h:89
friend void tag_invoke(Tag< start >, Type &self)
Definition bulk.h:94
meta::ConnectResult< Send, Rc > Op
Definition bulk.h:87
Receiver< Shape, Function, Rec > Rc
Definition bulk.h:86
auto base() const &-> Rec const &
Definition bulk.h:54
auto base() &&-> Rec &&
Definition bulk.h:55
Type(Data< Shape, Function, Rec > *data)
Definition bulk.h:52
Function function
Definition bulk.h:132
friend auto tag_invoke(Tag< get_completion_signatures >, Self &&, Env &&) -> Sigs< meta::Like< Self, Send >, Env, Shape, Function >
Definition bulk.h:136
friend auto tag_invoke(Tag< connect >, Self &&self, Rec receiver)
Definition bulk.h:144
Send sender
Definition bulk.h:130
Shape shape
Definition bulk.h:131
friend auto tag_invoke(Tag< get_env >, Type const &self)
Definition bulk.h:150
void is_sender
Definition bulk.h:128
Definition bulk.h:126
Definition core.h:5
Definition function.h:128
Definition completion_signuatures.h:7
Definition immovable.h:4