Namespaces
Variants

std:: is_invocable, std:: is_invocable_r, std:: is_nothrow_invocable, std:: is_nothrow_invocable_r

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
(C++11)
(C++11)
(C++11)
is_invocable is_invocable_r is_nothrow_invocable is_nothrow_invocable_r
(C++17) (C++17) (C++17) (C++17)
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더에 정의됨 <type_traits>
template < class Fn, class ... ArgTypes >
struct is_invocable ;
(1) (C++17부터)
template < class R, class Fn, class ... ArgTypes >
struct is_invocable_r ;
(2) (C++17부터)
template < class Fn, class ... ArgTypes >
struct is_nothrow_invocable ;
(3) (C++17부터)
template < class R, class Fn, class ... ArgTypes >
struct is_nothrow_invocable_r ;
(4) (C++17부터)
1) INVOKE ( std:: declval < Fn > ( ) , std:: declval < ArgTypes > ( ) ... ) 가 평가되지 않은 피연산자로 취급될 때 형성이 올바른지 여부를 결정합니다.
2) INVOKE<R> ( std:: declval < Fn > ( ) , std:: declval < ArgTypes > ( ) ... ) 가 평가되지 않은 피연산자로 취급될 때 올바르게 형성되는지 여부를 결정합니다.
3) INVOKE ( std:: declval < Fn > ( ) , std:: declval < ArgTypes > ( ) ... ) 가 평가되지 않은 피연산자로 취급될 때 올바르게 형성되는지 여부를 결정하며, 어떤 예외도 발생시키지 않음이 알려져 있습니다.
4) INVOKE<R> ( std:: declval < Fn > ( ) , std:: declval < ArgTypes > ( ) ... ) 가 평가되지 않은 피연산자로 취급될 때 올바르게 형성되는지 여부를 결정하고, 어떤 예외도 발생시키지 않음이 알려져 있는지 확인합니다.

만약 Fn, R 또는 매개변수 팩 ArgTypes 내의 어떤 타입이 완전한 타입이 아니거나, (cv-qualified일 수 있는) void , 또는 알려지지 않은 경계의 배열인 경우, 동작은 정의되지 않습니다.

템플릿의 인스턴스화가 직접적 또는 간접적으로 불완전한 타입에 의존하고, 해당 타입이 가상적으로 완성되었을 때 인스턴스화 결과가 달라질 수 있는 경우, 그 동작은 정의되지 않습니다.

프로그램이 이 페이지에 설명된 템플릿들 중 어느 하나에 대해 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

헬퍼 변수 템플릿

헤더에 정의됨 <type_traits>
template < class Fn, class ... ArgTypes >

inline constexpr bool is_invocable_v =

std :: is_invocable < Fn, ArgTypes... > :: value ;
(1) (C++17부터)
template < class R, class Fn, class ... ArgTypes >

inline constexpr bool is_invocable_r_v =

std :: is_invocable_r < R, Fn, ArgTypes... > :: value ;
(2) (C++17부터)
template < class Fn, class ... ArgTypes >

inline constexpr bool is_nothrow_invocable_v =

std :: is_nothrow_invocable < Fn, ArgTypes... > :: value ;
(3) (C++17부터)
template < class R, class Fn, class ... ArgTypes >

inline constexpr bool is_nothrow_invocable_r_v =

std :: is_nothrow_invocable_r < R, Fn, ArgTypes... > :: value ;
(4) (C++17부터)

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
true (오버로드 (1) 의 경우) INVOKE ( std:: declval < Fn > ( ) , std:: declval < ArgTypes > ( ) ... ) 가 평가되지 않은 피연산자로 취급될 때 유효한 형식인 경우, false 그렇지 않은 경우
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

Type Definition
value_type bool
type std:: integral_constant < bool , value >

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_is_invocable 201703L (C++17) std::is_invocable , std::invoke_result

예제

#include <type_traits>
auto func2(char) -> int (*)()
{
    return nullptr;
}
int main()
{
    static_assert(std::is_invocable_v<int()>);
    static_assert(not std::is_invocable_v<int(), int>);
    static_assert(std::is_invocable_r_v<int, int()>);
    static_assert(not std::is_invocable_r_v<int*, int()>);
    static_assert(std::is_invocable_r_v<void, void(int), int>);
    static_assert(not std::is_invocable_r_v<void, void(int), void>);
    static_assert(std::is_invocable_r_v<int(*)(), decltype(func2), char>);
    static_assert(not std::is_invocable_r_v<int(*)(), decltype(func2), void>);
}

참고 항목

(C++17) (C++23)
주어진 인수로 임의의 Callable 객체를 호출 및 반환 타입 지정 가능 (since C++23)
(함수 템플릿)
(C++11) (removed in C++20) (C++17)
호출 가능 객체를 인수 집합으로 호출한 결과 타입을 추론
(클래스 템플릿)
(C++11)
평가되지 않은 컨텍스트에서 사용하기 위해 템플릿 타입 인수의 객체에 대한 참조를 획득
(함수 템플릿)
호출 가능 타입이 주어진 인수 타입 집합으로 호출될 수 있음을 명시
(컨셉)