August 2012
Intermediate to advanced
976 pages
30h 17m
English
tuplesWhen 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 explicit (§ 7.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 ...
Read now
Unlock full access