std::function<R(Args...)>::target_type
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
См. также
| получает указатель на сохранённую цель (открытая функция-член) |
|
| содержит информацию о типе; класс, возвращаемый оператором typeid (класс) |
|
typeid | запрашивает информацию о типе, возвращая объект std::type_info, представляющий этот тип(оператор) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/utility/functional/function/target_type