"Tom" <Th************@epost.de> wrote in message
news:bq**********@news.mch.sbs.de...
| I am using a std::map that is sorted in a very special way.
| Therefore I am using my own sort function. That works fine.
| But this is only half the problem. Additionally "map.find()" should
| use a different comparison function.
|
| My map is like:
| map < myString, Whatever>
| As far as I know "find" uses operators from the key (myString).
| Therefore I wrote my own operator== ,operator< and operator>
| Nothing worked. Does anybody know which comparison
| function uses "find" or know any other solution while
| using std functionality ?
map.find() uses the comparison function that is used for sorting
( an item that comes neither before nor after is considered equal).
This allows the search to be performed in O(logN) time using
the map's tree structure.
If you want to use another equality criterion, you can use
the std::find function:
std::find( map.begin(), map.end(), MyPredicate(someKey) );
Note that this search will take linear O(N) time.
The predicate object is very much like a sort function:
its operator() shall take a MyMap::value_type& as a reference,
and return true if the item matches your search criterion.
hth -Ivan
--
http://ivan.vecerina.com