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 "__concepts.hpp" 22 #include "__sender_adaptor_closure.hpp" 23 #include "__let.hpp" 24 #include "__just.hpp" 25 26 namespace stdexec { 27 ///////////////////////////////////////////////////////////////////////////// 28 // [execution.senders.adaptors.stopped_as_error] 29 namespace __sae { 30 struct stopped_as_error_t { 31 template <sender _Sender, __movable_value _Error> operator ()stdexec::__sae::stopped_as_error_t32 auto operator()(_Sender&& __sndr, _Error __err) const { 33 return let_stopped( 34 static_cast<_Sender&&>(__sndr), 35 [__err2 = static_cast<_Error&&>(__err)]() mutable noexcept( 36 __nothrow_move_constructible<_Error>) { 37 return just_error(static_cast<_Error&&>(__err2)); 38 }); 39 } 40 41 template <__movable_value _Error> STDEXEC_ATTRIBUTEstdexec::__sae::stopped_as_error_t42 STDEXEC_ATTRIBUTE(always_inline) 43 auto operator()(_Error __err) const -> __binder_back<stopped_as_error_t, _Error> { 44 return {{static_cast<_Error&&>(__err)}, {}, {}}; 45 } 46 }; 47 } // namespace __sae 48 49 using __sae::stopped_as_error_t; 50 inline constexpr stopped_as_error_t stopped_as_error{}; 51 } // namespace stdexec 52