我需要存储设备列表.每个设备都有唯一的mac地址.我想用stl map存储它,mac地址作为键.
我定义了struct:
struct MacBytes
{
char byte1;
char byte2;
char byte3;
char byte4;
char byte5;
char byte6;
bool operator <(const MacBytes& rhs) const
{
//add implamention here
}
}
Run Code Online (Sandbox Code Playgroud)
任何建议实现'operator <'函数(stl映射必需),而不使用很多if语句.或者可以建议另一个代表.
使用,而不是具有一堆单个char字段的结构std::array<char, 6>.这是一种表示数据的简单方法,并且std::array已经有了一个,operator<因此您不需要编写自己的数据.