Friday, July 7, 2017

C++11: range-for

The following are examples of the ‘range-for’ statement:
for (auto element : vector) {}
for (auto& element : vector) {}
for (const auto element : vector) {}
for (const auto& element : vector) {}

The first returns copies of the vector elements in the loop, and the second returns references to the vector elements in the loop. The third and fourth examples are const versions of the first two.

No comments:

Post a Comment