I\'m taking a self-study course for C++, learning how the Standard Library works, and I want to understand how this code that uses for_each
works, particularly
The problem is that you are not allowed to modify elements in a std::set
. If it were possible, then how would it handle something like this:
std::set my_set { 1, 2, 3 };
int& foo = *(my_set.begin());
foo = 2;
Now there is two elements with value 2. That doesn't make sense in a set
due to
std::set is an associative container that contains a sorted set of unique objects of type Key.
(emphasis mine)
http://en.cppreference.com/w/cpp/container/set