Using template Metaprogramming to write optimized code