C++ solution using a Functor

Some abuse of the function operator means no #define needed in this solution.