#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
struct A
{
A(std::initializer_list<int> il) : _values(il) {}
std::vector<int>& get_values() { return _values; }
private:
std::vector<int> _values;
};
struct B
{
B(A* a) : _a(a) {}
void apply_filter(std::function<bool(int)> filter)
{
std::vector<int>& v = _a->get_values();
v.erase(std::remove_if(v.begin(), v.end(), filter), v.end());
}
private:
A* _a;
};
void print(const std::vector<int>& v)
{
std::cout << "{ ";
for (auto e : v)
std::cout << e << ' ';
std::cout << "}\n";
}
int main()
{
A a({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
print(a.get_values());
B b(&a);
b.apply_filter([](int val) { return val % 2 == 0; });
print(a.get_values());
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KCnN0cnVjdCBBCnsKICAgIEEoc3RkOjppbml0aWFsaXplcl9saXN0PGludD4gaWwpIDogX3ZhbHVlcyhpbCkge30KCiAgICBzdGQ6OnZlY3RvcjxpbnQ+JiBnZXRfdmFsdWVzKCkgeyByZXR1cm4gX3ZhbHVlczsgfQoKcHJpdmF0ZToKICAgIHN0ZDo6dmVjdG9yPGludD4gX3ZhbHVlczsKfTsKCnN0cnVjdCBCCnsKICAgIEIoQSogYSkgOiBfYShhKSB7fQoKICAgIHZvaWQgYXBwbHlfZmlsdGVyKHN0ZDo6ZnVuY3Rpb248Ym9vbChpbnQpPiBmaWx0ZXIpCiAgICB7CiAgICAgICAgc3RkOjp2ZWN0b3I8aW50PiYgdiA9IF9hLT5nZXRfdmFsdWVzKCk7CgogICAgICAgIHYuZXJhc2Uoc3RkOjpyZW1vdmVfaWYodi5iZWdpbigpLCB2LmVuZCgpLCBmaWx0ZXIpLCB2LmVuZCgpKTsKICAgIH0KCnByaXZhdGU6CiAgICBBKiBfYTsKfTsKCnZvaWQgcHJpbnQoY29uc3Qgc3RkOjp2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