3 ms·
Template metaprogramming still solves certain problems better than other solutions. If it is not used obsessively, then there are better languages
by veyron 15y ago
Template metaprogramming still solves certain problems better than other solutions. If it is not used obsessively, then there are better languages
- zurn 15y agoWhat kinds of problems? I can't easily think of problems where C++ templates are more powerful than metaprogramming facilities of high level languages like lisp...
- veyron 15y agoI 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.