mercredi 20 décembre 2017

What does a C++ compiler do with this initializer list?

When using an initializer list such as this:

for (int i : {3, 1, 6, 4})
{
    std::cout << "i=" << i << std::endl;
}

The ouput is in the same order, 3, 1, 6, and finally 4. So I know the compiler must be using something similar to std::vector<int> and not std::set<int>.

Is this guaranteed? Where can I find the docs that explain how the compiler must interpret {3, 1, 6, 4}.

Aucun commentaire:

Enregistrer un commentaire