Structured binding

korkhg15·2022년 6월 11일


목록 보기

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; = 1.0, = 2.0, = 3.0;
auto [x, y, z] = point;

0개의 댓글