4 ms·
C++ metaprogramming was an accident. Expression templates are a huge, obscure, and very surprising hack. I don't know about you, but I find them really hard to
by jordigh 9y ago
C++ metaprogramming was an accident. Expression templates are a huge, obscure, and very surprising hack. I don't know about you, but I find them really hard to understand. SFINAE wasn't meant to be used for compile-time branching, but when people realised that it could be used that way, it was just about the only tool for metaprogramming in C++. It certainly wasn't designed for that purpose, though.
C++ has for a long time embraced metaprogramming and given new tools for it (I think there's `static if` now? Or will be soon?), but it really all started out as an accident:
https://softwareengineering.stackexchange.com/questions/125314/in-c-were-sfinae-and-metaprogramming-intentional-or-just-a-byproduct-of-templ https://softwareengineering.stackexchange.com/questions/1253...
> If you wanted to compare D with C++
My second link does that, compares Mir to a bunch of other numeric libraries, most in C++.
Edit: (Replying to comment below by acdha because HN does not allow me to post new comments right now.)
I don't have that kind of example handy. I can point you to the D Gems section of the D tour to give you a taste of what is possible in D. Click on "Gems" in the navigation menu above to see them.
https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs https://tour.dlang.org/tour/en/gems/uniform-function-call-sy...
If you want a detailed blog post comparing D and C++ metaprogramming, I don't have it ready yet. If you're curious to learn about it, look in more depth at the links I've provided. I'm sorry I don't have the resources to give you the detailed answer you require.
- acdha 9y agoAgain, I'm not defending C++ or disparaging D but saying that this style of abrasive advocacy doesn't leave the reader knowing anything more about D than they already knew. Your last sentence is a great example: > My second link does that, compares Mir to a bunch of other numeric libraries, most in C++. This is technically correct but not helpful because it just shows a bunch of benchmark results. If the point is to demonstrate how D is more powerful for this kind of programming what would be useful is something which shows the same function written in modern C++ and D so you could see how they differ.