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 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
struct point : std::pair<int,int>
{
using base = std::pair<int,int> ;
using base::base ; // needs compiler support for inherited constructors
int& x() { return base::first ; }
const int& x() const { return base::first ; }
int& y() { return base::second ; }
const int& y() const { return base::second ; }
};
int main()
{
const auto print = [] ( const std::vector<point>& seq )
{
for( const auto& pt : seq ) std::cout << '(' << pt.x() << ',' << pt.y() << ") " ;
std::cout << '\n' ;
};
std::vector<point> seq { {1,2}, {3,4}, {1,2}, {5,6}, {3,4}, {1,2}, {3,4} };
print(seq) ;
std::sort( seq.begin(), seq.end() ) ;
seq.erase( std::unique( seq.begin(), seq.end() ), seq.end() ) ;
print(seq) ;
}
|