Skip to content

Commit 5387743

Browse files
committed
address issue 200: use stop_callback_traits to support std::stop_token
1 parent a098f90 commit 5387743

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

include/beman/execution/detail/stop_callback_for_t.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_STOP_CALLBACK_FOR
55
#define INCLUDED_BEMAN_EXECUTION_DETAIL_STOP_CALLBACK_FOR
66

7+
#include <beman/execution/detail/stop_token_traits.hpp>
78
#include <concepts>
89

910
// ----------------------------------------------------------------------------
1011

1112
namespace beman::execution {
1213
template <class Token, class CallbackFun>
13-
using stop_callback_for_t = typename Token::template callback_type<CallbackFun>;
14+
using stop_callback_for_t =
15+
typename ::beman::execution::detail::stoppable_token_traits<Token>::template callback_type<CallbackFun>;
1416
}
1517

1618
namespace beman::execution::detail {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// include/beman/execution/detail/stop_token_traits.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_STOP_TOKEN_TRAITS
5+
#define INCLUDED_BEMAN_EXECUTION_DETAIL_STOP_TOKEN_TRAITS
6+
7+
#include <beman/execution/detail/check_type_alias_exist.hpp>
8+
#include <stop_token>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace beman::execution::detail {
13+
template <typename>
14+
struct stoppable_token_traits;
15+
16+
template <typename Token>
17+
requires requires { typename check_type_alias_exist<Token::template callback_type>; }
18+
struct stoppable_token_traits<Token> {
19+
template <typename Fn>
20+
using callback_type = typename Token::template callback_type<Fn>;
21+
};
22+
23+
template <>
24+
struct stoppable_token_traits<std::stop_token> {
25+
template <typename Fn>
26+
using callback_type = std::stop_callback<Fn>;
27+
};
28+
} // namespace beman::execution::detail
29+
30+
// ----------------------------------------------------------------------------
31+
32+
#endif

include/beman/execution/detail/stoppable_token.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
#define INCLUDED_BEMAN_EXECUTION_DETAIL_STOPPABLE_TOKEN
66

77
#include <beman/execution/detail/check_type_alias_exist.hpp>
8+
#include <beman/execution/detail/stop_token_traits.hpp>
89
#include <concepts>
910

1011
// ----------------------------------------------------------------------------
1112

1213
namespace beman::execution {
1314
template <typename Token>
1415
concept stoppable_token = requires(const Token& token) {
15-
typename ::beman::execution::detail::check_type_alias_exist<Token::template callback_type>;
16+
typename ::beman::execution::detail::check_type_alias_exist<
17+
::beman::execution::detail::stoppable_token_traits<Token>::template callback_type>;
1618
{ token.stop_requested() } noexcept -> ::std::same_as<bool>;
1719
{ token.stop_possible() } noexcept -> ::std::same_as<bool>;
1820
{ Token(token) } noexcept;

tests/beman/execution/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ endif()
2121
list(
2222
APPEND execution_tests
2323
exec-affine-on.test
24+
issue-200.test
2425
issue-174.test
2526
issue-186.test
2627
exec-scope-counting.test
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// tests/beman/execution/issue-200.test.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution/detail/stoppable_token.hpp>
5+
#include <test/execution.hpp>
6+
#include <stop_token>
7+
8+
// ----------------------------------------------------------------------------
9+
10+
auto main() -> int {
11+
static_assert(test_std::stoppable_token<std::stop_token>);
12+
return 0;
13+
}

0 commit comments

Comments
 (0)