std::vector<bool>
uses proxy iterators.
So the following code will not compile (code taken from the accepted answer in related question ):
vector<bool> v = {true, false, false, true};
for (auto& x : v)
x = !x;
In the related question, the accepted answer states that to modify the components of the vector in place, we must use
for (auto&& x : v)
x = !x;
But if I simply do:
for (auto x : v)
x = !x;
This produces identical results. So is the &&
not needed?
Further why does the following 2 codes not modify the components?
for (bool &&x : v)
x = !x;
and
for (bool x : v)
x = !x;