std::function<R(Args...)>::target_type
From cppreference.com
< cpp | utility | functional | function
| 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 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
[編集] 関連項目
| 格納されたターゲットへのポインタを取得する (public member function) | |
| ある型の情報を保持し、typeid演算子によって返されるクラス (クラス) | |
| typeid | 型の情報を照会し、その型を表す std::type_info オブジェクトを返します。(演算子) |