types_is_applicable
types_is_applicable (튜플 인자로 호출 가능한지 검사하는 타입 특성)
이 페이지는 C++26에서 도입된 std::is_applicable과 std::is_nothrow_applicable 타입 특성에 대해 다뤄요. 이들은 주어진 함수 객체 Fn을 튜플 Tuple의 요소들을 인자로 하여 std::invoke로 호출할 수 있는지, 그리고 예외를 던지지 않는지 컴파일 타임에 검사해요. 이 특성들은 <type_traits> 헤더에 정의되어 있어요.
출처: cppreference
본문
정의
<type_traits> 헤더에 정의됨 |
||
|---|---|---|
template < class Fn , class Tuple > struct is_applicable ; |
(1) | (C++26부터) |
template < class Fn , class Tuple > struct is_nothrow_applicable ; |
(2) | (C++26부터) |
설명
Fn 타입이 주어진 인자 튜플 Tuple로 (std::invoke를 사용하는 것처럼) 호출 가능한지 검사해요.
/*ELEMS-OF*/ ( T )를 std::get<N>(std::declval<T>())의 매개변수 팩이라고 할게요. 여기서 N은 std::make_index_sequence<std::tuple_size_v<std::remove_reference_t<T>>>로 표기되는 std::index_sequence 특수화의 std::size_t 템플릿 인자 팩이에요.
Fn 또는 Tuple이 완전한 타입이 아니거나, (cv 한정된) void이거나, 경계를 알 수 없는 배열이면 동작이 정의되지 않아요.
위 템플릿 중 하나의 인스턴스화가 직접 또는 간접적으로 불완전한 타입에 의존하고, 그 타입이 가상으로 완성되었을 때 다른 결과를 낼 수 있다면 동작이 정의되지 않아요.
이 페이지에 설명된 템플릿에 대해 프로그램이 특수화를 추가하면 동작이 정의되지 않아요.
헬퍼 변수 템플릿
<type_traits> 헤더에 정의됨 |
||
|---|---|---|
template < class Fn , class Tuple > constexpr bool is_applicable_v = is_applicable < Fn , Tuple >:: value ; |
(1) | (C++26부터) |
template < class Fn , class Tuple > constexpr bool is_nothrow_applicable_v = is_nothrow_applicable < Fn , Tuple >:: value ; |
(2) | (C++26부터) |
std::integral_constant로부터 상속
멤버 상수
value [static] |
(오버로드 (1)의 경우) INVOKE(std::declval<Fn>(), /*ELEMS-OF*/(Tuple)...)가 비평가 피연산자(unevaluated operand)로 취급될 때 유효하면 true, 그렇지 않으면 false (공용 정적 멤버 상수) |
|---|
멤버 함수
operator bool |
객체를 bool로 변환하고 value를 반환해요 (공용 멤버 함수) |
|---|---|
operator() (C++14) |
value를 반환해요 (공용 멤버 함수) |
멤버 타입
| 타입 | 정의 |
|---|---|
value_type |
bool |
type |
std::integral_constant<bool, value> |
노트
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_reflection |
202506L |
(C++26) | <meta>: 리플렉션 라이브러리 지원. |
예제
#include <tuple>
#include <type_traits>
#include <utility>
void func(char) noexcept;
static_assert(
std::is_applicable_v<int(), std::tuple<>> and
not std::is_applicable_v<int(), std::tuple<int>> and
std::is_applicable_v<std::declval(func), std::tuple<char>> and
not std::is_applicable_v<std::declval(func), std::tuple<char, int>> and
std::is_nothrow_applicable_v<std::declval(func), std::tuple<char>>
);
int main() {}
같이 보기
apply (C++17) |
튜플의 인자들로 함수를 호출해요 (함수 템플릿) [편집] |
|---|---|
invoke, invoke_r (C++17) (C++23) |
주어진 인자들로 임의의 Callable 객체를 호출하고 반환 타입을 지정할 수 있어요 (C++23부터) (함수 템플릿) [편집] |
result_of, invoke_result (C++11) (C++20에서 제거됨) (C++17) |
인자 집합으로 호출 가능한 객체를 호출한 결과 타입을 추론해요 (클래스 템플릿) [편집] |
declval (C++11) |
비평가 문맥에서 사용하기 위해 템플릿 타입 인자의 객체에 대한 참조를 얻어요 (함수 템플릿) [편집] |
invocable, regular_invocable (C++20) (C++20) |
호출 가능한 타입이 주어진 인자 타입 집합으로 호출될 수 있음을 지정해요 (컨셉) [편집] |
is_invocable, is_invocable_r, is_nothrow_invocable, is_nothrow_invocable_r (C++17) (C++17) (C++17) (C++17) |
타입이 주어진 인자 타입들로 (std::invoke를 사용하는 것처럼) 호출 가능한지 검사해요 (클래스 템플릿) [편집] |
is_invocable_type, is_invocable_r_type, is_nothrow_invocable_type, is_nothrow_invocable_r_type (C++26) (C++26) (C++26) (C++26) |
반영된 타입이 주어진 인자 타입들로 (std::invoke를 사용하는 것처럼) 호출 가능한지 검사해요 (함수 템플릿) [편집] |
is_applicable_type, is_nothrow_applicable_type (C++26) (C++26) |
반영된 타입이 주어진 반영된 튜플 인자들로 (std::invoke를 사용하는 것처럼) 호출 가능한지 검사해요 (함수) [편집] |