fork(2) download
  1. #include <set>
  2. #include <iostream>
  3.  
  4. struct Base
  5. {
  6. Base(int xx, int yy) : x(xx), y(yy){}
  7. bool operator<(const Base&) const {return true;}
  8.  
  9. int x;
  10. int y;
  11. };
  12.  
  13. struct D1 : Base
  14. {
  15. D1(int x, int y) : Base(x, y){}
  16. };
  17.  
  18. struct D2 : Base
  19. {
  20. D2(int x = 0, int y = 0) : Base(x, y){}
  21. };
  22.  
  23. void test()
  24. {
  25. std::set<D1> s1;
  26. std::set<D2> s2;
  27.  
  28. s1.insert({1, 2});
  29. s2.insert({1, 2});
  30.  
  31. std::cout<<"s1 size:"<<s1.size()<<std::endl<<"Content:"<<std::endl;
  32. for(auto& v : s1)
  33. {
  34. std::cout<<v.x<<" "<<v.y<<std::endl;
  35. }
  36.  
  37. std::cout<<std::endl<<"s2 size:"<<s2.size()<<std::endl<<"Content:"<<std::endl;
  38. for(auto& v : s2)
  39. {
  40. std::cout<<v.x<<" "<<v.y<<std::endl;
  41. }
  42. }
  43.  
  44. int main()
  45. {
  46. test();
  47. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
s1 size:1
Content:
1 2

s2 size:2
Content:
2 0
1 0