function::target_type

Gets type information on the callable object.

const std::type_info& target_type() const;

Remarks

The member function returns typeid(void) if *this is empty, otherwise it returns typeid(T), where T is the type of the target object.

Example

 

// std_tr1__functional__function_target_type.cpp 
// compile with: /EHsc 
#include <functional> 
#include <iostream> 
 
int neg(int val) 
    { 
    return (-val); 
    } 
 
int main() 
    { 
    std::function<int (int)> fn0(neg); 
    std::cout << std::boolalpha << "empty == " << !fn0 << std::endl; 
    std::cout << "type == " << fn0.target_type().name() << std::endl; 
 
    std::function<int (int)> fn1; 
    std::cout << std::boolalpha << "empty == " << !fn1 << std::endl; 
    std::cout << "type == " << fn1.target_type().name() << std::endl; 
 
    return (0); 
    } 
 
empty == false
type == int (__cdecl*)(int)
empty == true
type == void

Requirements

Header: <functional>

Namespace: std

See Also

Reference

function Class

function::target

Other Resources

<functional> Members