模板模板可变参数专业化

Template template variadic parameter specialization

我想知道是否可以通过以下方式专门化模板:

template<typename... Ts>
class Typelist { };

template<template<typename> typename... TTs>
class Typelist<TTs<typename>> { };   //I don't know if that is the right syntax, at least the compiler doesn't complain

我希望它作为模板化类型列表和非模板化类型列表工作:

template<typename T>
class AT {};

template<typename T>
class BT {};

template<typename T>
class CT {};

int main() {

    using tl1 = Typelist<int, float, double>;   //works fine
    using tl2 = Typelist<AT, BT, CT>;   //gives an error

}

编辑:

如果我将第二个 Typelist 声明为单独的类型,它就可以工作...

template<template<typename> typename... TTs>
class Typelist2 { };

//...
using tl2 = Typelist2<AT, BT, CT>;   //compiler doesn't complain and it works fine

我想知道是否可以只对这两种情况使用 Typelist,这样 Typelist2 就不必是一个单独的类型。

有人可以帮我吗?

I was wondering though if it was possible to use only Typelist for both cases so that Typelist2 doesn't have to be a seperate type.

我不这么认为。

因为TypeList定义为template<typename... Ts>template<template<typename> typename... TTs>;这两个定义不能一起工作。

我能想到的最好的帮助是为简单类型定义一个 TypeList 基本版本

template <typename ... Ts>
struct TypeList
 {
   // here you can use Ts...
 };

和容器的专门化(其中只有一个类型)如下

template <template <typename> class ... Tts, typename ... Ts>
struct TypeList<Tts<Ts>...>
 {
   // here you can use Ts... and Tts...
 };

您可以在哪里使用 TsTts

但这不是一个很好的解决方案,因为您不能将容器 TypeList 简单地定义为

TypeList<AT, BT, CT> tcl;

但您必须添加包含的虚拟 (?) 类型,如下所示

TypeList<AT<int>, BT<float>, CT<double>> tl2;

另一个问题是你不能把它们混在一起,所以

TypeList<AT<int>, BT<float>, double> tl;

调用 TypeList 的基本版本(无容器)。