std::function<R(Args...)>::target_type
來自 cppreference.com
< cpp | utility | functional | function
const std::type_info& target_type() const noexcept; |
(C++11 起) | |
返回儲存的函式型別。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
如果儲存的函式型別為 T
,則返回 typeid(T),否則返回 typeid(void)。
[編輯] 示例
執行此程式碼
#include <functional> #include <iostream> 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'; }
可能的輸出
PFiiE Z4mainEUliE_ PFvdE
[編輯] 參閱
獲取指向儲存目標的指標 (公有成員函式) | |
包含某些型別資訊的類,由 typeid 運算子返回 (類) | |
typeid | 查詢型別資訊,返回表示該型別的 std::type_info 物件(運算子) |