본문 바로가기

프로그래밍 언어 노트/C++ | Modern C++

[Modern C++] C++ structured binding

    int array[3] = { 0,1,2 };
    auto tuple = std::make_tuple(1, 2);
    Struct s = Struct{ 1,2 };

    // Structured binding
    auto [x, y, z] = array;
    auto [t1, t2] = tuple;
    auto [s1, s2] = s;

    std::cout << x << '\t' << y << '\t' << z << std::endl;
    std::cout << t1 << '\t' << t2  << std::endl;
    std::cout << s1 << '\t' << s2 << std::endl;

destructuring같은거... 라고 봐야되나?

C++17 에서 추가된 기능

배열,튜플(튜플like), 구조체같은것의 데이터를 받을때

손쉽게, 하나하나 받을필요없이 한번에 받으면 알아서 잘 들어가게 할수있다.

728x90

'프로그래밍 언어 노트 > C++ | Modern C++' 카테고리의 다른 글

[Modern C++] Partition  (0) 2019.12.21
[Modern C++] Fold 표현  (0) 2019.12.21
[Modern C++] C++ 의 커링  (0) 2019.12.18
[Modern C++] C++ 의 map, reduce, filter  (0) 2019.12.18
[Modern C++] C++ 코루틴  (0) 2019.07.09