Commit 8c822b1eb4d4fa9121048f79922dc23a8336c22b

Authored by Grzegorz Jabłoński
1 parent 28f14253

Added two examples of dealing with tuples

examples11/06-template_metaprogramming/testvector.cpp
@@ -14,13 +14,24 @@ int main() { @@ -14,13 +14,24 @@ int main() {
14 a.push_back("5"); 14 a.push_back("5");
15 a.push_back("6"); 15 a.push_back("6");
16 a.push_back("7"); 16 a.push_back("7");
17 - a.reserve(11); // to avoid reallocation and reference invalidation  
18 - auto [x, y, z] = a.push_back("8", "9", "10"); 17 + a.reserve(10); // to avoid reallocation and reference invalidation
  18 +
  19 + std::tuple<string&, string&, string&> c = a.push_back("8", "9", "10");
  20 +
19 printvector(a); 21 printvector(a);
20 - x = "108";  
21 - y = "109";  
22 - z = "110";  
23 - string arg = "11"; 22 +
  23 + get<0>(c) = "108";
  24 + get<1>(c) = "109";
  25 + get<2>(c) = "110";
  26 +
  27 + printvector(a);
  28 +
  29 + a.reserve(12);
  30 + auto [x, y] = a.push_back("11", "12");
  31 + x = "111";
  32 + y = "112";
  33 +
  34 + string arg = "13";
24 a.push_back(arg); 35 a.push_back(arg);
25 b = a; 36 b = a;
26 printvector(b); 37 printvector(b);