Search⌘ K
AI Features

Template Parameter

Explore the kinds of template parameters in Modern C++ including type, non-type, and template-template types. Understand how dependent names affect template lookup and how to guide the compiler using typename and .template keywords.

Template Parameter

Every template is parametrized by one or more template parameters, indicated in the parameter-list of the template.

C++ supports three different kinds of template parameter:

1. Type parameter

std::vector<int> vec = {1, 2, 3, 4, 5}; 

2. Non-type parameter

std::array<int, 5> arr = {1, 2, 3, 4, 5};

3. Template-template Parameter

template <typename T, template <typename, typename> class Cont> 
class Matrix{ ...
Matrix<int, std::vector> myIntVec;

Types

Type parameters are of class types and fundamental types. ...