mercredi 19 décembre 2018

Template deduction/substitution error with decltype return

I have this code snippet here that takes a tuple of function pointers and a tuple of values and then binds the values to the function pointer and returns a new tuple with the bound functions.

When I call the bind_tuple_impl directly I don't have any errors, but it isn't really a practical way to call this routine. I also need to delay execution after the bind so just calling the function with the given parameter isn't an option.

Am I approaching this all wrong? Am I missing something obvious

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);
}

The error:

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:

Aucun commentaire:

Enregistrer un commentaire