Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions include/stdexec/__detail/__stop_token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,40 @@

#include "__concepts.hpp"

#include <stop_token>

namespace stdexec {
namespace __stok {
template <template <class> class>
struct __check_type_alias_exists;
} // namespace __stok

template <class _Token, class _Callback>
using stop_callback_for_t = _Token::template callback_type<_Callback>;
struct __stop_callback_for {
using __t = _Token::template callback_type<_Callback>;
};
template <class _Callback>
struct __stop_callback_for<std::stop_token, _Callback> {
using __t = std::stop_callback<_Callback>;
};

template <class _Token, class _Callback>
using stop_callback_for_t = __stop_callback_for<_Token, _Callback>::__t;

template <class _Token>
concept stoppable_token =
__nothrow_copy_constructible<_Token> && __nothrow_move_constructible<_Token>
&& equality_comparable<_Token> && requires(const _Token& __token) {
{ __token.stop_requested() } noexcept -> __boolean_testable_;
{ __token.stop_possible() } noexcept -> __boolean_testable_;
// workaround ICE in appleclang 13.1
}
// workaround ICE in appleclang 13.1
#if !defined(__clang__)
&& (__same_as<_Token, std::stop_token> || requires {
typename __stok::__check_type_alias_exists<_Token::template callback_type>;
})
#endif
};
;

template <class _Token, typename _Callback, typename _Initializer = _Callback>
concept stoppable_token_for =
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(stdexec_test_sources
stdexec/concepts/test_concepts_receiver.cpp
stdexec/concepts/test_concept_operation_state.cpp
stdexec/concepts/test_concepts_sender.cpp
stdexec/concepts/test_concepts_stop_tokens.cpp
stdexec/concepts/test_awaitables.cpp
stdexec/algos/factories/test_just.cpp
stdexec/algos/factories/test_transfer_just.cpp
Expand Down
43 changes: 43 additions & 0 deletions test/stdexec/concepts/test_concepts_stop_tokens.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2025 Robert Leahy. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
* Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://llvm.org/LICENSE.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdexec/execution.hpp>

#include <stop_token>
#include <type_traits>

namespace {

struct on_stop_request {
void operator()() && noexcept {
}
};

static_assert(::stdexec::stoppable_token<::stdexec::never_stop_token>);
static_assert(::stdexec::unstoppable_token<::stdexec::never_stop_token>);
static_assert(::stdexec::stoppable_token<::stdexec::inplace_stop_token>);
static_assert(!::stdexec::unstoppable_token<::stdexec::inplace_stop_token>);
static_assert(std::is_same_v<
::stdexec::stop_callback_for_t<::stdexec::never_stop_token, on_stop_request>,
::stdexec::never_stop_token::callback_type<on_stop_request>>);
static_assert(::stdexec::stoppable_token<std::stop_token>);
static_assert(std::is_same_v<
::stdexec::stop_callback_for_t<std::stop_token, on_stop_request>,
std::stop_callback<on_stop_request>>);

} // namespace
Loading