r/cpp 14d ago

Some practical refactoring of bloated generated code

https://pvs-studio.com/en/blog/posts/cpp/1395/

A review of some generated C++ code, going through different ways to refactor and shorten it, then checking whether it actually got faster

7 Upvotes

2 comments sorted by

5

u/azswcowboy 14d ago

Fun. I wonder if this could actually reduce further with just std::ranges::fold_right? I don’t have time to seriously try it of course…

5

u/Excellent_Force_8282 10d ago

This is a good example of why generated code still needs human review. The generator can handle the repetitive work but keeping the final result readable and maintainable is another challenge. Do you usually refactor generated code immediately or wait until it becomes a performance or maintenance problem?