Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

template-parameter vs type-parameter vs non-type parameter

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?

like image 307
Tony The Lion Avatar asked Dec 16 '22 13:12

Tony The Lion


1 Answers

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.

like image 126
Joseph Mansfield Avatar answered Dec 28 '22 23:12

Joseph Mansfield