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
4 changes: 3 additions & 1 deletion include/beman/execution/detail/stop_callback_for_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_STOP_CALLBACK_FOR
#define INCLUDED_BEMAN_EXECUTION_DETAIL_STOP_CALLBACK_FOR

#include <beman/execution/detail/stop_token_traits.hpp>
#include <concepts>

// ----------------------------------------------------------------------------

namespace beman::execution {
template <class Token, class CallbackFun>
using stop_callback_for_t = typename Token::template callback_type<CallbackFun>;
using stop_callback_for_t =
typename ::beman::execution::detail::stoppable_token_traits<Token>::template callback_type<CallbackFun>;
}

namespace beman::execution::detail {
Expand Down
34 changes: 34 additions & 0 deletions include/beman/execution/detail/stop_token_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// include/beman/execution/detail/stop_token_traits.hpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_STOP_TOKEN_TRAITS
#define INCLUDED_BEMAN_EXECUTION_DETAIL_STOP_TOKEN_TRAITS

#include <beman/execution/detail/check_type_alias_exist.hpp>
#include <stop_token>

// ----------------------------------------------------------------------------

namespace beman::execution::detail {
template <typename>
struct stoppable_token_traits;

template <typename Token>
requires requires { typename check_type_alias_exist<Token::template callback_type>; }
struct stoppable_token_traits<Token> {
template <typename Fn>
using callback_type = typename Token::template callback_type<Fn>;
};

#if not defined(__clang__) || __clang_major__ > 19
template <>
struct stoppable_token_traits<::std::stop_token> {
template <typename Fn>
using callback_type = ::std::stop_callback<Fn>;
};
#endif
} // namespace beman::execution::detail

// ----------------------------------------------------------------------------

#endif
4 changes: 3 additions & 1 deletion include/beman/execution/detail/stoppable_token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
#define INCLUDED_BEMAN_EXECUTION_DETAIL_STOPPABLE_TOKEN

#include <beman/execution/detail/check_type_alias_exist.hpp>
#include <beman/execution/detail/stop_token_traits.hpp>
#include <concepts>

// ----------------------------------------------------------------------------

namespace beman::execution {
template <typename Token>
concept stoppable_token = requires(const Token& token) {
typename ::beman::execution::detail::check_type_alias_exist<Token::template callback_type>;
typename ::beman::execution::detail::check_type_alias_exist<
::beman::execution::detail::stoppable_token_traits<Token>::template callback_type>;
{ token.stop_requested() } noexcept -> ::std::same_as<bool>;
{ token.stop_possible() } noexcept -> ::std::same_as<bool>;
{ Token(token) } noexcept;
Expand Down
1 change: 1 addition & 0 deletions tests/beman/execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ endif()
list(
APPEND execution_tests
exec-affine-on.test
issue-200.test
issue-174.test
issue-186.test
exec-scope-counting.test
Expand Down
15 changes: 15 additions & 0 deletions tests/beman/execution/issue-200.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// tests/beman/execution/issue-200.test.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <beman/execution/detail/stoppable_token.hpp>
#include <test/execution.hpp>
#include <stop_token>

// ----------------------------------------------------------------------------

auto main() -> int {
#if not defined(__clang__) || __clang_major__ > 19
static_assert(test_std::stoppable_token<std::stop_token>);
#endif
return 0;
}