Just use lambda:
template<typename O> void f(int& i, O op){ op(i); } int main() { int i; f(i,[] (int& x) { ++x; }); f(i,[] (int& x) { --x; }); return 0; }
It is also unclear whether you want a post or preincrement.
As @TC noted, if you want to preserve the semantics of a normal statement, you can add a return statement.
source share