logoalt Hacker News

aw1621107last Friday at 5:50 AM0 repliesview on HN

> I could imagine a world where templates are compiled separately and there is essentially duck typing built into the runtime.

The bit of my comment you quoted was just talking about definition checking. Separate compilation of templates is a distinct concern and would be an entirely new can of worms. I'm not sure if separate compilation of templates as they currently are is possible at all; at least off the top of my head there would need to be some kind of tradeoff/restriction added (opting into runtime polymorphism, restricting the types that can be used for instantiation, etc.).

I think both definition checking and separate compilation would be interesting to explore, but I suspect backwards compat and/or migration difficulties would make it hard, if not impossible, to add either feature to standard C++.

> For example, if the template parameter type is a concept, your type could be automatically hooked up as if it was just a normal class and you inherited from it.

Sounds a bit like `dyn Trait` from Rust or one of the myriad type erasure polymorphism libraries in C++ (Folly.Poly [0], Proxy [1], etc.). Not saying those are precisely on point, though; just thought some of the ideas were similar.

[0]: https://github.com/facebook/folly/blob/main/folly/docs/Poly....

[1]: https://github.com/microsoft/proxy