假设您有一个元组类型,并且您想要提取其模板参数包以实例化另一个模板。如果那是一个类型模板,那么我可以有一个这样的实用程序:
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...>;
};
但是,如果所需的模板是可变模板怎么办?虽然template <typename...> typename What
是类型模板的“占位符”,但变量模板的“占位符”是什么?
我已经为 clang-4.0.0(目前唯一支持具有自动类型的非类型模板参数的编译器)尝试了以下操作,但它失败了。实际上我不确定这是否是 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...>;
};