Boost contains dozens of libraries with widely varying purposes.
The first place to look for containers in C++ is the STL library, which is part of standard C++. They are nothing like Java containers AFAIK, which is great, because C++ is nothing like Java.
Last edited by D_Drmmr; January 30th, 2012 at 09:08 AM.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
C++ also has std::deque, which looks similar to std::vector but is different internally, and some adapters std::stack, std::queue, and std:riority_queue which are not containers but can be used to modify the interface of standard containers if desired.
Boost has some additional containers.
Last edited by Lindley; January 30th, 2012 at 10:09 AM.
Yes and no. Yes, in the sense that the typically expected usage of a std::map would be identical to that of a SortedMap. No, because the details of their interfaces are different, and in fact std::map is a concrete class template whereas SortedMap is an interface construct.
Originally Posted by lucky6969b
what is the equivalence for stdext::hash_map in Java?
If the name is any clue, then stdext::hash_map's rough equivalent in Java is obviously HashMap.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
In other words, do I need to write extra code to keep it sorted?
Thanks
Jack
You need to provide the key class with an operator<, OR you need to explicitly provide a comparison function defining a strict weak ordering when the map is constructed.
This sort of approach (either explicitly provide a comparator, or use the type's natural operators by default) is used throughout the STL.
If the key is a primitive such as an int, and the natural notion of ordering is sufficient, then there is no need to do anything special to keep the container sorted.
One thing to watch out for: If you are using a string as the key, it must be a std::string or other string class defining operator< lexicographically. C-style strings, which are essentially just char arrays, will *not* provide the expected behavior when used as map keys (only the pointer values will be compared).
Since you presumably do not want to use the default "less than" comparison for std::string as provided by the overloaded operator<, how you do want to compare the strings? That is central to implementing this "less than" comparison function.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
I'd like to have it in the ascending order.
BTW how do we get the first item out of an ordered std::set?
I tried m_Set[0] and we can't use begin() since it returns an iterator
Thanks a lot
Jack
Last edited by lucky6969b; January 30th, 2012 at 11:59 PM.
Bookmarks