Say you have a tuple type and you want to extract its template parameter package to create an instance of another template. If this is a type template, then I might have a utility like this:
template < typename Tuple, template <typename...> typename What > struct PutTupleInT; template < typename... Types, template <typename...> typename What > struct PutTupleInT<std::tuple<Types...>, What> { using Result = What<Types...>; };
But what if the desired template is a variable template? While template <typename...> typename What is a placeholder for a type template, what is a placeholder for a variable template?
I tried the following for clang-4.0.0 (the only compiler that now supports non-Pig type template parameters with automatic type), but this failed. Actually, I'm not sure if this is the correct syntax for C ++ 17.
template < typename Tuple, template <typename...> auto What > struct PutTupleInV; template < typename... Types, template <typename...> auto What > struct PutTupleInV<std::tuple<Types...>, What> { static constexpr auto value = What<Types...>; };
c ++ c ++ 14 c ++ 17 template-templates variable-templates
Vahagn
source share