프로그래밍/코드 조각
c++17 std::transform과 구조화된 바인딩 예제
제페
2017. 12. 4. 13:21
반응형
#include <iostream>
#include <tuple>
#include <algorithm>
#include <vector>
#include <string>
int main()
{
std::vector<int> a{
1,2,3,4,5
};
std::vector<std::string> b{
"6", "7", "8", "9", "10"
};
std::vector<std::tuple<int, std::string>> c;
std::transform(a.begin(), a.end(), b.begin(), std::back_inserter(c), [](auto a, auto b) {
return std::make_tuple(a, b);
});
for (auto v : c)
{
auto [x, y] = v;
std::cout << x << ',' << y << std::endl;
}
return 0;
}
구조화 된 바인딩이 c++17 스펙이다.
http://en.cppreference.com/w/cpp/language/structured_binding
결과
반응형