January 2018
Intermediate to advanced
374 pages
9h 53m
English
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 ...