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