Topic: STL newcomer needs help!!!
Author: "Yuri de Wit" <ydwit@worldnet.att.net>
Date: 1998/04/18 Raw View
Hi,
And what about the member funtion:
pair<iterator, iterator> equal_range(const Key& key);
Don't this do the same as upper_bound and lower_bound, but in one shot???
Yuri
laytong@gaatlanta1.btna.com wrote in message
<6h5m5v$2m1$1@nnrp1.dejanews.com>...
>You can try the lower_bound() and upper_bound() algorithms.. They should
>give you the iterator range for the vectors that match a key... Then
looping
>through those iterators should give you the vectors you need.
>
>> I am using MSVC++ 4.0 and trying to implement a multimap of vectors with
>> integer key. I have gotten as far as the declaration:
>>
>> multimap<key_t, vector<component_t>, less<key_t> > vector_map;
>>
>> This at least compiles without error, but I have yet to find an
>> effective method for looking at all vectors associated with a given
>> key.
[ 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: "Yuri de Wit" <ydwit@worldnet.att.net>
Date: 1998/04/19 Raw View
Hi Steve,
I am also a newcomer to STL, but I think I have already got the same problem
as you with multimaps.
What I found out was that the multimap class has a member function called:
pair<iterator, iterator> equal_range(const Key& key);
This member function returns a pair containing a iterator to the first
element that has key as the key and a iterator to the last one. So you can
use a while or a for to iterator through all vectors that has the same key.
I don't believe you have to erase and insert again just to update a value. I
have never tried, but there must be some way to get a reference to the
object and then just update it (I think it is more simple than we expect).
I will try to do it and if I have any news I will tell you.
Yuri
Steve Clamage wrote in message <3535871e.0@news1.ibm.net>...
>I have tried posting this message several times and have gotten no
>response. I am guessing the newsfeed at my other location is not up to
>snuff.
>I would greatly appreciate any response - be it pointing to a helpful site,
>commiseration, or a golden egg ( the solution )
>
>I am using MSVC++ 4.0 and trying to implement a multimap of vectors with
>integer key. I have gotten as far as the declaration:
>
>multimap<key_t, vector<component_t>, less<key_t> > vector_map;
>
>This at least compiles without error, but I have yet to find an
>effective method for looking at all vectors associated with a given
>key. I will also be changing key values - I will probably just have to
>erase the value from the multimap then re-insert it with the correct
>key.
>
>I am getting very frustrated with this, but at this point I am stubborn
>enough to fight with this late into the night every night (like I have
>the last week or so) until I figure the darn thing out. I have just
>ordered a book that focuses on the STL - I just hope it doesn't make
>little more than an honorable mention of the map and multimap templates
>like Ladd and Stroustrup do.
>By the way, the book I just ordered is "Using the Stl : The C++ Standard
>Template Library" by Robert Robson. I wanted the new Plauger, et al.
>book, but it won't be released until June. Has anyone read Robson?
>What did you think?
>Any and all information in this area will be greatly appreciated!!!
>TIA
>
>
>
>[ 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 ]
>
---
[ 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: clamage@taumet.eng.sun.com (Steve Clamage)
Date: 1998/04/16 Raw View
I have tried posting this message several times and have gotten no
response. I am guessing the newsfeed at my other location is not up to
snuff.
I would greatly appreciate any response - be it pointing to a helpful site,
commiseration, or a golden egg ( the solution )
I am using MSVC++ 4.0 and trying to implement a multimap of vectors with
integer key. I have gotten as far as the declaration:
multimap<key_t, vector<component_t>, less<key_t> > vector_map;
This at least compiles without error, but I have yet to find an
effective method for looking at all vectors associated with a given
key. I will also be changing key values - I will probably just have to
erase the value from the multimap then re-insert it with the correct
key.
I am getting very frustrated with this, but at this point I am stubborn
enough to fight with this late into the night every night (like I have
the last week or so) until I figure the darn thing out. I have just
ordered a book that focuses on the STL - I just hope it doesn't make
little more than an honorable mention of the map and multimap templates
like Ladd and Stroustrup do.
By the way, the book I just ordered is "Using the Stl : The C++ Standard
Template Library" by Robert Robson. I wanted the new Plauger, et al.
book, but it won't be released until June. Has anyone read Robson?
What did you think?
Any and all information in this area will be greatly appreciated!!!
TIA
[ 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: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1998/04/16 Raw View
The article below was approved by me as moderator, but due to some
sort of glitch, the actual author's name and email address got
lost. I didn't realize the problem until it showed up in the
newsgroup attributed to me. I apologize for the confusion this
has caused.
---
Steve Clamage, stephen.clamage@sun.com
In article 0@news1.ibm.net, clamage@taumet.eng.sun.com (Steve Clamage) writes:
>I have tried posting this message several times and have gotten no
>response. I am guessing the newsfeed at my other location is not up to
>snuff.
>I would greatly appreciate any response - be it pointing to a helpful site,
>commiseration, or a golden egg ( the solution )
>
>I am using MSVC++ 4.0 and trying to implement a multimap of vectors with
>integer key. I have gotten as far as the declaration:
>
>multimap<key_t, vector<component_t>, less<key_t> > vector_map;
>
>This at least compiles without error, but I have yet to find an
>effective method for looking at all vectors associated with a given
>key. I will also be changing key values - I will probably just have to
>erase the value from the multimap then re-insert it with the correct
>key.
>
>I am getting very frustrated with this, but at this point I am stubborn
>enough to fight with this late into the night every night (like I have
>the last week or so) until I figure the darn thing out. I have just
>ordered a book that focuses on the STL - I just hope it doesn't make
>little more than an honorable mention of the map and multimap templates
>like Ladd and Stroustrup do.
>By the way, the book I just ordered is "Using the Stl : The C++ Standard
>Template Library" by Robert Robson. I wanted the new Plauger, et al.
>book, but it won't be released until June. Has anyone read Robson?
>What did you think?
>Any and all information in this area will be greatly appreciated!!!
>TIA
[ 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: laytong@gaatlanta1.btna.com
Date: 1998/04/16 Raw View
You can try the lower_bound() and upper_bound() algorithms.. They should
give you the iterator range for the vectors that match a key... Then looping
through those iterators should give you the vectors you need.
> I am using MSVC++ 4.0 and trying to implement a multimap of vectors with
> integer key. I have gotten as far as the declaration:
>
> multimap<key_t, vector<component_t>, less<key_t> > vector_map;
>
> This at least compiles without error, but I have yet to find an
> effective method for looking at all vectors associated with a given
> key.
...
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
---
[ 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: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/04/16 Raw View
Steve Clamage writes:
[ I'm pretty sure it wasn't Steve who wrote this, but that's what the
From: header says... Is this a bug in the moderation software? -oliva ]
> multimap<key_t, vector<component_t>, less<key_t> > vector_map;
> This at least compiles without error, but I have yet to find an
> effective method for looking at all vectors associated with a given
> key.
Use the equal_range(const key_type&) member function. It returns a
pair P of iterators so that [P.first, P.second) is the interval from
the first occurrence of the given key to one past the last occurrence
of it.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
[ 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/17 Raw View
laytong@gaatlanta1.btna.com wrote:
>You can try the lower_bound() and upper_bound() algorithms.. They should
>give you the iterator range for the vectors that match a key... Then looping
>through those iterators should give you the vectors you need.
>
No. The lower_bound() and upper_bound() ALGORITHMS are inefficient when
used with associative containers because they do not have random-access
iterators. You would effectively be defeating the benefit of the sorted
container types. Instead, you should use the lower_bound() and
upper_bound() MEMBER FUNCTIONS, as follows:
>> I am using MSVC++ 4.0 and trying to implement a multimap of vectors with
>> integer key. I have gotten as far as the declaration:
>>
>> multimap<key_t, vector<component_t>, less<key_t> > vector_map;
>>
>> This at least compiles without error, but I have yet to find an
>> effective method for looking at all vectors associated with a given
>> key.
// Iterate through all of the vectors in vector_map that have key, k:
typedef multimap<key_t,vector<component_t>, less<key_t> > vector_map_t;
vector_map_t vector_map;
vector_map_t::iterator iter = vector_map.lower_bound(k);
vector_map_t::iterator finish = vector_map.upper_bound(k);
for ( ; iter != finish; ++iter)
// Do something with iter->second; (which is a vector<component_t>)
-------------------------------------------------------------
Pablo Halpern phalpern@truffle.ultranet.com
I am self-employed. Therefore, my opinions *do* represent
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 ]