#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
struct Obj { static int i; int id; Obj() { id = ++i; } };
int main() {
Obj a, b, c, d, e, f, g, h, i, j;
std::vector<Obj> v { a,b,c,d,e,f,g,h,i,j},
u {a,e,i},
r;
auto it = std::set_intersection(
v.begin(), v.end(), u.begin(), u.end(), std::back_inserter(r),
[](const Obj x, const Obj y){ return x.id < y.id; }
);
for(const auto c : r)
std::cout << c.id << ' ';
}
int Obj::i = 0;
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8aXRlcmF0b3I+CgpzdHJ1Y3QgT2JqIHsgc3RhdGljIGludCBpOyBpbnQgaWQ7IE9iaigpIHsgaWQgPSArK2k7IH0gfTsKCmludCBtYWluKCkgewoJT2JqIGEsIGIsIGMsIGQsIGUsIGYsIGcsIGgsIGksIGo7CglzdGQ6OnZlY3RvcjxPYmo+IHYgeyBhLGIsYyxkLGUsZixnLGgsaSxqfSwKCQkJCQkgIHUge2EsZSxpfSwKCQkJCQkgIHI7CglhdXRvIGl0ID0gc3RkOjpzZXRfaW50ZXJzZWN0aW9uKAoJCXYuYmVnaW4oKSwgdi5lbmQoKSwgdS5iZWdpbigpLCB1LmVuZCgpLCBzdGQ6OmJhY2tfaW5zZXJ0ZXIociksIAoJCVtdKGNvbnN0IE9iaiB4LCBjb25zdCBPYmogeSl7IHJldHVybiB4LmlkIDwgeS5pZDsgfQoJKTsJCgkKCWZvcihjb25zdCBhdXRvIGMgOiByKQoJCXN0ZDo6Y291dCA8PCBjLmlkIDw8ICcgJzsKfQppbnQgT2JqOjppID0gMDs=