Hacker News new | ask | show | jobs
by majoe 81 days ago
> I've seen some examples of C++ contracts replacing CRTP, but it used templates, which again, not a fan of.

I think you meant concepts.

C++ Concepts are the right answer in my opinion, if you want compile time polymorphism against an interface.

I don't think, there is a way around templates, they are C++'s way of compile-time polymorphism. Other languages, which allow for compile-time polymorphism, have similar mechanisms with similar constraints. I get where you come from, when you say that you're not a fan of templates, though. At least concepts help with clearer error messages for templates.

One advantage, that concepts have over CRTP is, that only consumers of your interface, not implementers, need to know about your concept.