【发布时间】:2023-01-20 20:07:29
【问题描述】:
假设我有以下函数指针 typedef:
using FType = int(*)(int,int);
如何使用FType 的签名构造一个std::function 对象?
例如,如果 FType 是使用 using FType = int(int,int) 定义的,则可以通过 std::funtion<FType> func = ... 完成
【问题讨论】:
假设我有以下函数指针 typedef:
using FType = int(*)(int,int);
如何使用FType 的签名构造一个std::function 对象?
例如,如果 FType 是使用 using FType = int(int,int) 定义的,则可以通过 std::funtion<FType> func = ... 完成
【问题讨论】:
using FType = int(*)(int,int);
std::function<std::remove_pointer_t<FType>> func;
【讨论】:
std::function 可以做 CTAD,因此这个有效:
#include <iostream>
#include <functional>
using FType = int(*)(int,int);
int foo(int,int) {}
int main(){
FType x = &foo;
auto f = std::function(x);
}
【讨论】: