How do I apply lower_bound to a set with a comparison function of my own creation in c++? 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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.