Описание тега template-templates

Often used to refer to a template parameter that is itself a template.

A C++ template can have parameters which are types (such as int), non-types (such as the integer 2) or templates. The latter are called template template parameters.

For example this class template has a template template parameter called Templ and a template type parameter called Type:

template<template<typename> class Templ, typename Type>
  struct Apply
  {
    typedef Templ<Type> type;
  };

To instantiate the class template Apply the argument substituted for Templ must be the name of a class template or alias template taking a single type parameter e.g.

Apply<std::shared_ptr, int>::type ptr;

The nested typedef type is a synonym for std::shared_ptr<int>.

In the ISO C++ Standard, template template parameters are type parameters for convenience (and the name for the grammar production used to define them is called "type-parameter"), so care should be taken when working in the context of the Standard. Conversely, the phrase "non-type template parameter" is a template parameter that is neither a type nor a template in the ISO C++ Standard.

Sometimes, template template parameters are called template templates, but it is better to avoid this term to avoid misunderstandings - the term "template templates" could equally well refer to member templates that are members of class templates, in the absence of any definition in the ISO C++ Standard.

Use this tag for questions about writing and using templates that have template template parameters.