Advertisement
Guest User

Fun with lower_bound

a guest
Sep 17th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. struct Marker {
  6.     char type;
  7.     int start;
  8.     int end;
  9.    
  10.     Marker(char t, int s, int e) : type(t), start(s), end(e) {}
  11. };
  12.  
  13. static bool doesNotOverlap(const Marker& lhv, const Marker& rhv) {
  14.     return lhv.end < rhv.start;
  15. }
  16.  
  17.  
  18. int main (int argc, const char * argv[]) {
  19.    
  20.     std::vector<Marker> markers;
  21.     markers.push_back(Marker('X', 2, 8));
  22.     markers.push_back(Marker('O', 3, 4));
  23.     markers.push_back(Marker('X', 12, 20));
  24.    
  25.     Marker newMarker('X', 7, 9);
  26.    
  27.     std::vector<Marker>::const_iterator iter =
  28.         std::lower_bound(markers.begin(), markers.end(), newMarker, doesNotOverlap);
  29.    
  30.     printf("Found the thing %d!\n", int(iter-markers.begin()));
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement