A template template parameter is a template parameter that acts as a placeholder expecting an uninstantiated class template or alias template as its argument. It allows a host template to receive a template rather than a fully instantiated type, granting the host template the authority to instantiate the provided template internally using types, non-type parameters, or other templates of its own choosing.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Syntax
The declaration of a template template parameter requires its own nested template parameter list. This nested list defines the exact signature (arity and parameter kinds) of the templates that can be passed as arguments.class was strictly required to declare a template template parameter. Since C++17, typename is also permitted and functionally identical in this context:
Parameter Matching Rules
When passing a template argument to a template template parameter, the compiler enforces matching rules between the nested parameter list and the provided template. Pre-C++17 (Strict Matching): The parameter list of the argument template must exactly match the parameter list of the template template parameter. Default template arguments in the argument template are ignored during this evaluation.A is considered a valid match for a template template parameter P if P is at least as specialized as A. Because the parameter template <typename> class is more specialized than the argument template <typename, typename> class, and the extra parameters in the argument have default values, the match succeeds.
Variadic Template Template Parameters
Template template parameters can be variadic. A variadic template template parameter specifically expects a variadic template as its argument (a template that takes zero or more parameters). It will strictly reject fixed-arity templates, even if the fixed arity falls within the “zero or more” conceptual range.Mixing Parameter Kinds
The nested parameter list of a template template parameter can include type parameters, non-type template parameters (NTTPs), and even other template template parameters, dictating a highly specific signature.Restrictions
- Class and Alias Templates Only: Only class templates and alias templates can be passed as arguments to a template template parameter. Function templates and variable templates are strictly prohibited.
- Nested Parameter Names: The names of the parameters within the nested template parameter list (e.g.,
Uintemplate <typename U> class) cannot be referenced within the body of the host template. While they are often omitted for simple type parameters, they are strictly required if a subsequent parameter in the nested list depends on a previous one.
Master C++ with Deep Grasping Methodology!Learn More





