C++ solution using template metaprogramming.