Foward iterators

D

Dave

Can anybody offer a specific example of an iterator that has the
capabilities of a forward iterator but no more?
 
A

Andrew Koenig

Can anybody offer a specific example of an iterator that has the
capabilities of a forward iterator but no more?

Look at the sequence class in chapter 15 of "Ruminations on C++."

That class offers behavior similar to Lisp lists, but with the restriction
that all elements of a sequence must have the same type. It also has the
interesting property that the container and iterator classes are the same
type.
 
H

Howard Hinnant

Dave said:
Can anybody offer a specific example of an iterator that has the
capabilities of a forward iterator but no more?

The iterators of a singly linked list are such an example. You can't
iterate backwards (in constant time).

-Howard
 
H

Howard Hinnant

Andre Kostur said:
Or an istream iterator....

Actually not really, at least if we're using the std::definition of
"forward". A std::istream_iterator fails to meet the forward spec
because it can not be used in multi-pass algorithms. The standard terms
iterators in this class as "input iterators" which have a subset of the
functionality of forward iterators.

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top