Advanced
minutes
Class Templates Terminology
Overview of generic programming and class template concepts in this chapter.
Last updated:
Class Templates Terminology Reference
This reference provides an overview of class templates terminology you'll encounter in this chapter. Use it as a quick lookup guide.
Template Basics
| Term | Definition | Example |
|---|---|---|
| Class Template | Blueprint for creating classes with type parameters | template<typename T> class Container { }; |
| Template Parameter | Placeholder for type or value in template | typename T, int N |
| Template Argument | Actual type or value when instantiating template | Container<int>, Array<double, 10> |
| Template Instantiation | Compiler generating concrete class from template | Container<int> c; creates int version |
| Template Specialization | Custom implementation for specific type | template<> class Container<bool> { }; |
| Explicit Instantiation | Forcing compiler to generate template instance | template class Container<int>; |
Template Parameters
| Term | Definition | Example |
|---|---|---|
| Type Parameter | Template parameter representing a type | template<typename T> or template<class T> |
| Non-type Parameter | Template parameter for constant value | template<int Size>, template<bool Flag> |
| Template Template Parameter | Template parameter that is itself a template | template<template<typename> class Container> |
| Parameter Pack | Variable number of template parameters | template<typename... Args> |
| Default Template Argument | Default value for template parameter | template<typename T = int> |
| typename Keyword | Declares type parameter or dependent type name | typename T::value_type |
Template Member Functions
| Term | Definition | Example |
|---|---|---|
| Member Function Template | Template function inside class | template<typename U> void convert(U value); |
| Template Method | Regular method of template class | void add(const T& value); |
| Template Constructor | Constructor in template class | Container(const T& initial); |
| Conversion Constructor | Constructor enabling type conversion | template<typename U> Container(const Container<U>&); |
| Out-of-class Definition | Defining template member outside class | template<typename T> void Container<T>::clear() { } |
Specialization
| Term | Definition | Example |
|---|---|---|
| Full Specialization | Complete replacement for specific types | template<> class Container<bool> { }; |
| Partial Specialization | Specialization for subset of types | template<typename T> class Container<T*> { }; |
| Primary Template | Original unspecialized template | Base template definition |
| Specialization for Pointer | Common specialization for pointer types | template<typename T> class Array<T*> { }; |
| Function Template Specialization | Specializing member function only | Cannot partially specialize functions |
Template Concepts and Constraints
| Term | Definition | Example |
|---|---|---|
| Concept | Named requirement on template parameter (C++20) | template<std::integral T> |
| Requires Clause | Boolean expression constraining template | requires std::is_copy_constructible_v<T> |
| Type Trait | Compile-time type property query | std::is_integral<T>::value |
| SFINAE | Substitution Failure Is Not An Error | Used for template overload selection |
| enable_if | Conditionally enable template instantiation | std::enable_if_t<condition, T> |
| static_assert | Compile-time assertion | static_assert(sizeof(T) > 0); |
Dependent Types
| Term | Definition | Example |
|---|---|---|
| Dependent Name | Name depending on template parameter | T::value_type, Container<T>::iterator |
| typename Disambiguator | Telling compiler name is a type | typename T::value_type x; |
| template Disambiguator | Telling compiler name is a template | obj.template func<int>(); |
| Non-dependent Name | Name not depending on template parameter | Known at template definition time |
| Two-phase Lookup | Names resolved at definition and instantiation | Dependent vs non-dependent lookup |
Template Instantiation
| Term | Definition | Example |
|---|---|---|
| Implicit Instantiation | Compiler generates code when template used | Container<int> c; triggers instantiation |
| Explicit Instantiation | Manually requesting template instantiation | template class Container<int>; |
| Instantiation Point | Location where template is instantiated | Affects name lookup |
| Template Definition Required | Template definition must be visible | Usually in header files |
| Extern Template | Suppressing implicit instantiation | extern template class Container<int>; |
Template Friends
| Term | Definition | Example |
|---|---|---|
| Non-template Friend | Regular function as friend of template | friend void display(const Container&); |
| Template Friend | Template function as friend | template<typename U> friend class Other; |
| Bound Friend | Friend tied to specific instantiation | friend void func<T>(Container<T>&); |
| Unbound Friend | Friend independent of template parameter | template<typename U> friend void func(U); |
Variadic Templates
| Term | Definition | Example |
|---|---|---|
| Variadic Template | Template accepting variable number of arguments | template<typename... Args> |
| Parameter Pack | Sequence of template parameters | Args... |
| Pack Expansion | Expanding parameter pack | Args... args |
| sizeof... | Number of elements in pack | sizeof...(Args) |
| Fold Expression | Applying operator to all pack elements | (args + ...) (C++17) |
| Recursive Template | Processing pack elements recursively | Base case + recursive case |
Template Design Patterns
| Term | Definition | Example |
|---|---|---|
| CRTP | Curiously Recurring Template Pattern | class Derived : public Base<Derived> |
| Policy-based Design | Using template parameters for policies | template<typename T, typename Allocator> |
| Traits Class | Template providing type information | std::iterator_traits<T> |
| Type Erasure | Hiding type through abstraction | std::function, std::any |
| Expression Templates | Templates for lazy evaluation | Mathematical expression optimization |
| Mixin Class | Template base providing functionality | Adding capabilities via inheritance |
Type Deduction
| Term | Definition | Example |
|---|---|---|
| Template Argument Deduction | Compiler inferring template arguments | make_pair(1, 2.0) deduces types |
| CTAD | Class Template Argument Deduction (C++17) | std::vector v{1, 2, 3}; deduces int |
| Deduction Guide | Custom rules for CTAD | template<typename T> Container(T) -> Container<T>; |
| Auto Return Type | Deducing return type automatically | auto func() { return value; } |
| decltype | Querying type of expression | decltype(expr) |
How did you find this lesson?
Your rating helps us improve the content.
Create an account to track your progress and access interactive exercises. Already have one? Sign in.
Class Templates Terminology - Quiz
Test your understanding of the lesson.
7 questions
~6 min expected
60% to pass
Lesson Discussion
Share your thoughts and questions
💬
No comments yet. Be the first to share your thoughts!