I want to get the type of std::tuple argument, that is passed to function like variadic argument. This type I need to put into std::pair. So I don't have any information about types that user will put in std::tuple and what types will have std::pair after function return.
For example, call may be like this:
std::tuple t = std::make_tuple(18, "Test", 17.2);
std::pair<const char*, double> p = foo<1,2>(t);
Expected, that p will contain "Test" and 17.2.
I've tryed this code:
template<int N, int M, typename ... Args>
auto foo(std::tuple<Args...> t) -> std::pair< std::tuple_element<N, std::tuple<Args...>>::type,
std::tuple_element<M, std::tuple<Args...>>::type>
{
return std::tie(std::get<N>(t), std::get<M>(t));
}
But all that I get is compiler error:
Error C2923 'std::pair': 'std::tuple_element<M,std::tuple<_Rest...>>::type' is not a valid template type argument for parameter '_Ty2'
Error C2923 'std::pair': 'std::tuple_element<N,std::tuple<_Rest...>>::type' is not a valid template type argument for parameter '_Ty1'
What should I change to force this code to work?
Aucun commentaire:
Enregistrer un commentaire