kokkos-execution 0.0.1
Loading...
Searching...
No Matches
env.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_IMPL_ENV_HPP
2#define KOKKOS_EXECUTION_IMPL_ENV_HPP
3
5
7#define KOKKOS_EXECUTION_FORWARDING_GET_ENV(_type_, _obj_) \
8 [[nodiscard]] \
9 constexpr auto get_env() const noexcept -> ::stdexec::__fwd_env_t<::stdexec::env_of_t<_type_>> { \
10 return ::stdexec::__fwd_env(::stdexec::get_env(_obj_)); \
11 }
12
14
16
17 template <typename>
18 struct EnvOneOf;
19
20 template <typename Env1, typename Env2>
21 struct EnvOneOf<stdexec::env<Env1, Env2>> {
22 using type = Env1;
23 };
24
25 template <typename Env>
27
29 template <typename Tag, typename PropValue, typename Value>
30 constexpr auto operator()(Tag tag, stdexec::prop<Tag, PropValue>, Value&& value) const noexcept {
31 return stdexec::prop{tag, std::forward<Value>(value)};
32 }
33
35 template <typename Tag, typename Env, typename Value>
36 requires(!stdexec::__queryable_with<std::remove_cvref_t<Env>, Tag>)
37 constexpr auto operator()(Tag tag, Env&& env, Value&& value) const noexcept {
38 return stdexec::env{
39 stdexec::prop{tag, std::forward<Value>(value)},
40 std::forward<Env>(env)
41 };
42 }
43
45 template <typename Tag, typename PropValue, typename Value>
46 constexpr auto operator()(Tag tag, stdexec::env<stdexec::prop<Tag, PropValue>>, Value&& value) const noexcept {
47 return stdexec::env{
48 stdexec::prop{tag, std::forward<Value>(value)}
49 };
50 }
51
53 template <typename Tag, typename Env, typename Value>
54 requires(stdexec::__queryable_with<env1_of_t<std::remove_cvref_t<Env>>, Tag>)
55 constexpr auto operator()(Tag tag, Env&& env, Value&& value) const noexcept {
56 return stdexec::env{
57 stdexec::prop{tag, std::forward<Value>(value)},
58 std::forward<Env>(env).__env2_
59 };
60 }
61
63 template <typename Tag, typename Env, typename Value>
64 requires(
65 stdexec::__queryable_with<std::remove_cvref_t<Env>, Tag>
66 && !stdexec::__queryable_with<env1_of_t<std::remove_cvref_t<Env>>, Tag>)
67 constexpr auto operator()(Tag tag, Env&& env, Value&& value) const noexcept {
68 return stdexec::env{
69 std::forward<Env>(env).__env1_,
70 this->operator()(
71 tag, std::forward<Env>(env).__env2_, std::forward<Value>(value))}; // NOLINT(bugprone-use-after-move)
72 }
73
75 template <typename Tag, typename Env, typename Value>
76 requires(
77 stdexec::__queryable_with<Env &&, Tag> && stdexec::__env::__is_fwd_env<Env>
78 && requires(
79 UpsertInEnvFn const & self,
80 Tag tag,
81 Env&& env,
82 Value&& value) { self(tag, std::forward<Env>(env).__env_, std::forward<Value>(value)); })
83 constexpr auto operator()(Tag tag, Env&& env, Value&& value) const noexcept {
84 return stdexec::__env::__fwd{this->operator()(tag, std::forward<Env>(env).__env_, std::forward<Value>(value))};
85 }
86};
87
89 template <typename Tag, typename Env, typename Value>
90 requires(std::is_invocable_v<UpsertInEnvFn, Tag, Env &&, Value &&>)
91 constexpr auto operator()(Tag tag, Env&& env, Value&& value) const noexcept {
92 return UpsertInEnvFn{}.operator()(tag, std::forward<Env>(env), std::forward<Value>(value));
93 }
94
95 template <typename Tag, typename Env, typename Value>
96 requires(!std::is_invocable_v<UpsertInEnvFn, Tag, Env &&, Value &&>)
97 constexpr auto operator()(Tag tag, Env&& env, Value&& value) const noexcept {
98 return stdexec::__env::__join(stdexec::prop{tag, std::forward<Value>(value)}, std::forward<Env>(env));
99 }
100};
101
102template <typename Tag, typename Env, typename Value>
103using upsert_in_env_t = std::invoke_result_t<UpsertInEnvFn, Tag, Env, Value>;
104
105inline constexpr UpsertInEnvFn upsert_in_env{};
106
107template <typename Tag, typename Env, typename Value>
108using upsert_in_env_or_join_t = std::invoke_result_t<UpsertInEnvOrJoinFn, Tag, Env, Value>;
109
111
112} // namespace Kokkos::Execution::Impl
113
114#endif // KOKKOS_EXECUTION_IMPL_ENV_HPP
std::invoke_result_t< UpsertInEnvFn, Tag, Env, Value > upsert_in_env_t
Definition env.hpp:103
constexpr UpsertInEnvFn upsert_in_env
Definition env.hpp:105
constexpr UpsertInEnvOrJoinFn upsert_in_env_or_join
Definition env.hpp:110
std::invoke_result_t< UpsertInEnvOrJoinFn, Tag, Env, Value > upsert_in_env_or_join_t
Definition env.hpp:108
constexpr auto operator()(Tag tag, stdexec::prop< Tag, PropValue >, Value &&value) const noexcept
Handle the case of a stdexec::prop without wrapping it into an stdexec::env.
Definition env.hpp:30
typename EnvOneOf< std::remove_cvref_t< Env > >::type env1_of_t
Definition env.hpp:26
constexpr auto operator()(Tag tag, stdexec::env< stdexec::prop< Tag, PropValue > >, Value &&value) const noexcept
The environment contains the required property, possibly with a value mismatch.
Definition env.hpp:46
Inspired by https://github.com/NVIDIA/stdexec/blob/16076a81efa4477513e6ede9c2741fd034ecef99/include/s...
Definition sync_wait.hpp:9