C++ template insanity