fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iterator>
  5.  
  6. struct Obj { static int i; int id; Obj() { id = ++i; } };
  7.  
  8. int main() {
  9. Obj a, b, c, d, e, f, g, h, i, j;
  10. std::vector<Obj> v { a,b,c,d,e,f,g,h,i,j},
  11. u {a,e,i},
  12. r;
  13. auto it = std::set_intersection(
  14. v.begin(), v.end(), u.begin(), u.end(), std::back_inserter(r),
  15. [](const Obj x, const Obj y){ return x.id < y.id; }
  16. );
  17.  
  18. for(const auto c : r)
  19. std::cout << c.id << ' ';
  20. }
  21. int Obj::i = 0;
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
1 5 9