error: invalid conversion from `constint* const' to `int*'
Any ideas? I'd really like to understand the problem here. Maybe it's an error within g++. Could someone try another compiler (and uncomment the stuff)?
Using const_iterators here works with both compiler versions (and makes more sense in this situation), but why does the first version with the temporary vector<int> still work. Is it generally impossible/forbidden to use normal iterators here?
The type(name)s used are just there to provide a minimal failing example, of course.
Update: OK, the assignment of the temporary variable actually copies the vector and prints out these values, I see it now.
It would seem dereferencing any iterator (both const and non-const) returns a const reference, and using begin() on that reference returns therefore a const_iterator, which of course can't be assigned to a non-const_iterator.
set<>::iterator is the same as set<>::const_iterator. The container cannot allow you to modify an element of it through an iterator since doing so may break the container's invariant (the sort order and the uniqueness of all elements).