A C++ solution using macros.

Reviewed by @tolmasky.