Re: Rationale behind variadic template template argument matching
On 7 mrt, 03:42, Rodolfo Lima <rodl...@gmail.com> wrote:
(W)hy (is) the
following code (taken from the example in the proposal with a little
modification) ill-formed?
template<class T, class U> class B { /*... */ };
template<template<class...> class Q> class Y { /*... */ };
Y<B> yb; // ill-formed: a template parameter pack does not match a
template parameter
The definer of Y should be able to assume that Q is a template class
with a variadic nr of arguments; Y<B> violates that assumption.
B is not a valid substitution for Q since it cannot be instantiated
with 3 type parameters. Think of concepts:
the template parameter specification defines a contract between the
definer and the instantiator.
For example:
//=============
template<class T, class U> class B { /*... */ };
template<template<class...> class Q> class Y
{
typename Q<int, float, bool> Z;
};
Y<B>::Z z; // what is Z?
//=============
What I don't understand is why susbtitution the other way is also
forbidden.
Quoting the other part of the same example (page 8 of N2242):
template<class T> class A { /* ... */ };
template<class T, class U = T> class B { /* ... */ };
template<class... Types> class C { /* ... */ };
template<template<class> class P> class X { /* ... */ };
X<A> xa; // okay
X<B> xb; // ill-formed (...)
X<C> xc; // ill-formed (...)
I don't see why P cannot be substituted by B or C since both B and C
can be
used in the way that is specified for P,
that is: instantiate it with one (non-default) parameter.
Can anybody clarify?
Greetings,
Maarten.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]