fork download
  1. #include <iostream>
  2. #include <set>
  3.  
  4. struct A {
  5. int i = 0;
  6. bool operator()(int a, int b)
  7. {
  8. ++i;
  9. return a < b;
  10. }
  11. };
  12.  
  13. int main()
  14. {
  15. A a;
  16.  
  17. std::set<int, A> s(a);
  18.  
  19. for (int j = 0; j < 10; ++j) {
  20. int const prev = s.key_comp().i;
  21. s.insert(j);
  22. std::cout << j << ": " << (s.key_comp().i - prev) << "\n";
  23. }
  24. }
  25.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0: 0
1: 3
2: 4
3: 4
4: 5
5: 5
6: 6
7: 6
8: 6
9: 6