On 2006-01-03, Mateusz ?oskot <se****@signature.net> wrote:
Neil Cerutti wrote: On 2006-01-03, Mateusz oskot <se****@signature.net> wrote: I'm talking about iterator categories in terms of operations
they provide.
Obviously, my english may be a limitation here.
I'll try to explain it more clear.
Input iterator category is based on following set of operations
(from Josuttis' STL book):
*iter
++iter
iter++
iter1 == iter2
iter1 != iter2
TYPE(iter)
Output iterator category operations list:
*iter = value (assignment)
++iter
iter++
TYPE(iter)
Forward iterator category is a combination of both sets of
operations above.
Now, I'm asking if I can define list of operations of my custom
iterator this way:
### Input ###
*iter
++iter
iter++
iter1 == iter2
iter1 != iter2
TYPE(iter)
### Bidirectional ###
--iter
iter--
As you can see, I've not applied set of operations from Output
iterator (or even from Forward iterator). But Bidirectional
iterator is assumed to provide those operations. So, how about
that?
You need to support all the operations of Forward iterators in a
Bidirectional iterator, or it won't qualify as one, and might not
work with standard algorithms that require Bidirectional
iterators.
This quote is from the SGI docs:
The illustration below displays the five iterator categories
defined by the standard library, and shows their hierarchical
relationship. Because standard library iterator categories are
hierarchical, each category includes all the requirements of
the categories above it.
Requirements of Forward Iterators
<SNIP>
Requirements of Bidirectional Iterators
A bidirectional iterator must meet all the requirements for
forward iterators. In addition, the following expressions must
be valid
<SNIP>
If your design is the best type of iterator for your container,
then you'll have to tag it as an Input or Output iterator, which
happens to support a few more operations than normal. Clients
won't be able to use it as a Bidirectional iterator, despite that
it can go both ways.
--
Neil Cerutti