1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
#include <set>
struct pos {
int x,y;
};
bool operator< ( pos a, pos b ) {
if( a.x == b.x ) return a.y < b.y ;
else return a.x < b.x;
}
int main() {
std::set<pos> s = { {2,6}, {5,2}, {3,4}, {6,1}, {5,0}, {4,9} } ;
// auto iter = s.lower_bound(4) ;
auto iter = s.lower_bound( pos{5,0} ); // value_type of the set is pos
std::cout << iter->x << ' ' << iter->y << '\n' ; // 5 0
iter = s.upper_bound( pos{5,0} );
std::cout << iter->x << ' ' << iter->y << '\n' ; // 5 2
}
|