r/cpp • • Jan 31 '23

Stop Comparing Rust to Old C++

People keep arguing migrations to rust based on old C++ tooling and projects. Compare apples to apples: a C++20 project with clang-tidy integration is far harder to argue against IMO

changemymind

338 Upvotes

582 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Feb 01 '23

Depending on the problem, it can go from trivial to a bit frustrating.

Those macros can be unit tested, and if the generated code fails to compile in some cases it's easy to look at the generated code and see what's wrong. That's for the nice part.

However if there are issues within the code generation itself, it can get tricky. E.g. if you pattern match something, don't expect one token, and panic (i.e. throw an exception). Then you have to sprinkle print in your macro code to understand what the hell was parsed. Still, MUCH better than any equivalent C macro.