struct C_S
{
int m_a;
std::string m_s;
C_S(const std::string &s,int i):m_a(i),m_s(s)
{
//
}
//重载operator<,支持
//std::map<C_S,int>这类默认定义,实际
//是std::map<C_S,int,std::less<C_S> >;
bool operator<(const C_S &c_s) const
{
return c_s.m_a > this->m_a;
}
//重载operator>,支持
//std::map<C_S,int,std::greater<C_S> >
//指定map按key 从大到小排序
bool operator>(const C_S &c_s) const
{
return c_s.m_a < this->m_a;
}
//bool operator!(const C_S &c_s) const
//{
//return c_s.m_a == this->m_a && c_s.m_s == this->m_s;
//}
};
void map_test()
{
//MAP 元素按从大大小的顺序排列
std::map<C_S,int> less_map;
less_map[C_S("AAA",3)] = 3;