自定义set的比较函数的示例代码
http://www.cplusplus.com/reference/set/set/insert/
3 #include <set>
4 using std::set;
5
- 6 struct Center{
| 7 Center(){}
| 8 Center(long x, long y):x_(x), y_(y){}
| 9 long x_;
| 10 long y_;
|- 11 bool operator==(const Center& c)const{
|| 12 if (x!=c.x) return false;
|| 13 if (y!=c.y) return false;
|| 14 return true;
|| 15 }
| 16 };
17
- 18 struct CenterCmp{
|- 19 inline bool operator()(const Center& s1, const Center& s2)const{
|| 20 if(s1.x_>s2.x_) return true;
|| 21 if(s1.x_<s2.x_) return false;
|| 22 if(s1.y_>x2.y_) return true;
|| 23 if(s1.y_<x2.y_) return false;
|| 24 return false;
|| 25 }
| 26 };
27
28 typedef set<Group, GroupComp> CenterSet;