mercredi 9 juin 2021

for loop with square brackets [duplicate]

        map<int, string> m = { {1,string("abc")},{2,string("ttt")}, };
        for (auto&[a, b] : m)
        {
            cout << a << b << endl;
        }

I know the other style for (auto &iter : m), iter is the pair of every element. But in this auto&[a, b], I'm the first time seeing it. Who can tell me the usage?

Edit: my question is for structured binding -- as Eljay prompted, not definitely for std::map looping.

Aucun commentaire:

Enregistrer un commentaire