0

In range-v3 the following is legal code for 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();
}

I have never seen that syntax auto [value, suit] anywhere, could somebody explain when this is possible?
Is there a general explanation for when this may be used or is it magic from the ranges library?

0 Answers0