std::function<R(Args...)>:: target_type
From cppreference.net
<
cpp
|
utility
|
functional
|
function
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Function objects
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::function
| Member functions | ||||
|
(until C++17)
|
||||
|
function::target_type
|
||||
| Non-member functions | ||||
|
(until C++20)
|
||||
| Helper classes | ||||
|
(until C++17)
|
||||
| Deduction guides (C++17) |
|
const
std::
type_info
&
target_type
(
)
const
noexcept
;
|
(C++11 起) | |
返回存储函数的类型。
目录 |
参数
(无)
返回值
typeid
(
T
)
若存储的函数具有类型
T
,否则为
typeid
(
void
)
示例
运行此代码
#include <functional> #include <iostream> int f(int a) { return -a; } void g(double) {} int main() { // fn1 和 fn2 具有相同类型,但其目标对象不同 std::function<int(int)> fn1(f), fn2([](int a) {return -a;}); std::cout << fn1.target_type().name() << '\n' << fn2.target_type().name() << '\n'; // 自 C++17 起可使用推导指引(CTAD) std::cout << std::function{g}.target_type().name() << '\n'; }
可能的输出:
PFiiE Z4mainEUliE_ PFvdE
参见
|
获取指向存储目标的指针
(公开成员函数) |
|
|
包含类型信息,由 typeid 运算符返回的类
(类) |
|
| typeid |
查询类型信息,返回表示该类型的
std::type_info
对象
(运算符) |