operator * of iterator

G

George2

Hello everyone,


Operator * on iterator of type T will result in reference to type T
(T&), right (i.e. not type T itself or some other types)?

I am looking for some STL implementation code for this (operator * on
iterator of type T will result in reference to type T (T&)), but can
not find (maybe I search method is not correct). Could anyone post
some internal implementation code please?


thanks in advance,
George
 
V

Victor Bazarov

George2 said:
Operator * on iterator of type T will result in reference to type T
(T&), right (i.e. not type T itself or some other types)?

I am looking for some STL implementation code for this (operator * on
iterator of type T will result in reference to type T (T&)), but can
not find (maybe I search method is not correct). Could anyone post
some internal implementation code please?

Iterators are closely tied to the container for which they were made,
and the implementation can differ greatly depending on the container.

What problem are you trying to solve?

V
 
A

Abhishek Padmanabh

Hello everyone,

Operator * on iterator of type T will result in reference to type T
(T&), right (i.e. not type T itself or some other types)?

I am looking for some STL implementation code for this (operator * on
iterator of type T will result in reference to type T (T&)), but can
not find (maybe I search method is not correct). Could anyone post
some internal implementation code please?

You can look into the standard header <vector> to see a sample
iterator class. It should be available with your STL implementation of
the compiler.
 
P

Pete Becker

Iterators are closely tied to the container for which they were made,
and the implementation can differ greatly depending on the container.

Iterators provide access to the elements of a sequence. Containers are
one way of creating sequences, but not the only way. Unfortunately,
people tend to learn containers first, and give them undue importance,
ending up confused about how the STL works.
 
J

James Kanze

Iterators are closely tied to the container for which they were made,
and the implementation can differ greatly depending on the container.
[/QUOTE]
Iterators provide access to the elements of a sequence. Containers are
one way of creating sequences, but not the only way. Unfortunately,
people tend to learn containers first, and give them undue importance,
ending up confused about how the STL works.

Maybe. But for anything more than an input or an output
iterator, operator*() must return a real reference; in addition,
"If a and b are both dereferenceable, then a == b if and only if
*a and *b are the same object." Meeting this requirement more
or less requires some sort of backing collection. The result is
that just about any interesting use without a backing collection
(and many with it, if you aren't returning exactly the element
of the collection) can only be an input iterator, which in turn
means that many of the algorithms won't work with them.
 
P

Pete Becker

Maybe. But for anything more than an input or an output
iterator, operator*() must return a real reference; in addition,
"If a and b are both dereferenceable, then a == b if and only if
*a and *b are the same object." Meeting this requirement more
or less requires some sort of backing collection. The result is
that just about any interesting use without a backing collection
(and many with it, if you aren't returning exactly the element
of the collection) can only be an input iterator, which in turn
means that many of the algorithms won't work with them.

Yes, certainly: if we ignore the parts that don't fit our model, then
everything fits our model. Nevertheless, conceptually, containers are
one of the least important parts of STL. Sequences are fundamental.
Iterators give you access to the elements of a sequence. Containers are
one way of creating sequences, but they are not the only way. Analyzing
iterators in terms of "the container for which they were made" is like
analyzing internal combustion engines in terms of "the automobiles that
contain them," ignoring the many other places where internal combustion
engines are used and the varying requirements imposed by those uses.
 

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,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top