logoalt Hacker News

rfgplktoday at 3:56 PM3 repliesview on HN

I've developed a style that I legitimately call Heterodox C++ (mainly due to the popularity of Orthodox C++), it is effectively a purely functional & metaprogramming heavy style of C++. Quite the opposite of this, not everyones cup of tea, and it won't fit into every codebase but it is incredibly powerful. The template metaprogramming C++ offers is the most powerful of any imperative language, and (subjective opinion) is second only to Lisp, but few people make use of it. With some of C++26 features you can almost even replicate most of Rusts safety features in pure C++ (via function tagging + reflection)


Replies

cyber_kinetisttoday at 4:42 PM

The problem with metaprogramming-heavy C++ codebases is always compilation times and obtuse error messages...

Template metaprogramming is sometimes very useful to get around C++'s language restrictions, but I tend to use it sparingly.

show 1 reply
undershirttoday at 4:05 PM

have you written about this anywhere, or hosting any examples?

show 2 replies
unnahtoday at 4:13 PM

C++ template metaprogramming is in some ways more powerful than Common Lisp macros, because it works at the type level: you can generate new types and dispatch into separate implementations by type. In contrast, Common Lisp type declarations are not available at macro expansion time unless you implement a full source-to-source translator in macros.