17.1.1. Defining and Initializing tuples

When we define a tuple, we name the type(s) of each of its members:

tuple<size_t, size_t, size_t> threeD; // all three members set to 0tuple<string, vector<double>, int, list<int>>    someVal("constants", {3.14, 2.718}, 42, {0,1,2,3,4,5});

When we create a tuple object, we can use the default tuple constructor, which value initializes (§ 3.3.1, p. 98) each member, or we can supply an initializer for each member as we do in the initialization of someVal. This tuple constructor is explicit7.5.4, p. 296), so we must use the direct initialization syntax:

tuple<size_t, size_t, size_t> threeD =  {1,2,3};  // errortuple<size_t, size_t, size_t> threeD{1,2,3};      // ok

Alternatively, similar to the make_pair ...

Get C++ Primer, Fifth Edition 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.