यहां हम देखेंगे कि C++ STL में upper_bound() फ़ंक्शन क्या है। यह फ़ंक्शन एक इटरेटर लौटाता है जो कंटेनर में पहले तत्व की ओर इंगित करता है, जिसे val के बाद माना जाता है। सिंटैक्स इस प्रकार है:
iterator upper_bound (const value_type& val); const_iterator upper_bound (const value_type& val) const;
रिटर्न मान एक इटरेटर है, जो कंटेनर में पहले तत्व की ओर इंगित करता है जिसे val के बाद माना जाता है।
उदाहरण
#include <iostream>
#include <set>
using namespace std;
int main() {
set<int> myset;
set<int>::iterator itlow, itup;
for (int i = 1; i < 10; i++) myset.insert(i * 10);
itup = myset.upper_bound(60);
myset.erase(itup);
cout << "myset contains:";
for (set<int>::iterator it = myset.begin(); it != myset.end(); ++it)
cout << ' ' << *it;
}
आउटपुट
myset contains: 10 20 30 40 50 60 80 90