r/learnprogramming • • 17m ago

Topic Where does the Curiously Recurring Template Pattern actually earn its keep in production code

I understand CRTP 👀 class Derived : public Base<Derived>, static polymorphism, no vtable overhead. Every tutorial shows the same toy example with `Shape` and `area()`, and then it stops. What I can't find is real-world usage. I'd love to hear where you've actually shipped it, and why prefer beat the Mixin or policy‑based design. Use cases I've seen so far:

Mixins, like std::enable_shared_from_this, to inject behavior into the derived class

Static interfaces for hot paths where virtual dispatch costs too much

Expression templates in Eigen

I'm still unsure about whether-

  1. Is it worth the readability cost since C++20 has concepts and deducing this?
  2. Any production pitfalls like error messages, code bloat, or slicing issues?

If you've used it in a codebase you maintain, I'd love to hear what problem it solved and if you derived any reusable patterns that you continue to use as snippet when shipping production code under limited time constraints. 🙏

1 Upvotes

0 comments sorted by