(Yes, the title is so weird thanks to my poor English; I hope someone can improve it.)
Answering this question, I found that this code works:
template <typename T1, typename T2> class A { };
template <template <typename...> class U> class B { };
int main()
{
B<A> it_works;
}
..although template <typename...> class
and template <typename, typename> class
aren't equal.
I tried to figure out why it is possible and watch [temp.param] of N3337 standard, but I can't find anything. How is it possible?
Yes, it is possible to do so. C++ 11 14.3.3/3 specifically allows it, and provides an example.
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 itA
) matches the corresponding template parameter in the template-parameter-list ofP
. WhenP
’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 ofA
with the same type and form as the template parameter pack inP
(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 ]
(Emphasis mine)
[temp.arg.template] describes how template template arguments are matched with the corresponding parameter. In particular, C++11 14.3.3/3 says
When P’s template-parameter-list contains a template parameter pack, 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
where P is the parameter (U
in your example), and A the argument (A
in your example). So your example, with only a parameter pack, will match a template with any number of type parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With