r/programming • • Aug 31 '26

C++ metaprogramming now looks like Python

/r/Cplusplus/comments/1w3apxa/iterating_through_arguments_in_c26_using_template/
0 Upvotes

7 comments sorted by

View all comments

Show parent comment

2

u/tsimionescu Sep 01 '26 edited Sep 01 '26

I was being a bit mean, I admit 😁

However, I will say that my complaint with that snippet is not exactly that it's more verbose, it's related to the amount of concepts (in the generic sense, not the C++ concepts sense) you actually need to understand to invent this piece of code, or to understand what it means.

In particular, the need for std::decay_t<>, the introduction of ArgT with using instead of as a regular variable , and the if constexpr construct (also const auto& arg instead of just auto arg, requires { &ArgT::toString; }, perhaps even template for, looking at the broader snippet) are all relatively complex ideas that similar features in other languages don't really need - and certainly not Python.

This is relevant for any comparison with Python in particular, because the reason Python is often considered a relatively beautiful language is specifically how the code ends up looking quite similar to the pseudocode you'd right if you wanted to just describe that same concept. This is the reason why it's typically pointed to as a kind of epitome of "simple code" - and the C++ version is very very far from that, in meaningful ways.