stop_callback_for_t — std::stop_callback_for_t
stop_callback_for_t — std::stop_callback_for_t
std::stop_callback_for_t는 타입 T의 stop 콜백 타입을 얻는 데 사용되는 별칭 템플릿이에요. C++26에서 도입됐어요. <stop_token> 헤더에 있어요.
출처: cppreference
본문
// <stop_token> 헤더, C++26
template< class T, class CallbackFn >
using stop_callback_for_t = T::template callback_type<CallbackFn>;
T가 stoppable_token(또는 그 파생)일 때, T::template callback_type<CallbackFn>으로 그 토큰의 콜백 타입을 얻어요.
사용 예
#include <stop_token>
// 어떤 스톱 토큰 타입 T에 대해 콜백 타입 조회
using callback_t = std::stop_callback_for_t<std::stop_token, decltype([]{})>;
// std::stop_callback<...> 타입
std::stop_callback은 std::stop_token을 받아 콜백을 등록하는데, 제네릭 코드에서 "이 토큰에 맞는 콜백 타입이 뭐지?"라고 물을 때 별칭 템플릿을 써요.
특징
- 제네릭(concept) 코드에서 중지 토큰 타입에 대응하는 콜백 타입을 추론하는 데 사용.
T가stoppable_token개념을 만족해야 의미가 있어요 (C++26).
template<std::stoppable_token Token>
void register_callback(Token tok, auto fn) {
std::stop_callback_for_t<Token, decltype(fn)> cb(tok, std::move(fn));
}
std::stop_callback_for_t는 중지 토큰 타입으로부터 그에 맞는 스톱 콜백 타입을 가져오는 메타 프로그래밍 도구예요. C++26 신규 기능이에요.