Topic: -> and multimap
Author: Srinivas Vobilisetti <srinivas-v@usa.net>
Date: 1998/04/25 Raw View
Lo=EFc Tr=E9gan wrote:
>=20
> with the Rogue Wave STL, this code does not works :
>=20
> for( multimap<Entity*,Bid*>::iterator bid=3Dbids.begin(); bid !=3D
> bids.end(); bid++) {
> if( (bid->second->GetRessource() =3D=3D res)
> ...
> I must use :
>=20
> if( (*bid).second->GetRessource() =3D=3D res)
>=20
> why no multimap<Entity*,Bid*>::iterator::operator-> ??
>=20
> it a bit a surprising because this code works :
> for( vector<Entity>::iterator e=3Dentities.begin(); e !=3D entities.=
end();
> e++) {
> if( e->GetRessource() =3D=3D res)
It is most likely that the vector<T>::iterator is a typedef for 'T*' in
your Rogue Wave STL. You know, you can always apply operator -> on a
pointer type. But the multimap<T, S>::iterator may not be (most probably
not) a pointer type and Rogue Wave STL implementation of the type
multimap<T, S>::iterator may not provide operator ->. But I think any
X::iterator should support operator ->, where X is a Standard container
library class, because the standard says the return type of X::iterator
is a iterator type pointing to T. But I amy be worng too.
Srinivas
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Oleg Zabluda <zabluda@math.psu.edu>
Date: 1998/04/26 Raw View
Lo=EFc Tr=E9gan <loic.tregan@isdnet.net> wrote:
: with the Rogue Wave STL, this code does not works :
: for( multimap<Entity*,Bid*>::iterator bid=3Dbids.begin(); bid !=3D
: bids.end(); bid++) {
: if( (bid->second->GetRessource() =3D=3D res)
: ...
: I must use :
: if( (*bid).second->GetRessource() =3D=3D res)
: why no multimap<Entity*,Bid*>::iterator::operator-> ??
: it a bit a surprising because this code works :
: for( vector<Entity>::iterator e=3Dentities.begin(); e !=3D entities.=
end();
: e++) {
: if( e->GetRessource() =3D=3D res)
It looks to me that you might be confusing Entity and Bid here.
In the multimap example you are trying to modify Bid, while
in the vector example you are trying to modify Entity.
Oleg.
--=20
Life is a sexually transmitted, 100% lethal disease.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Loic.Tregan" <Loic.Tregan@cert.fr>
Date: 1998/04/28 Raw View
Oleg Zabluda wrote:
> It looks to me that you might be confusing Entity and Bid here.
> In the multimap example you are trying to modify Bid, while
> in the vector example you are trying to modify Entity.
sorry, Entity::GetRessource() already exists, not a very didactic
example !
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: phalpern@truffle.ma.ultranet.com (Pablo Halpern)
Date: 1998/04/28 Raw View
"Lo=EFc Tr=E9gan" <loic.tregan@isdnet.net> wrote:
>with the Rogue Wave STL, this code does not works :
>
> for( multimap<Entity*,Bid*>::iterator bid=3Dbids.begin(); bid !=3D
>bids.end(); bid++) {
> if( (bid->second->GetRessource() =3D=3D res)
> ...
>I must use :
>
> if( (*bid).second->GetRessource() =3D=3D res)
>
>why no multimap<Entity*,Bid*>::iterator::operator-> ??
Bug in the RW STL.
Possibly this is a deliberate omission to allow it to compile on
compilers that don't support on-demand member instantiation. On those
compilers, instantiating list<int> will always instantiate all of the
members of vector, including operator->. However, operator-> doesn't
make sense for ints because ints don't have members:
vector<int> vi;
vector<int>::iterator vii =3D vi.begin();
vii->foo; // ??? doesn't make sense
No that I think about it, though, the same logic doesn't apply to
multimap since the elements of multimap are always struct types
(pair<>). Back to the original answer: Bug in RW STL. The standard says
that iterators should have operator->() defined.
>
>it a bit a surprising because this code works :
> for( vector<Entity>::iterator e=3Dentities.begin(); e !=3D entities.e=
nd();
>e++) {
> if( e->GetRessource() =3D=3D res)
vector<T>::iterator is a typedef for T* in many implementations of the
STL. All of the pointer-like characteristics, including operator->, come
for free.
-------------------------------------------------------------
Pablo Halpern phalpern@truffle.ultranet.com
I am self-employed. Therefore, my opinions *do* represent=20
those of my employer.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Lo c Tr gan" <loic.tregan@isdnet.net>
Date: 1998/04/23 Raw View
with the Rogue Wave STL, this code does not works :
for( multimap<Entity*,Bid*>::iterator bid=bids.begin(); bid !=
bids.end(); bid++) {
if( (bid->second->GetRessource() == res)
...
I must use :
if( (*bid).second->GetRessource() == res)
why no multimap<Entity*,Bid*>::iterator::operator-> ??
it a bit a surprising because this code works :
for( vector<Entity>::iterator e=entities.begin(); e != entities.end();
e++) {
if( e->GetRessource() == res)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]