function::target
Depolanmış Callable nesnesi, sınamaları belirtildiği gibi çağrılabilir.
template<class Fty2>
Fty2 *target();
template<class Fty2>
const Fty2 *target() const;
Parametreler
- Fty2
Test etmek için hedef callable nesne türü.
Notlar
Type Fty2 için bağımsız değişken türleri callable olmalıdır T1, T2, ..., TN ve dönüş türü Ret.target_type() == typeid(Fty2), Adresi hedef nesnenin; üye şablon işlevini verir Aksi takdirde 0 döndürür.
Bir tür Fty2 bağımsız değişken türleri için çağrılabilir olan T1, T2, ..., TN ve dönüş türü Ret Eğer, lvalues fn, t1, t2, ..., tN türleri Fty2, T1, T2, ..., TN, sırasıyla INVOKE(fn, t1, t2, ..., tN) doğru biçimlendirildiğinden ve Ret değil void, dönüştürülebilir için Ret.
Örnek
// 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);
}
Gereksinimler
Başlık: <functional>
Namespace: std