c ++中集合的lower_bound中的关键参数

时间:2018-01-11 21:16:31

标签: c++ set

如何将lower_bound应用于具有我自己在c ++中创建的比较函数的集合? 例如,我编写了一个比较函数,用于检查数字是否足够大,然后我需要使用带有我编写的函数的组合中的lower_bound对集合执行二进制搜索。

1 个答案:

答案 0 :(得分:0)

我实际上并没有想到,我想出了你想要做的事情。 我想你想在set bound with lower bound中使用二进制搜索。如果它在这里是正确的方法:

template <typename T>
bool searchValueInSetWithLowerBound(const std::set<T> &mySet, const T& lowerBound, const T& value) {
    return std::binary_search(std::lower_bound(mySet.begin(), mySet.end(), lowerBound), mySet.end(), value);