我想知道查找以一对整数(坐标)作为键的 map 是否具有lower_bound 和upper_bound 的任何可用含义?
using Point = std::pair<int, int>;
std::map<Point, Vertex> vertex_map = {};
const auto p = std::make_pair(0, 0);
const auto q = std::make_pair(10, 10);
auto foo = vertex_map.lower_bound(p);
auto bar = vertex_map.upper_bound(q);
特别是,我想检查 map 是否包含由给定矩形(p,q)绑定(bind)的任何顶点。
最佳答案
不,我不认为这是可能的。您需要一个 comparator这样p < x && x < p
如果x
受 Rectangle (p, q)
约束这个比较器必须定义一个 strict weak ordering
据我所知,这是不可能的。
以一种有效的方式解决这个问题的方法是保存两个列表:一个包含由 x
排序的点。组件和另一个具有 y
排序的点零件。
关于c++ - 搜索具有下限和上限的 map <pair<int, int>, ...>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64640365/