Higher order functions in C++