#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct ha {
int i;
explicit ha(int a) : i(a) {}
};
int main()
{
vector<ha> v{ ha{1}, ha{7}, ha{1} }; // initial vector
// GOAL : make a vector of pointers to elements with i < 2
vector<ha*> ph; // target vector
vector<ha*> pv; // temporary vector
// 1.
transform(v.begin(), v.end(), back_inserter(pv),
[](ha &arg) { return &arg; });
// 2.
copy_if(pv.begin(), pv.end(), back_inserter(ph),
[](ha *parg) { return parg->i < 2; }); // 2.
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBoYSB7IAoJaW50IGk7CiAgICBleHBsaWNpdCBoYShpbnQgYSkgOiBpKGEpIHt9Cn07CgppbnQgbWFpbigpIAp7CiAgICB2ZWN0b3I8aGE+IHZ7IGhhezF9LCBoYXs3fSwgaGF7MX0gfTsgLy8gaW5pdGlhbCB2ZWN0b3IKICAgIC8vIEdPQUwgOiBtYWtlIGEgdmVjdG9yIG9mIHBvaW50ZXJzIHRvIGVsZW1lbnRzIHdpdGggaSA8IDIKICAgIHZlY3RvcjxoYSo+IHBoOyAvLyB0YXJnZXQgdmVjdG9yCiAgICB2ZWN0b3I8aGEqPiBwdjsgLy8gdGVtcG9yYXJ5IHZlY3RvcgogICAgLy8gMS4gCiAgICB0cmFuc2Zvcm0odi5iZWdpbigpLCB2LmVuZCgpLCBiYWNrX2luc2VydGVyKHB2KSwgCiAgICAgICAgW10oaGEgJmFyZykgeyByZXR1cm4gJmFyZzsgfSk7IAogICAgLy8gMi4gCiAgICBjb3B5X2lmKHB2LmJlZ2luKCksIHB2LmVuZCgpLCBiYWNrX2luc2VydGVyKHBoKSwKICAgICAgICBbXShoYSAqcGFyZykgeyByZXR1cm4gcGFyZy0+aSA8IDI7ICB9KTsgLy8gMi4gCgogICAgcmV0dXJuIDA7Cn0KCg==