fork download
  1. #include <iostream>
  2. #include <unordered_set>
  3.  
  4. struct B
  5. {
  6. int x, y;
  7. };
  8.  
  9. class A
  10. {
  11. struct hash
  12. {
  13. std::size_t operator()( int const a ) const
  14. {
  15. return std::hash<int>()( a );
  16. }
  17. };
  18.  
  19. struct equal_to
  20. {
  21. std::size_t operator()( int const a, int const b ) const
  22. {
  23. return std::equal_to<int>()( a, b );
  24. }
  25. };
  26.  
  27. public:
  28. std::unordered_set< int, hash, equal_to > set;
  29. void push( const B& b )
  30. {
  31. set.insert( b.x );
  32. }
  33. };
  34. int main(int argc, char**)
  35. {
  36. A a;
  37. a.push({4, 7});
  38. a.push({15, 7});
  39. a.push({15, 7});
  40. a.push({101, 10});
  41.  
  42. for (auto i: a.set) std::cout << i << "\n";
  43. }
  44.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
101
15
4