The std::tuple container

The std::tuple is a statically sized heterogeneous container that can be declared to be of any size. In contrast to std::vector, for example, its size cannot change at runtime; you cannot add or remove elements.

A tuple is constructed with its member types explicitly declared like this:

auto tuple0 = std::tuple<int, std::string, bool>{}; 

This will make the compiler generate a class which can roughly be viewed like this:

class Tuple { 
public: 
  int data0_{};
  std::string data1_{}; 
  bool data2_{};
}; 

As with many other classes in C++, std::tuple also has a corresponding std::make_tuple function, which deduces the types automatically from the parameters:

auto tuple = std::make_tuple(42, std::string{"hi"}, true);

As you ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.