function::target
Tests if stored callable object is callable as specified.
template<class Fty2>
Fty2 *target();
template<class Fty2>
const Fty2 *target() const;
매개 변수
- Fty2
The target callable object type to test.
설명
The type Fty2 must be callable for the argument types T1, T2, ..., TN and the return type Ret. If target_type() == typeid(Fty2), the member template function returns the address of the target object; otherwise, it returns 0.
A type Fty2 is callable for the argument types T1, T2, ..., TN and the return type Ret if, for lvalues fn, t1, t2, ..., tN of types Fty2, T1, T2, ..., TN, respectively, INVOKE(fn, t1, t2, ..., tN) is well-formed and, if Ret is not void, convertible to 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