共用方式為


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) ,分別是語式正確,則為,如果 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); 
    } 
 
  

需求

標題: <functional>

命名空間: std

請參閱

參考

function Class

function::target_type