Type of key value for map
-Can be a custom type (object, function pointer, smart pointer 、。。。 )
-but there are side effects-a variety of problems arise when you define a type key value that cannot be sorted by the system's own < or >.
-so you need to define your own comparator for processing
Solve:
-If the key value is an object type
-You can overload the < or > operator yourself in a class
-You do not need to overload the = =
-Because the ordering of the elements is based on <, and the > is compared
eg
-a > B is b <= A;
-This is a bit of a question. I want to add ....
classkey{ Public: Key (intival): _ival (ival) {}int_ival;};BOOL operator< (Constkey& left,Constkey&Right ) { //return Left._ival < Right._ival; return false; //if always return False, Amap.size () is always 1. Any data coming in is/a >= b && b >= a so it's always equal.}
-When we are unable to modify the class, we can process the comparison function in the class for external use
-This is a bit of a question. I want to add ....
eg
bool Compare (constconst sale_item& RHS) { return Lhs.book < bool (*COMP) (constconst sale_item&
Reference:
-http://www.zhihu.com/question/34290683?sort=created
-http://blog.csdn.net/ultrahook/article/details/8146529
-http://bbs.csdn.net/topics/360183804
STL Template _MULTIMAP_ Smart pointer as key value