0
你好,我是试图建立一个功能,这将使调用函数提供的参数与一些提供参数和返回它的价值,我目前的做法如下推断拉姆达返回类型
#include <functional>
#include <iostream>
#include <type_traits>
template <typename Res,typename... T>
auto func(typename std::common_type<std::function<Res(T...)>>::type f, T... values) -> decltype(f(values...)) {
f(values...);
}
int fx(int x,int y){return x+y; }
int main() {
>> func([](int x, int y, int z) { std::cout << (x*y*z) << std::endl; }, 3, 6, 8);
return 0;
}
如果我用void替换Res并删除它的自动工作,但不知何故我无法获得正确的返回类型。