Search⌘ K
AI Features

Non-type Template Parameters

Explore how C++20 expands template capabilities with non-type parameters such as floating-point values, literal types, and string literals. Understand the structural requirements and benefits, including compile-time regular expressions, to write more versatile and type-safe templates.

C++ supports non-types as template parameters. Essentially non-types could be:

  • integers and enumerators
  • pointers or references to objects, to functions, and to attributes of a class
  • std::nullptr_t

🔑 Typical non-type template parameter

When I ask the students in my class if they ever used a non-type as template parameter they say: No! Of course, I answer my tricky question and show an often-used example for non-type template parameters:

std::array<int, 5> myVec;

Constant 55 ...