gpt4 book ai didi

C++11 : Is it possible to give fixed-template-parameted template to varidic-template-template-parameter?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:24:09 27 4
gpt4 key购买 nike

(是的,由于我糟糕的英语,标题很奇怪;我希望有人能改进它。)

接听this question ,我发现这段代码有效:

template <typename T1, typename T2> class A { };
template <template <typename...> class U> class B { };

int main()
{
B<A> it_works;
}

..虽然template <typename...> classtemplate <typename, typename> class不相等。

我试图弄清楚为什么这是可能的,并观察了 N3337 standard 的 [temp.param] ,但我找不到任何东西。怎么可能?

最佳答案

是的,这是可能的。 C++ 11 14.3.3/3 特别允许,并提供了一个例子。

3 A template-argument matches a template template-parameter (call it P) when each of the template parameters in the template-parameter-list of the template-argument’s corresponding class template or alias template (call it A) matches the corresponding template parameter in the template-parameter-list of P. When P’s template-parameter-list contains a template parameter pack (14.5.3), the template parameter pack will match zero or more template parameters or template parameter packs in the template-parameter-list of A with the same type and form as the template parameter pack in P (ignoring whether those template parameters are template parameter packs) [ Example:

template <class T> struct eval;

template <template <class, class...> class TT, class T1, class... Rest>
struct eval<TT<T1, Rest...>> { };

template <class T1> struct A;
template <class T1, class T2> struct B;
template <int N> struct C;
template <class T1, int N> struct D;
template <class T1, class T2, int N = 17> struct E;

eval<A<int>> eA; // OK: matches partial specialization of eval
eval<B<int, float>> eB; // OK: matches partial specialization of eval
eval<C<17>> eC; // error: C does not match TT in partial specialization
eval<D<int, 17>> eD; // error: D does not match TT in partial specialization
eval<E<int, float>> eE; // error: E does not match TT in partial specialization

—end example ]

(强调我的)

关于C++11 : Is it possible to give fixed-template-parameted template to varidic-template-template-parameter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26060176/

27 4 0