gpt4 book ai didi

c++ - decltype 返回的模板推导/替换错误

转载 作者:行者123 更新时间:2023-11-28 04:27:50 32 4
gpt4 key购买 nike

<分区>

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

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

我是不是完全错了?我是否遗漏了一些明显的东西

template <class Fs, class Ts, std::size_t... Is>
auto bind_tuple_impl(std::tuple<Fs> f, std::tuple<Ts> t, std::index_sequence<Is...>)
-> decltype(std::make_tuple(std::bind(std::get<Is>(f),std::get<Is>(t))...))
{
return std::make_tuple(std::bind(std::get<Is>(f),std::get<Is>(t))...);
}

template <class... Fs, class... Ts>
auto bind_tuple(std::tuple<Fs...> f, std::tuple<Ts...> t)
-> decltype(bind_tuple_impl(f, t, std::index_sequence_for<Fs...>))
{
return bind_tuple_impl(f, t, std::index_sequence_for<Fs...>);
}

int main()
{
std::tuple<std::function<void(double)>> f;
std::tuple<double> t;

auto f_bound = bind_tuple(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:

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com