#include <iostream>
#include <vector>
class INT {
int i;
public:
INT(int ii) : i{ ii } {}
operator int() { return i; }
INT& operator++() { ++i; return *this; }
INT operator++(int) { int temp = i; ++i; return temp; } //is this the way to go?
INT& operator--() { --i; return *this; }
INT operator--(int) { int temp = i; --i; return temp; } //is this the way to go?
};
template<typename Iter, typename Fct>
Fct for_each(Iter b, Iter e, Fct f)
{
while(b != e) f(*b++);
return f;
}
void increment(INT&i)
{
++i;
}
void display(INT i)
{
std::cout << int(i) << ' ';
}
int main() {
std::vector<INT> v = { 3, 4, 5 };
for_each(v.begin(), v.end(), display);
std::cout << '\n';
for_each(v.begin(), v.end(), increment);
for_each(v.begin(), v.end(), display);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKY2xhc3MgSU5UIHsKCWludCBpOwpwdWJsaWM6CglJTlQoaW50IGlpKSA6IGl7IGlpIH0ge30KCW9wZXJhdG9yIGludCgpIHsgcmV0dXJuIGk7IH0KCglJTlQmIG9wZXJhdG9yKysoKSB7ICsraTsgcmV0dXJuICp0aGlzOyB9CglJTlQgb3BlcmF0b3IrKyhpbnQpIHsgaW50IHRlbXAgPSBpOyArK2k7IHJldHVybiB0ZW1wOyB9ICAgLy9pcyB0aGlzIHRoZSB3YXkgdG8gZ28/CgoJSU5UJiBvcGVyYXRvci0tKCkgeyAtLWk7IHJldHVybiAqdGhpczsgfQoJSU5UIG9wZXJhdG9yLS0oaW50KSB7IGludCB0ZW1wID0gaTsgLS1pOyByZXR1cm4gdGVtcDsgfSAgIC8vaXMgdGhpcyB0aGUgd2F5IHRvIGdvPwp9OwoKdGVtcGxhdGU8dHlwZW5hbWUgSXRlciwgdHlwZW5hbWUgRmN0PgpGY3QgZm9yX2VhY2goSXRlciBiLCBJdGVyIGUsIEZjdCBmKQp7CiAgICB3aGlsZShiICE9IGUpIGYoKmIrKyk7CiAgICByZXR1cm4gZjsKfQoKdm9pZCBpbmNyZW1lbnQoSU5UJmkpCnsKICA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