Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;将函数参数类型用于模板参数推断_C++_Templates_C++11_C++14_Functor - Fatal编程技术网

C++ C++;将函数参数类型用于模板参数推断

C++ C++;将函数参数类型用于模板参数推断,c++,templates,c++11,c++14,functor,C++,Templates,C++11,C++14,Functor,f中的fall tofunc应该可以由编译器内联,因此不能使用std::function。我通常使用类似于(GPL-3许可)的函数特性代码: template<typename T, typename Function> void f(Function func); template<typename Function> void call_f(Function func) { using arg_type = first_argument_type_t<

f
中的fall to
func
应该可以由编译器内联,因此不能使用
std::function

我通常使用类似于(GPL-3许可)的函数特性代码:

template<typename T, typename Function> void f(Function func);

template<typename Function>
void call_f(Function func) {
    using arg_type = first_argument_type_t<Function>; // ???
    f<arg_type, Function>(func);
}
模板
使用第一个参数类型=
typename sharemind::FunctionTraits::模板参数::类型;

但是还有另一种选择,这可能是有帮助的。

有很多要考虑的参数来推断参数类型。在一般情况下,如果那个函子是通用lambda,或者类类型实例有重载/模板<代码>运算符()/<代码>,则不能实现。
template<typename T, typename Function> void f(Function func);

template<typename Function>
void call_f(Function func) {
    using arg_type = first_argument_type_t<Function>; // ???
    f<arg_type, Function>(func);
}
template <typename F>
using first_argument_type_t =
     typename sharemind::FunctionTraits<F>::template argument<0u>::type;