std::function<R(Args...)>::target_type - cppreference.com (original) (raw)
Returns the type of the stored function.
[edit] Parameters
(none)
[edit] Return value
typeid(T) if the stored function has type T, otherwise typeid(void)
[edit] Example
#include #include int f(int a) { return -a; } void g(double) {} int main() { // fn1 and fn2 have the same type, but their targets do not std::function<int(int)> fn1(f), fn2([](int a) {return -a;}); std::cout << fn1.target_type().name() << '\n' << fn2.target_type().name() << '\n'; // since C++17 deduction guides (CTAD) can avail std::cout << std::function{g}.target_type().name() << '\n'; }
Possible output:
[edit] See also
| | obtains a pointer to the stored target (public member function) [edit] | | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | | | contains some type’s information, the class returned by the typeid operator (class) [edit] | | | typeid | queries information of a type, returning a std::type_info object representing the type(operator) |