Variadic Class Templates
Gain valuable insights into variadic class templates through the implementation and analysis of a basic tuple class.
Class templates may also have a variable number of template arguments. This is key to building some categories of types, such as tuple
and variant
, that are available in the standard library. In this lesson, we’ll see how we could write a simple implementation for a tuple
class. A tuple is a type that represents a fixed-size collection of heterogeneous values.
Implementing variadic class templates
When implementing variadic function templates, we used a recursion pattern with two overloads, one for the general case and one for ending the recursion. The same approach has to be taken with variadic class templates, except that we need to use specialization for this purpose. Next, we can see a minimal implementation for a tuple:
Get hands-on with 1200+ tech skills courses.