Today I wrote a small predicate to find matching symbols in a container.
But I’m faced to a problem: I want to use this predicate in a std::find_if call inside a const-method of a class, searching in a container that is a member of this class.
But I just noticed that neither std::find nor std::find_if are able to operate on const_iterators !
I checked on some C++ references and it seems there is no version of std::find or std::find_if that accept/return const_iterators. I just can’t understand why, since from what I’ve seen, there is no way that these algorithms could modify the object referenced by the iterator.
Here is how is documented std::find in the SGI implementation:
Returns the first iterator i in the
range [first, last) such that *i ==
value. Returns last if no such
iterator exists.
std::findandstd::find_ifcan definitely operate on*::const_iteratorfor a given container. Are you by chance looking at the signatures of those functions, and misunderstanding them?Note that
InputIteratorhere is just a name of a template type parameter, and anyconst_iteratorwill satisfy the requirements for it.Or, perhaps, you’re confusing
const_iterator(i.e. an iterator referencing a const value) with aconstiterator (i.e. an iterator which is itselfconst)?