This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Stl map problems, gcc 3.0, libstdc++ 3


I think that may have been the solution to that problem. Doing the same
thing without a positional insert seems to have solved the random
behavior of count and find. Maybe this was because the map
was empty when I was inserting, though this shouldn't make a difference.
I also am no longer using the key comparision object in the map
declaration (no more less<string>, I really didn't need it for this map
anyway). I'm not sure if just the removal of the positional insert or
the removal of using less did it (or both) , but it seems to work now. 


Mike Stultz

On 23 Jul 2001 18:02:22 -0400, michael.collison@mindspeed.com wrote:
> Michael Stultz <mikes@jumpline.com>
> Sent by: libstdc++-owner@gcc.gnu.org
> 07/23/01 12:17 PM
> 
>  
>         To:     libstdc++@gcc.gnu.org
>         cc: 
>         Subject:        Re: Stl map problems, gcc 3.0, libstdc++ 3
> 
> On 23 Jul 2001 08:55:55 -0700, Benjamin Kosnik wrote:
> > 
> > Can you please post an example, in C++, of the problems you are having?
> > 
> 
> 
> >Here is a rough example of how I am using the map:
> >typedef map<std::string, std::list<classObject>, std::less<std::string> > 
> testHash;
> >typedef testHash::value_type testHashVal
> >testHash hash;
> >...
> >...
> 
> >// The key in the real code I'm using come from another
> >list<string>::iterator.
> >void someFunc() {
> >   string key("TestKey");
> >   // Put in several objects, only 1 here
> >   list<classObject> holder;
> >   classObject listObj;
> >   holder.push_back(listObj);
> >   hash.insert(hash.begin(), testHashVal(key, holder));
> >}
>  
> I'm using maps with gcc-3.0 and have had no problems. I'm curious as to 
> why you are using 'hash.begin()' as a hint to insert the new value in the 
> map? Perhaps there is a problem with the 'insert' method that takes a hint 
> (this would be a bug of course). I would suggest trying the 'insert' 
> method that does not take a hint parameter to see if that works.
> 
> >void example(const char *name) {
> >   testHash::iterator p = hash.find(name);
> >   if(p == hash.end()) {
> >     // Didn't find the key
> >   }
> }
>  
> >void example2(const char *name) {
> >   int num = hash.count(name);
> >   if(num == 0) {
> >      // Can't find 
> >   }
> >}
>  
> 
> >Neither of the above fuctions for finding a key work consistantly for me
> >in gcc 3.0. They return 0 for count and hash.end() for find sometimes,
> >and then sometimes they find the key. This same code works fine (find
> >keys that exist every time using count or find) in gcc 2.95.x and under,
> >but not gcc 3.0. 
> 
> Michael Collison
> Manager - Software Tools Group
> Mindspeed Technologies
> 8 Technology Dr.
> Westboro, MA  01581
> 508-621-0697
> 508-621-0605 (f)
> michael.collison@mindspeed.com
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]