Advertisement
rizky_herucakra

using unique on vector

Jul 3rd, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  uniquevector
  4. //
  5. //  Created by Rizky Herucakra on 7/4/13.
  6. //  Copyright (c) 2013 Rizky Herucakra. All rights reserved.
  7. //
  8.  
  9. #include <vector>
  10. #include <algorithm>
  11. #include <iostream>
  12.  
  13. using namespace std;
  14.  
  15. struct Point
  16. {
  17.     int x ;
  18.     int y;
  19. };
  20.  
  21. bool point_eq(const Point& a, const Point& b){
  22.     return (a.x == b.x) && (a.y == b.y);
  23. }
  24.  
  25.  
  26.  
  27. int main()
  28. {
  29.     vector< Point> myPoints = {{2,4},{2,4},{5,4},{0,1}};
  30.     myPoints.erase( unique(myPoints.begin(),myPoints.end(),  point_eq) );
  31.    
  32.     for (auto& t : myPoints){
  33.    
  34.         cout << "{ " << t.x << " , " << t.y << " }" << endl;
  35.     }
  36.    
  37.    
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement