Namespaces
Variants

std::function<R(Args...)>:: target_type

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
const std:: type_info & target_type ( ) const noexcept ;
(C++11 이후)

저장된 함수의 타입을 반환합니다.

목차

매개변수

(없음)

반환값

typeid ( T ) 저장된 함수가 타입 T 를 가지는 경우, 그렇지 않으면 typeid ( void )

예제

#include <functional>
#include <iostream>
int f(int a) { return -a; }
void g(double) {}
int main()
{
    // fn1과 fn2는 동일한 타입을 가지지만, 대상은 다릅니다
    std::function<int(int)> fn1(f),
                            fn2([](int a) {return -a;});
    std::cout << fn1.target_type().name() << '\n'
              << fn2.target_type().name() << '\n';
    // C++17부터는 추론 가이드(CTAD)를 사용할 수 있습니다
    std::cout << std::function{g}.target_type().name() << '\n';
}

가능한 출력:

PFiiE
Z4mainEUliE_
PFvdE

참고 항목

저장된 대상에 대한 포인터를 획득
(public member function)
특정 타입의 정보를 포함하며, typeid 연산자가 반환하는 클래스
(class)
typeid 타입 정보를 질의하며, 해당 타입을 나타내는 std::type_info 객체를 반환
(operator)