1 /* 2 * Copyright (c) 2021-2024 NVIDIA Corporation 3 * 4 * Licensed under the Apache License Version 2.0 with LLVM Exceptions 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * https://llvm.org/LICENSE.txt 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include "__execution_fwd.hpp" 19 20 // include these after __execution_fwd.hpp 21 #include "__basic_sender.hpp" 22 #include "__env.hpp" 23 #include "__sender_adaptor_closure.hpp" 24 #include "__senders.hpp" 25 #include "__transform_sender.hpp" 26 #include "__utility.hpp" 27 28 namespace stdexec 29 { 30 ////////////////////////////////////////////////////////////////////////////////////////////////// 31 // __write adaptor 32 namespace __write_ 33 { 34 struct __write_env_t 35 { 36 template <sender _Sender, class _Env> operator ()stdexec::__write_::__write_env_t37 auto operator()(_Sender&& __sndr, _Env __env) const 38 { 39 return __make_sexpr<__write_env_t>(static_cast<_Env&&>(__env), 40 static_cast<_Sender&&>(__sndr)); 41 } 42 43 template <class _Env> 44 STDEXEC_ATTRIBUTE((always_inline)) operator ()stdexec::__write_::__write_env_t45 auto operator()(_Env __env) const -> __binder_back<__write_env_t, _Env> 46 { 47 return {{static_cast<_Env&&>(__env)}, {}, {}}; 48 } 49 50 template <class _Env> 51 STDEXEC_ATTRIBUTE((always_inline)) __transform_env_fnstdexec::__write_::__write_env_t52 static auto __transform_env_fn(_Env&& __env) noexcept 53 { 54 return [&](__ignore, const auto& __state, __ignore) noexcept { 55 return __env::__join(__state, static_cast<_Env&&>(__env)); 56 }; 57 } 58 59 template <sender_expr_for<__write_env_t> _Self, class _Env> transform_envstdexec::__write_::__write_env_t60 static auto transform_env(const _Self& __self, _Env&& __env) noexcept 61 { 62 return __sexpr_apply(__self, 63 __transform_env_fn(static_cast<_Env&&>(__env))); 64 } 65 }; 66 67 struct __write_env_impl : __sexpr_defaults 68 { 69 static constexpr auto get_env = // __anon164445800202stdexec::__write_::__write_env_impl70 [](__ignore, const auto& __state, const auto& __rcvr) noexcept { 71 return __env::__join(__state, stdexec::get_env(__rcvr)); 72 }; 73 74 static constexpr auto get_completion_signatures = // 75 []<class _Self, class... _Env>(_Self&&, _Env&&...) noexcept 76 -> __completion_signatures_of_t< 77 __child_of<_Self>, 78 __meval<__env::__join_t, const __decay_t<__data_of<_Self>>&, 79 _Env...>> { 80 static_assert(sender_expr_for<_Self, __write_env_t>); 81 return {}; 82 }; 83 }; 84 } // namespace __write_ 85 86 using __write_::__write_env_t; 87 inline constexpr __write_env_t __write{}; 88 inline constexpr __write_env_t __write_env{}; 89 90 template <> 91 struct __sexpr_impl<__write_env_t> : __write_::__write_env_impl 92 {}; 93 } // namespace stdexec 94