function::target

测试,如果存储可调用对象是可调用的。指定。

template<class Fty2>
    Fty2 *target();
template<class Fty2>
    const Fty2 *target() const;

参数

  • Fty2
    测试的目标可调用的对象类型。

备注

类型 Fty2 绑定是可调用的。T1, T2, ..., TN 类型参数并返回 Ret类型。 如果 target_type() == typeid(Fty2),成员模板函数返回目标对象的地址;否则,返回 0。

Fty2 类型为参数类型 T1, T2, ..., TN 和 Ret 返回类型是可调用的,如果,为 Fty2, T1, T2, ..., TNfn, t1, t2, ..., tN,INVOKE(fn, t1, t2, ..., tN),分别为格式类型 lvalue 标准的,因此,如果 Ret 为 void,则不转换为 Ret。

示例

 

// std_tr1__functional__function_target.cpp 
// compile with: /EHsc 
#include <functional> 
#include <iostream> 
 
int neg(int val) 
    { 
    return (-val); 
    } 
 
int main() 
    { 
    typedef int (*Myfun)(int); 
    std::function<int (int)> fn0(neg); 
    std::cout << std::boolalpha << "empty == " << !fn0 << std::endl; 
    std::cout << "no target == " << (fn0.target<Myfun>() == 0) << std::endl; 
 
    Myfun *fptr = fn0.target<Myfun>(); 
    std::cout << "val == " << (*fptr)(3) << std::endl; 
 
    std::function<int (int)> fn1; 
    std::cout << std::boolalpha << "empty == " << !fn1 << std::endl; 
    std::cout << "no target == " << (fn1.target<Myfun>() == 0) << std::endl; 
 
    return (0); 
    } 
 
  

要求

标头: <起作用的>

命名空间: std

请参见

参考

function 类

function::target_type