Why does range-for over const vector<Thing>
yield const Thing
?
I thought fn_a
would compile fine :
#include <vector>
class Some {
public:
void not_const();
};
void fn_a ( const std::vector<Some> &vs) {
for( Some &s : vs )
s.not_const();
}
void fn_b ( std::vector<Some const> &vs) {
for( Some &s : vs )
s.not_const();
}
Errors ( omitting some others ):
a.cc:10:21: error: binding reference of type ‘Some&’ to ‘const Some’ discards qualifiers
a.cc:16:21: error: binding reference of type ‘Some&’ to ‘const Some’ discards qualifiers
Q: Is it possible to range-for over a const vector and get mutable elements ?