What is the auto Bracketed List Syntax?

2019-04-13 02:30发布

问题:

W.F. gave a now-deleted answer to my question here which used the line:

auto [x, y] = div_t{ 1, 0 };

From the code in the answer it looks like that's like a tie for the div_t struct. I was hoping that someone could explain what was going on here. The complete function code was as follows:

constexpr bool first_quot() {
    auto [x, y] = std::div_t{1, 0};
    (void)y;
    return x;
}

回答1:

In the most most recent draft of the C++17 specification it's called "Decomposition declarations" and is defined in section 8.5 [dcl.decomp].