Iterators on Vector

C

codefixer

Hello,

I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.

OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.

But I still want to know how to declare just an Input or Output
iterator on vector(is it possible ?)

What is the best reference to understand which(iterator) can be
declared on which(container) and how ?

Thanks.
 
T

Thomas Tutone

codefixer said:
I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.

Why would you want to? std::vectors (and the other predefined standard
containers) already have their iterators defined for you:
std::vector:iterator etc.
OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.

Correct (although the term is "random access iterator" rather than
"random iterator," and a std::vector is spelled with an uncapitalized
"v").
But I still want to know how to declare just an Input or Output
iterator on vector(is it possible ?)

A random access iterator has all the functionality of an input iterator
and all the functionality of an output iterator. You could define your
own iterator ("codefixer_iterator") for a vector that was just an input
iterator or just an output iterator, but that would be silly and a
waste of time when vector already has a random access iterator
predefined for you.
What is the best reference to understand which(iterator) can be
declared on which(container) and how ?

Josuttis's The C++ Standard Library.

But you seem to be missing the point. The standard containers already
have their iterators predefined, so you don't declare them.
std::vector, std::deque, and std::string have random access iterators.
std::list, std::set, and std::map have bidirectional iterators.
iterators into streams are typically either input or output iterators.
You typically define new iterators for new containers or sequences you
define, not for those already defined.

Best regards,

Tom
 
?

=?ISO-8859-1?Q?Stefan_N=E4we?=

Hello,

I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.

OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.

But I still want to know how to declare just an Input or Output
iterator on vector(is it possible ?)

What is the best reference to understand which(iterator) can be
declared on which(container) and how ?

The different iterator categories (input, output, etc.) are only
concepts. If a particular iterator type (e.g. vector<int>::iterator)
supports a specific set of operations it is of a particular category
(random access in the case of vector<int>::iterator).

Stefan
 
M

msalters

(e-mail address removed) schreef:
Hello,

I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5 kinds of
iterators on say a vector.

OR is it that any iterator declared on Vector is Random Iterator which
has the functionality of all the others.

Yes. In fact, with the exception of Input/Output Iterators, the
iterator categories are nested. A random iterator is also a member of
all other categorie (e.g. it is both an input and an output iterator)

Regards,
Michiel Salters
 

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,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top