Connecting Tech Pros Worldwide Forums | Help | Site Map

Iterators on Vector

codefixer@gmail.com
Guest
 
Posts: n/a
#1: Aug 23 '05
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.


Thomas Tutone
Guest
 
Posts: n/a
#2: Aug 23 '05

re: Iterators on Vector


codefixer at gmail.com wrote:
[color=blue]
> 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.[/color]

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

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

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.
[color=blue]
> What is the best reference to understand which(iterator) can be
> declared on which(container) and how ?[/color]

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

Stefan Näwe
Guest
 
Posts: n/a
#3: Aug 24 '05

re: Iterators on Vector


codefixer@gmail.com wrote:[color=blue]
> 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 ?
>[/color]

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
msalters
Guest
 
Posts: n/a
#4: Aug 24 '05

re: Iterators on Vector



codefixer@gmail.com schreef:
[color=blue]
> 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.[/color]

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

Closed Thread