首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::function::target_type

const std::type_info& target_type() const;

(since C++11)

返回存储函数的类型。

参数

%280%29

返回值

typeid(T)如果存储的函数有类型T,否则typeid(void)...

例外

noexcept规格:

noexcept

二次

代码语言:javascript
复制
#include <functional>
#include <iostream>
 
int f(int a) { return -a; }
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';
}

二次

可能的产出:

二次

代码语言:javascript
复制
int (*)(int)
main::$_0

二次

另见

target

obtains a pointer to the stored target (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券