Structured binding

hogeol·2022년 6월 11일
0

C/C++

목록 보기
3/9

After c++17, The concept of structured binding is added

I'll give you some examples

if the array is defined,

std::array<int, 3> values = {11,22,33};

you can declare x, y, z variables based on values array

auto [x, y, z] = values;

It is neccesary for the left values(x, y, z) and the right values values is the same number

Another examples,

struct Point3d {double mx, my, mz; };
Point3d point;
point.mx = 1.0, point.my = 2.0, point.mz = 3.0;
auto [x, y, z] = point;

0개의 댓글