Connecting Tech Pros Worldwide Forums | Help | Site Map

operator * of iterator

George2
Guest
 
Posts: n/a
#1: Dec 3 '07
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

Victor Bazarov
Guest
 
Posts: n/a
#2: Dec 3 '07

re: operator * of iterator


George2 wrote:
Quote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Abhishek Padmanabh
Guest
 
Posts: n/a
#3: Dec 3 '07

re: operator * of iterator


On Dec 3, 9:07 pm, George2 <george4acade...@yahoo.comwrote:
Quote:
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 <vectorto see a sample
iterator class. It should be available with your STL implementation of
the compiler.
Pete Becker
Guest
 
Posts: n/a
#4: Dec 3 '07

re: operator * of iterator


On 2007-12-03 11:24:16 -0500, "Victor Bazarov" <v.Abazarov@comAcast.netsaid:
Quote:
George2 wrote:
Quote:
>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.
>
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.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

James Kanze
Guest
 
Posts: n/a
#5: Dec 4 '07

re: operator * of iterator


On Dec 3, 5:35 pm, Pete Becker <p...@versatilecoding.comwrote:
Quote:
On 2007-12-03 11:24:16 -0500, "Victor Bazarov" <v.Abaza...@comAcast.netsaid:
Quote:
Quote:
George2 wrote:
Quote:
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)?
Quote:
Quote:
Quote:
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?
Quote:
Quote:
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.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Pete Becker
Guest
 
Posts: n/a
#6: Dec 4 '07

re: operator * of iterator


On 2007-12-04 04:33:16 -0500, James Kanze <james.kanze@gmail.comsaid:
Quote:
On Dec 3, 5:35 pm, Pete Becker <p...@versatilecoding.comwrote:
Quote:
>On 2007-12-03 11:24:16 -0500, "Victor Bazarov" <v.Abaza...@comAcast.nets
aid:
>
Quote:
Quote:
>>George2 wrote:
>>>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)?
>
Quote:
Quote:
>>>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?
>
Quote:
Quote:
>>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.
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.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Closed Thread