Re: Is a std::map<> ordered?
On 2008-11-21 08:46:16 -0500, Juha Nieminen <nospam@thanks.invalid> said:
acehreli@gmail.com wrote:
std::map<int, int> myMap(myPredicate);
I don't think you can do that because the comparator template
parameter is set by default to std::less, and unless myPredicate casts
implicitly to type std::less, that won't work. You have to do it like:
std::map<int, int, MyPredicateType> myMap(myPredicate);
If 'myPredicate' is a function, the syntax becomes awkward:
std::map<int, int, bool(*)(int, int)> myMap(myPredicate);
Well, yes, and as we've seen in many Ginsu knife commercials, a normal
knife can't slice a tomato. The way to write this code is, of course,
with appropriate typedefs:
typedef bool (*pred)(int,int);
std::map<int, int, pred> myMap(myPredicate);
This becomes even more awkward if the key and data types of the map
are something more complicated than int.
Not at all. Again, typedefs.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)