如何为模板类型创建别名?

Igo*_*gor 3 c++ templates template-meta-programming c++11 template-aliases

我有一些模板类,其声明如下所示:

template <typename T, typename A, typename B, typename C>
class foo1;

template <typename T, typename A, typename B, typename C>
class foo2;

...
Run Code Online (Sandbox Code Playgroud)

我用它们在以下方面(每foo*进行实例化A,并BCbar用实例化):

template <typename A, typename B, typename C>
class bar {
    foo1<int, A, B, C> f1;
    foo2<int, A, B, C> f2;
    foo2<char, A, B, C> f3;
};
Run Code Online (Sandbox Code Playgroud)

为了简单和清晰的原因,我希望能够省略A,B并且C内部的参数bar只是写:

...
foo1<int> f1;
...
Run Code Online (Sandbox Code Playgroud)

我知道我可以为所有foo类型使用别名模板,如下所示:

template <typename T>
using foo1_a = foo1<T, A, B, C>;
Run Code Online (Sandbox Code Playgroud)

但是foo类型可能有很多,它需要为所有类型创建别名.

我试图将所有这些别名放在一个类中:

template <typename A, typename B, typename C>
class types {
    template <typename T>
    using foo1_a = foo1<T, A, B, C>;

    ...
};
Run Code Online (Sandbox Code Playgroud)

然后使用看起来像这样:

...
using t = types<A,B,C>;
typename t::template foo1_a<int> f1;
...
Run Code Online (Sandbox Code Playgroud)

但在我看来,这看起来更糟糕......

是否有可能以其他方式实现这一目标?

max*_*x66 7

关于什么

template <template <typename...> class Cnt, typename T>
using bar = Cnt<T, A, B, C>;
Run Code Online (Sandbox Code Playgroud)

用过的

bar<foo1, int> f1;
bar<foo2, int> f2;
bar<foo2, char> f3;
Run Code Online (Sandbox Code Playgroud)