Remix.run Logo
rfgplk 5 hours ago

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)

kartoffelsaft 4 hours ago | parent | next [-]

> The template metaprogramming C++ offers is the most powerful of any imperative language

I'm curious what languages you're comparing to here. Feels like it's only slightly more expressive than pure generics, but I admittedly haven't done much template metaprogramming myself. How does it compare to, say, Zig's comptime?

cyber_kinetist 4 hours ago | parent | prev | next [-]

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.

nly 4 hours ago | parent [-]

> obtuse error messages

With concepts and constexpr-if and consteval it's increasingly less of a problem

undershirt 5 hours ago | parent | prev | next [-]

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

rramadass 5 hours ago | parent | next [-]

You might find Functional Programming in C++ by Ivan Cukic relevant.

rfgplk 5 hours ago | parent | prev [-]

Not yet, I might one day.

unnah 5 hours ago | parent | prev [-]

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.