Templated c++ memoization from a local programming contest