deduction guides for std::stop_callback
From cppreference.com
| Defined in header <stop_token>
|
||
template< class Callback >
stop_callback( std::stop_token, Callback ) -> stop_callback<Callback>;
|
(since C++20) | |
One deduction guide is provided for std::stop_callback to permit deduction from argument of invocable types.
Example
Run this code
#include <concepts>
#include <iostream>
#include <stop_token>
#include <thread>
int main()
{
std::stop_source source;
std::stop_token token = source.get_token();
auto callback_fn = [] { std::cout << "|> stop-request callback\n"; };
// Use deduction guide to deduce the type of Callback
std::stop_callback callback(token, callback_fn);
static_assert(std::same_as<
decltype(callback_fn),
decltype(callback)::callback_type>);
source.request_stop();
}
Output:
|> stop-request callback