user2889159
user2889159

Reputation:

What does template-parameter-list of template parameter mean

There is a quote from 3.3.9/1:

The declarative region of the name of a template parameter of a template template-parameter is the smallest template-parameter-list in which the name was introduced.

Can you give an example to understand the above definition? I am also interested in knowing what does the template-parameter-list of a template parameter mean? An example will be helpful.

Upvotes: 5

Views: 93

Answers (2)

user657267
user657267

Reputation: 21000

It limits the scope of template template parameters to the innermost parameter list, for instance the following is valid

template<template<typename U, typename V = U> class T>
struct foo
{
  T<int> bar(); // T<int, int>
};

But this is not

template<template<typename U> class T>
struct foo
{
  U bar(); // error: ‘U’ does not name a type
};

Upvotes: 2

Potatoswatter
Potatoswatter

Reputation: 137820

template< // outer template-parameter-list
    template< // inner template-parameter-list
        typename q, // named parameter of a template template-parameter
        q x // use that name
    > // the declarative region ends here
    class q // hence the name may be reused
> struct x {};

Here it is again without comments if that helps to follow along:

template< template< typename q, q x > class q >
struct x {};

It's a class parameterized on a template taking a constant value of a given type. You could for example have x< std::integral_constant >.

Upvotes: 5

Related Questions