简体   繁体   English

C ++中set的lower_bound中的关键参数

[英]A key parameter in lower_bound of a set in c++

How do I apply lower_bound to a set with a comparison function of my own creation in c++? 如何在C ++中将lower_bound应用于具有我自己创建的比较功能的集合? For example, I've written a comparison function that checks if a number is big enough, and then I need to perform a binary search on a set using a lower_bound in composition with the function I've written. 例如,我编写了一个比较函数,用于检查数字是否足够大,然后需要使用我编写的函数使用lower_bound组成对集合执行二进制搜索。

I don't actually think, that i figured out what you trying to do. 我实际上不认为我知道您要做什么。 I guess you want to use binary search in set limited with lower bound. 我猜您想在下限限制的集合中使用二进制搜索。 If it's correct here is method: 如果正确,这里是方法:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM