3 ms·
I didn't use the word 'powerful' because powerful generally refers to expressivity. I'm most interested in performance. C++ template metaprogramming gives you
by veyron 15y ago
I didn't use the word 'powerful' because powerful generally refers to expressivity. I'm most interested in performance.
C++ template metaprogramming gives you most of the expressivity of generic programming without paying a large runtime penalty (because the resolution still occurs at compile time, the compiler can take advantage of this). This is in contrast to other languages, where run-time generic programming leads to performance penalties.
Now, as the stereotypical example of how C++ template metaprogramming can actually beat standard C programming, compare the performance of C qsort with C++ std::sort.
- mietek 15y agoNot all expressive generic programming techniques have run time costs. The parent poster mentioned Lisp, in which macros are also usually expanded at compile time. Furthermore, Template Haskell offers type-safe compile time metaprogramming.