Boost logo

Boost Users :

Subject: [Boost-users] Boost Iterator: Limiting an existing iterator
From: אנטולי קרסנר (fr33domlover_at_[hidden])
Date: 2013-08-03 16:38:15


Hello,

I'm writing a C++ class which has an STL container as a data member, and
I'd like to write an iterator class which allows to iterate through the
container.

Which container is used, is implementation detail. I want the iterator
to be a ForwardIterator, even if a random-access container is used, e.g.
std::vector.

What's the quick and simple way to define an iterator adapter class
which uses the "base" iterator's functions, but only the ones supported
by a forward iterator?

The reason I need it is error detection. If the user gets a
random-access iterator and treats it as such, the compiler won't
complain, but in future versions of my code the user's code may break
because random access shouldn't really be supported, e.g. if I change
from vector to list.

Thanks in advance,
fr33domlover

Hmmm... I guess using boost::iterator_adapter should help


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net