我有一个 std::multimap ,其中 key 是一个自定义类。像这样的东西:
Class X {
public:
std::string s;
int x;
operator <(const X& other) const { return s < other.s; }
};
std::multimap<X, int> mymap;
现在,我想使用 upper_bound 和 lower_bound 来遍历所有具有相同“s”值的元素。我是否需要为 X 实现一些其他运算符(例如:==)。或者它会像这样正常工作?
另外,我应该提供什么作为upper_bound和lower_bound的参数?我假设我应该创建一个所需值为“s”的虚拟对象?