0

在 range-v3 中,以下是 c++17 的合法代码。

CardDeck::CardDeck() {
    std::vector<Suit> Suits = {Clubs, Diamonds, Hearts, Spades};
    std::vector<Value> Values = {Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace};
    for (auto [value, suit] : ranges::view::cartesian_product(Values, Suits))
        this->Cards.emplace_back(value, suit);
    this->shuffle();
}

我从来没有在auto [value, suit]任何地方看到过这种语法,有人可以解释一下什么时候可以吗?
是否有关于何时可以使用它的一般解释,或者它是来自范围库的魔法?

4

0 回答 0