1 /* 2 * Copyright (c) 2021-2022 Facebook, Inc. and its affiliates 3 * Copyright (c) 2021-2024 NVIDIA Corporation 4 * 5 * Licensed under the Apache License Version 2.0 with LLVM Exceptions 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * https://llvm.org/LICENSE.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 #pragma once 18 19 #include "__concepts.hpp" 20 #include "__execution_fwd.hpp" 21 22 namespace stdexec 23 { 24 namespace __stok 25 { 26 template <template <class> class> 27 struct __check_type_alias_exists; 28 } // namespace __stok 29 30 template <class _Token, class _Callback> 31 using stop_callback_for_t = typename _Token::template callback_type<_Callback>; 32 33 template <class _Token> 34 concept stoppable_token = 35 __nothrow_copy_constructible<_Token> // 36 && __nothrow_move_constructible<_Token> // 37 && equality_comparable<_Token> // 38 && requires(const _Token& __token) { 39 { __token.stop_requested() } noexcept -> __boolean_testable_; 40 { __token.stop_possible() } noexcept -> __boolean_testable_; 41 // workaround ICE in appleclang 13.1 42 #if !defined(__clang__) 43 typename __stok::__check_type_alias_exists< 44 _Token::template callback_type>; 45 #endif 46 }; 47 48 template <class _Token, typename _Callback, typename _Initializer = _Callback> 49 concept stoppable_token_for = 50 stoppable_token<_Token> // 51 && __callable<_Callback> // 52 && requires { typename stop_callback_for_t<_Token, _Callback>; } && 53 constructible_from<_Callback, _Initializer> && 54 constructible_from<stop_callback_for_t<_Token, _Callback>, const _Token&, 55 _Initializer>; 56 57 template <class _Token> 58 concept unstoppable_token = // 59 stoppable_token<_Token> && // 60 requires { 61 { _Token::stop_possible() } -> __boolean_testable_; 62 } && (!_Token::stop_possible()); 63 } // namespace stdexec 64