Why does const_iterator not provide a const_iterator::base() function, to obtain corresponding non-const iterator like reverse_iterator does?
Considering following pseudocode (say, geometric algorithm):
std::container< point > universe; auto it = std::cbegin(universe); std::list< decltype(it) > interesting_subset = sieve(it, std::cend(universe)); auto structure = algorithm(interesting_subset); where universe is all the input points. After sieve()-ing the interesting_subset contains iterators to subset of universe's members. Following algorithm() constructs a resulting structure from interesting_subset, which consists of references (iterators) to members of the universe.
At the end, I want to change the points, containing into resulting structure (say, shift them). But equally I want to protect them from modyfining during algorithm action, and therefore I used std::cbegin/std::cend as opposite to std::begin/std::end. Finally I have only const_iterator references to source points.
This is a very use case for iterator std::container< T >::const_iterator::base() const member function I want to be present into STL containers.
const?const_iterator(say, the current should be replaced withreally_const_iterator=).std::cbegin(non_const_container)should return augmented version ofconst_iteratorhaving member functionbase().containersupports random access iterators, you can easily convertitto a non-const version usingauto offset = it - cbegin(universe); auto new_it = begin(universe) + offset;. If it is not random access, this will be less efficient.std::addressof(*cit) == std::addressof(*it)comparison. But it results in additional quadratic complexity step to find all the coresponding elements.