15cee9157SPatrick Williams /*
25cee9157SPatrick Williams  * Copyright (c) 2021-2022 Facebook, Inc. and its affiliates
35cee9157SPatrick Williams  * Copyright (c) 2021-2024 NVIDIA Corporation
45cee9157SPatrick Williams  *
55cee9157SPatrick Williams  * Licensed under the Apache License Version 2.0 with LLVM Exceptions
65cee9157SPatrick Williams  * (the "License"); you may not use this file except in compliance with
75cee9157SPatrick Williams  * the License. You may obtain a copy of the License at
85cee9157SPatrick Williams  *
95cee9157SPatrick Williams  *   https://llvm.org/LICENSE.txt
105cee9157SPatrick Williams  *
115cee9157SPatrick Williams  * Unless required by applicable law or agreed to in writing, software
125cee9157SPatrick Williams  * distributed under the License is distributed on an "AS IS" BASIS,
135cee9157SPatrick Williams  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145cee9157SPatrick Williams  * See the License for the specific language governing permissions and
155cee9157SPatrick Williams  * limitations under the License.
165cee9157SPatrick Williams  */
175cee9157SPatrick Williams #pragma once
185cee9157SPatrick Williams 
195cee9157SPatrick Williams #include "__concepts.hpp"
205cee9157SPatrick Williams #include "__execution_fwd.hpp"
215cee9157SPatrick Williams 
225cee9157SPatrick Williams namespace stdexec
235cee9157SPatrick Williams {
245cee9157SPatrick Williams namespace __stok
255cee9157SPatrick Williams {
265cee9157SPatrick Williams template <template <class> class>
275cee9157SPatrick Williams struct __check_type_alias_exists;
285cee9157SPatrick Williams } // namespace __stok
295cee9157SPatrick Williams 
305cee9157SPatrick Williams template <class _Token, class _Callback>
315cee9157SPatrick Williams using stop_callback_for_t = typename _Token::template callback_type<_Callback>;
325cee9157SPatrick Williams 
335cee9157SPatrick Williams template <class _Token>
34*06f265f6SPatrick Williams concept stoppable_token =
35*06f265f6SPatrick Williams     __nothrow_copy_constructible<_Token>    //
365cee9157SPatrick Williams     && __nothrow_move_constructible<_Token> //
375cee9157SPatrick Williams     && equality_comparable<_Token>          //
385cee9157SPatrick Williams     && requires(const _Token& __token) {
39*06f265f6SPatrick Williams            { __token.stop_requested() } noexcept -> __boolean_testable_;
40*06f265f6SPatrick Williams            { __token.stop_possible() } noexcept -> __boolean_testable_;
415cee9157SPatrick Williams     // workaround ICE in appleclang 13.1
425cee9157SPatrick Williams #if !defined(__clang__)
435cee9157SPatrick Williams            typename __stok::__check_type_alias_exists<
445cee9157SPatrick Williams                _Token::template callback_type>;
455cee9157SPatrick Williams #endif
465cee9157SPatrick Williams        };
475cee9157SPatrick Williams 
485cee9157SPatrick Williams template <class _Token, typename _Callback, typename _Initializer = _Callback>
495cee9157SPatrick Williams concept stoppable_token_for =
505cee9157SPatrick Williams     stoppable_token<_Token>  //
515cee9157SPatrick Williams     && __callable<_Callback> //
525cee9157SPatrick Williams     && requires { typename stop_callback_for_t<_Token, _Callback>; } &&
535cee9157SPatrick Williams     constructible_from<_Callback, _Initializer> &&
545cee9157SPatrick Williams     constructible_from<stop_callback_for_t<_Token, _Callback>, const _Token&,
555cee9157SPatrick Williams                        _Initializer>;
565cee9157SPatrick Williams 
575cee9157SPatrick Williams template <class _Token>
585cee9157SPatrick Williams concept unstoppable_token =    //
595cee9157SPatrick Williams     stoppable_token<_Token> && //
605cee9157SPatrick Williams     requires {
61*06f265f6SPatrick Williams         { _Token::stop_possible() } -> __boolean_testable_;
625cee9157SPatrick Williams     } && (!_Token::stop_possible());
635cee9157SPatrick Williams } // namespace stdexec
64