1. #include <string>
  2. #include <iostream>
  3. #include <list>
  4. #include <vector>
  5. #include "pivot.hpp"
  6.  
  7. void testcase4()
  8. {
  9. using namespace std;
  10. list<list<int>> alist;
  11. alist.push_back(list<int>{10, 20, 30});
  12. alist.push_back(list<int>{40, 50, 60});
  13.  
  14. vector<vector<double>> vlist;
  15. vlist.push_back({10, 20, 30});
  16. vlist.push_back(vector<double>{40, 50, 60});
  17.  
  18. vector<vector<string>> vstrlist;
  19. vstrlist.push_back(vector<string>{"s10", "s20", "s30"});
  20. vstrlist.push_back(vector<string>{"s40", "s50", "s60"});
  21.  
  22. list<list<wstring>> strlist;
  23. strlist.push_back(list<wstring>{L"ws10", L"ws20", L"ws30"});
  24. strlist.push_back(list<wstring>{L"ws40", L"ws50", L"ws60"});
  25.  
  26.  
  27. for (auto it : vlist)
  28. {
  29. const double nArr[] = { 1,2,3 };
  30. double age, weight, height;
  31. pivot::tie(age, weight, height) = nArr;
  32. pivot::tie(age, weight, height) = it;
  33. cout << "age: " << age
  34. << ", weight: " << weight
  35. << ", height: " << height << endl << endl;
  36. }
  37. for (auto it : alist)
  38. {
  39. int age, weight, length;
  40. pivot::tie(age, weight, length) = it;
  41. cout << "age: " << age
  42. << ", weight: " << weight
  43. << ", height: " << length << endl << endl;
  44. }
  45. for (auto it : vstrlist)
  46. {
  47. const char* nArr[] = {"a1","b1","c1"};
  48. const char *pcAge, *pcWeight, *pcHeight;
  49. pivot::tie(pcAge, pcWeight, pcHeight) = nArr; // non copy
  50. pivot::tie(pcAge, pcWeight, pcHeight) = it; // non copy
  51.  
  52. string age, weight, height;
  53. pivot::tie(age, weight, height) = it; // copy
  54.  
  55. cout << "age: " << age
  56. << ", weight: " << pcWeight
  57. << ", height: " << pcHeight << endl << endl;
  58. }
  59. #if defined(_MSC_VER)
  60. for (auto it : strlist)
  61. {
  62. const wchar_t* nArr[] = { L"a1", L"b1", L"c1" };
  63. const wchar_t *pcAge, *pcWeight, *pcHeight;
  64. pivot::tie(pcAge, pcWeight, pcHeight) = nArr; // non copy
  65. pivot::tie(pcAge, pcWeight, pcHeight) = it; // non copy
  66.  
  67. wstring age, weight, height;
  68. pivot::tie(age, weight, height) = it; // copy
  69.  
  70. wcout << L"age: " << age
  71. << L", weight: " << pcWeight
  72. << L", height: " << pcHeight << endl << endl;
  73. }
  74. #endif
  75. }


https://github.com/GuruWand/sswitch/blob/master/include/pivot.hpp


c++0x 이상 동작

vc++ 및 g++, clang++ 테스트완료.