boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
101 stars 113 forks source link

set::iterator should be constant #176

Open alexkaratarakis opened 3 years ago

alexkaratarakis commented 3 years ago

boost::container::set's iterator is a mutable iterator. This allows modification of keys, which can destroy the container's invariants, for example when using the erase-remove idiom. This used to be a defect in std::set as well but has been fixed. As can be seen in cppreference

iterator | Constant LegacyBidirectionalIterator
const_iterator | Constant LegacyBidirectionalIterator

and in stdlib:

      // _GLIBCXX_RESOLVE_LIB_DEFECTS
      // DR 103. set::iterator is required to be modifiable,
      // but this allows modification of keys.
      typedef typename _Rep_type::const_iterator     iterator;
      typedef typename _Rep_type::const_iterator     const_iterator;