A C++ solution using macros.

I have one that uses operator overloading from a few days ago too if you want ( https://gist.github.com/tolmasky/f2f79c7e56472bd47eb7 ), but this one is much shorter.