【发布时间】:2015-04-06 21:57:55
【问题描述】:
如何使用 STL 二进制搜索操作和对? 我也希望使用 lower_bound 函数。有可能吗?
【问题讨论】:
标签: c++ stl binary-search stl-algorithm
如何使用 STL 二进制搜索操作和对? 我也希望使用 lower_bound 函数。有可能吗?
【问题讨论】:
标签: c++ stl binary-search stl-algorithm
std::pair 重载了operator<,因此任何使用排序的算法都适用于pair(假设您已经为pair 成员重载了operator<)。如果first 部分相等,则首先按first 成员排序,然后按second。不接受谓词作为参数的lower_bound 函数使用operator< 进行比较,因此它也适用于对。
【讨论】: