- #include <string>
- #include <iostream>
- #include <list>
- #include <vector>
- #include "pivot.hpp"
- void testcase4()
- {
- using namespace std;
- list<list<int>> alist;
- alist.push_back(list<int>{10, 20, 30});
- alist.push_back(list<int>{40, 50, 60});
- vector<vector<double>> vlist;
- vlist.push_back({10, 20, 30});
- vlist.push_back(vector<double>{40, 50, 60});
- vector<vector<string>> vstrlist;
- vstrlist.push_back(vector<string>{"s10", "s20", "s30"});
- vstrlist.push_back(vector<string>{"s40", "s50", "s60"});
- list<list<wstring>> strlist;
- strlist.push_back(list<wstring>{L"ws10", L"ws20", L"ws30"});
- strlist.push_back(list<wstring>{L"ws40", L"ws50", L"ws60"});
- for (auto it : vlist)
- {
- const double nArr[] = { 1,2,3 };
- double age, weight, height;
- pivot::tie(age, weight, height) = nArr;
- pivot::tie(age, weight, height) = it;
- cout << "age: " << age
- << ", weight: " << weight
- << ", height: " << height << endl << endl;
- }
- for (auto it : alist)
- {
- int age, weight, length;
- pivot::tie(age, weight, length) = it;
- cout << "age: " << age
- << ", weight: " << weight
- << ", height: " << length << endl << endl;
- }
- for (auto it : vstrlist)
- {
- const char* nArr[] = {"a1","b1","c1"};
- const char *pcAge, *pcWeight, *pcHeight;
- pivot::tie(pcAge, pcWeight, pcHeight) = nArr; // non copy
- pivot::tie(pcAge, pcWeight, pcHeight) = it; // non copy
- string age, weight, height;
- pivot::tie(age, weight, height) = it; // copy
- cout << "age: " << age
- << ", weight: " << pcWeight
- << ", height: " << pcHeight << endl << endl;
- }
- #if defined(_MSC_VER)
- for (auto it : strlist)
- {
- const wchar_t* nArr[] = { L"a1", L"b1", L"c1" };
- const wchar_t *pcAge, *pcWeight, *pcHeight;
- pivot::tie(pcAge, pcWeight, pcHeight) = nArr; // non copy
- pivot::tie(pcAge, pcWeight, pcHeight) = it; // non copy
- wstring age, weight, height;
- pivot::tie(age, weight, height) = it; // copy
- wcout << L"age: " << age
- << L", weight: " << pcWeight
- << L", height: " << pcHeight << endl << endl;
- }
- #endif
- }
https://github.com/GuruWand/sswitch/blob/master/include/pivot.hpp
c++0x 이상 동작
vc++ 및 g++, clang++ 테스트완료.
댓글 0