function::target_type
获取在可调用对象的类型信息。
const std::type_info& target_type() const;
备注
成员函数返回 typeid(void) ,如果 *this 为空,否则返回 typeid(T), T 是目标对象的类型。
示例
// 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);
}
要求
**标题:**functional
命名空间: std