Consider this code example:
#include
#include
using namespace std;
set string_set;
void foo(const string& a)
{
Because according to the standard, modifications through
a set<>::iterator
are not allowed. The standard specifically
allows set<>::iterator
and set<>::const_iterator
to be the
same type. And although it doesn't require them to be the same
type, it does require the value_type
of set<>::iterator
to
be const
.
The reason for this, of course, is that any modifications to the
value could invalidate the invariants of std::set<>
.