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 = __nothrow_copy_constructible<_Token> // 35 && __nothrow_move_constructible<_Token> // 36 && equality_comparable<_Token> // 37 && requires(const _Token& __token) { 38 { 39 __token.stop_requested() 40 } noexcept -> __boolean_testable_; 41 { 42 __token.stop_possible() 43 } noexcept -> __boolean_testable_; 44 // workaround ICE in appleclang 13.1 45 #if !defined(__clang__) 46 typename __stok::__check_type_alias_exists< 47 _Token::template callback_type>; 48 #endif 49 }; 50 51 template <class _Token, typename _Callback, typename _Initializer = _Callback> 52 concept stoppable_token_for = 53 stoppable_token<_Token> // 54 && __callable<_Callback> // 55 && requires { typename stop_callback_for_t<_Token, _Callback>; } && 56 constructible_from<_Callback, _Initializer> && 57 constructible_from<stop_callback_for_t<_Token, _Callback>, const _Token&, 58 _Initializer>; 59 60 template <class _Token> 61 concept unstoppable_token = // 62 stoppable_token<_Token> && // 63 requires { 64 { 65 _Token::stop_possible() 66 } -> __boolean_testable_; 67 } && (!_Token::stop_possible()); 68 } // namespace stdexec 69