4
votes

In the C++ Standard in chapter 14 (Templates) it refers to template parameters with several different names, depending on their context.

non-type parameter

 template<int N>
 class foo {};

template parameter

template<typename T>
class bar {};

type-parameter

 ?????

In this quote below, it makes it seem like these are three distinct things, however I can't figure out what type-parameter is?

14.1 Template parameters [temp.param]

9 ... A default template-argument may be specified for any kind of template-parameter (type, non-type, template) that is not a template parameter pack (14.5.3). ...

You can see here that it has three distinct names for template parameters. If template-parameter was a generalization of the other two, then why include that in the list above.

In section 14.1.2 it then refers to them as just type and non-type, and the template-parameter as a generalization.

So what is it? Can someone explain?

2

2 Answers

5
votes

In the context you are using this wording, "template parameters" are parameters which are class templates. For instance:

template<template<typename, typename> class T, typename U, int N>
struct { ... };

Here, T is a template parameter, U is a type parameter, and N is a non-type parameter.

In section 14.1.2 it then refers to them as just type and non-type, and the template-parameter as a generalization.

Here it is important to disambiguate the use of the word "template". In many contexts, it is just used to indicate that those are parameters "of a template" (as opposed to parameters of a function, for instance). In that case, these categories become (respectively) "template template parameters", "template type parameters", and "template non-type parameters".

Also, in some situations the first category is also considered to define a "non-type parameter", because the arguments which can be provided for it are not types (they are templates). Therefore, sometimes you may find the wording "non-type, non-template parameters" to refer strictly to the third category (i.e. the category of N above).

Also see footnote 136 to Paragraph 14.1/2 of the C++11 Standard:

Since template template-parameters and template template-arguments are treated as types for descriptive purposes, the terms non-type parameter and non-type argument are used to refer to non-type, non-template parameters and arguments.

7
votes

It's saying that there are three types of template-parameter:

  1. Type template parameter

    template<typename T>
    class bar {};
    
  2. Non-type template parameter

    template<int N>
    class foo {};
    
  3. Template template parameter

    template<template<class> class T>
    class baz {};
    

I do however agree that this is badly defined. In the grammar, a template-parameter that begins with template is one of the possible productions of type-parameter.