2 ms·
I really wish templates didn't work on a dumb "replace at call site until something compiles" manner. All template requirements should be verified at the funct
by eddd-ddde 2y ago
I really wish templates didn't work on a dumb "replace at call site until something compiles" manner.
All template requirements should be verified at the function definition, not at every call site.
There is concepts. But they are so unwieldy.
- munificent 2y agoIt's honestly a seriously hard problem. Yes, it's definitely nice to be able to typecheck generic code before instantiation. But supporting that ends up adding a lot of complexity to the typesystem. C++-style templates are sort of like "compile-time dynamic types" where the type system is much simpler because you can just write templates that try to do stuff and if the instantiation works, it works. C++ templates are more powerful than generics in most other languages, while not having to deal with covariance/contravariance, bounded quantification, F-bounded quantification, traits, and all sorts of other complex machinery that Java, C#, etc. have. I still generally prefer languages that do the type-checking before instantiation, but I think C++ picks a really interesting point in the design space.
- jenadine 2y agoC++0x concepts tried to achieve that but that didn't work. (But Rust traits works like that)
- pjmlp 2y agoThere were lots of politics evolved, moreso than technical issues. While not perfect concepts lite, alongside compile time evaluation do the job.
- trashburger 2y agoPlease no. Templates being lazy is so much better than Rust's eager trait evaluation, the latter causing incredible amounts of pain beyond a certain complexity threshold.
- eddd-ddde 1y agoHow so? I'd really like to see an example. If you can't explain what requirements your function has before calling it then how do you know it even does what you expect?