Skip to content
Draft
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
10 changes: 4 additions & 6 deletions include/stdexec/__detail/__stop_token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,10 @@ STDEXEC_P2300_NAMESPACE_BEGIN()

STDEXEC_MODULE_EXPORT
template <class _Token>
concept unstoppable_token =
stoppable_token<_Token> //
&& requires {
{ _Token::stop_possible() } -> STDEXEC::__boolean_testable_;
} //
&& (!_Token::stop_possible());
concept unstoppable_token = stoppable_token<_Token> && requires {
{ _Token::stop_possible() } -> STDEXEC::__boolean_testable_;
requires STDEXEC::__mbool<(!_Token::stop_possible())>::value;
};

template <unstoppable_token _Token>
struct __stoppable_base_for<_Token>
Expand Down
39 changes: 39 additions & 0 deletions test/stdexec/concepts/test_concepts_stop_tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,45 @@ namespace
#endif
}

struct runtime_stop_possible_token
{
template <class Fun>
struct callback_type
{
template <class Init>
explicit callback_type(runtime_stop_possible_token const &, Init&&) noexcept
{}
};

static auto stop_possible() noexcept -> bool
{
return false;
}

auto stop_requested() const noexcept -> bool
{
return false;
}

auto operator==(runtime_stop_possible_token const &) const noexcept -> bool = default;
};

struct constexpr_stop_possible_token : runtime_stop_possible_token
{
static constexpr auto stop_possible() noexcept -> bool
{
return true;
}
};

TEST_CASE("unstoppable_token requires a constant-false static stop_possible", "[concepts]")
{
STATIC_REQUIRE(::STDEXEC::stoppable_token<runtime_stop_possible_token>);
STATIC_REQUIRE(!::STDEXEC::unstoppable_token<runtime_stop_possible_token>);
STATIC_REQUIRE(::STDEXEC::stoppable_token<constexpr_stop_possible_token>);
STATIC_REQUIRE(!::STDEXEC::unstoppable_token<constexpr_stop_possible_token>);
}

TEST_CASE("inplace_stop_callback supports class template argument deduction", "[stop_token]")
{
::STDEXEC::inplace_stop_source source;
Expand Down
Loading