Skip to content

Commit

Permalink
Some fixes to definition of stoppable_token and unstoppable_token con…
Browse files Browse the repository at this point in the history
…cepts (facebookexperimental#359)

* `unstoppable_token` concept now checks `T::stop_possible()` is constexpr.
* Fix typo in definition of `never_stop_token::callback` - constructor was named `callback_type` instead of callback.
* Clarified in `stoppable_token` semantic requirements that callback is invoked in a noexcept context.
* Remove spurious const qualification of static members in `never_stop_token`.
* Add `operator==()` definition to `never_stop_token` so it actually satisfies the unstoppable_token concept.

Thanks to @dietmarkuehl for the suggestions.
  • Loading branch information
lewissbaker authored Oct 14, 2021
1 parent 870f694 commit af981be
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions doc/std/D2175.md
Original file line number Diff line number Diff line change
Expand Up @@ -1436,10 +1436,13 @@ namespace std
constructible_from<typename T::template callback_type<CB>, const T, Initializer> &&
constructible_from<typename T::template callback_type<CB>, const T&, Initializer>;

template<bool> struct __constexpr_bool; // exposition only

template<typename T>
concept unstoppable_token =
stoppable_token<T> &&
requires {
typename __constexpr_bool<T::stop_possible()>;
{ T::stop_possible() } -> boolean-testable;
} &&
(!T::stop_possible());
Expand Down Expand Up @@ -1472,7 +1475,8 @@ The `stoppable_token` concept has a number of semantic requirements on types:
argument to the constructor, shall, if `t.stop_possible()` is `true`, construct an
instance, `callback`, of type `CB`, direct-initialized with `init`, and register
`callback` with `t`'s shared stop state such that `callback` will be invoked with
an empty argument list if a stop request is made on the shared stop state.
an empty argument list from a `noexcept` context if a stop request is made on the
shared stop state.
* If `t.stop_requested()` is `true` at the time `callback` is registered then
`callback` _may_ be invoked immediately inline inside the call to `cb`'s constructor.
* If `callback` is invoked then for any token, `u`, that references the same shared
Expand Down Expand Up @@ -1529,14 +1533,16 @@ namespace std
class callback {
public:
template<typename C>
explicit callback_type(never_stop_token, C&&) noexcept {}
explicit callback(never_stop_token, C&&) noexcept {}
};
public:
template<invocable CB>
using callback_type = callback;

static constexpr bool stop_requested() const noexcept { return false; }
static constexpr bool stop_possible() const noexcept { return false; }
static constexpr bool stop_requested() noexcept { return false; }
static constexpr bool stop_possible() noexcept { return false; }

friend constexpr bool operator==(never_stop_token, never_stop_token) noexcept { return true; }
};
}
```
Expand Down

0 comments on commit af981be

Please sign in to comment.