Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/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++ decltype返回的模板扣除/替换错误_C++_C++11_C++14_Variadic Templates_Decltype - Fatal编程技术网

C++ decltype返回的模板扣除/替换错误

C++ decltype返回的模板扣除/替换错误,c++,c++11,c++14,variadic-templates,decltype,C++,C++11,C++14,Variadic Templates,Decltype,我这里有一个代码片段,它获取一个函数指针元组和一个值元组,然后将值绑定到函数指针,并返回一个包含绑定函数的新元组 当我直接调用bind_tuple_impl时,我没有任何错误,但是调用这个例程并不是一种实用的方法。我还需要在绑定后延迟执行,因此不能仅使用给定参数调用函数 我是不是完全错了?我是不是漏掉了什么明显的东西 模板 自动绑定(std::tuple f,std::tuple t,std::index\u序列) ->decltype(std::make_tuple(std::bind(std

我这里有一个代码片段,它获取一个函数指针元组和一个值元组,然后将值绑定到函数指针,并返回一个包含绑定函数的新元组

当我直接调用bind_tuple_impl时,我没有任何错误,但是调用这个例程并不是一种实用的方法。我还需要在绑定后延迟执行,因此不能仅使用给定参数调用函数

我是不是完全错了?我是不是漏掉了什么明显的东西

模板
自动绑定(std::tuple f,std::tuple t,std::index\u序列)
->decltype(std::make_tuple(std::bind(std::get(f),std::get(t))…)
{
返回std::make_tuple(std::bind(std::get(f),std::get(t))…);
}
样板
自动绑定(std::tuple f,std::tuple t)
->decltype(bind_tuple_impl(f,t,std::index_sequence_for))
{
返回bind\u tuple\u impl(f,t,std::index\u sequence\u for);
}
int main()
{
std::元组f;
std::元组t;
自动绑定=绑定元组(f,t);
}
错误:

main.cpp:91:68: error: expected primary-expression before ')' token    
    -> decltype(bind_tuple_impl(f, t, std::index_sequence_for<Fs...>))    
                                                                    ^    
main.cpp: In function 'decltype (bind_tuple_impl(f, t, <expression error>)) bind_tuple(std::tuple<_Tps ...>, std::tuple<_Elements ...>)':

main.cpp:94:63: error: expected primary-expression before ')' token    
    return bind_tuple_impl(f, t, std::index_sequence_for<Fs...>);    
                                                               ^    
main.cpp: In function 'int main()':    
main.cpp:102:34: error: no matching function for call to 'bind_tuple(std::tuple<std::function<void(double)> >&, std::tuple<double>&)'    
     auto f_bound = bind_tuple(f,t);    
                                  ^    
main.cpp:89:6: note: candidate: 'template<class ... Fs, class ... Ts> decltype (bind_tuple_impl(f, t, <expression error>)) bind_tuple(std::tuple<_Tps ...>, std::tuple<_Elements ...>)'    
 auto bind_tuple(std::tuple<Fs...> f, std::tuple<Ts...> t)    
      ^~~~~~~~~~    
main.cpp:89:6: note:   template argument deduction/substitution failed:
main.cpp:91:68:错误:在“')标记之前应该有主表达式
->decltype(bind_tuple_impl(f,t,std::index_sequence_for))
^    
main.cpp:在函数“decltype(bind_tuple_impl(f,t,))bind_tuple(std::tuple,std::tuple)”中:
main.cpp:94:63:错误:在“')标记之前应该有主表达式
返回bind\u tuple\u impl(f,t,std::index\u sequence\u for);
^    
main.cpp:在函数“int main()”中:
main.cpp:102:34:错误:调用“bind_tuple(std::tuple&,std::tuple&)”时没有匹配的函数
自动绑定=绑定元组(f,t);
^    
main.cpp:89:6:注:候选:“模板decltype(bind_tuple_impl(f,t,))bind_tuple(std::tuple,std::tuple)”
自动绑定(std::tuple f,std::tuple t)
^~~~~~~~~~    
main.cpp:89:6:注意:模板参数扣除/替换失败:
此处:

return bind_tuple_impl(f, t, std::index_sequence_for<Fs...>);
返回bind\u tuple\u impl(f,t,std::index\u sequence\u for);

std::index\u sequence\u for
只是一种类型。您需要实例化它:

return bind_tuple_impl(f, t, std::index_sequence_for<Fs...>{});
返回bind_tuple_impl(f,t,std::index_sequence_for{});

在您的
decltype
中做同样的更改(或者干脆去掉尾随的返回类型,让
auto
完成它的工作!)。

std::index\u sequence\u for{}
std::index\u sequence\u for
是一个类型,您需要传递一个objectyup。我现在觉得自己很笨。谢谢你的回复!