3 ms·
> A C++ implementor could use a strategy similar to what is used in Java and C#, and re-instantiate every template on demand at runtime. Are you sure? Expandin
by pcwalton 11y ago
> A C++ implementor could use a strategy similar to what is used in Java and C#, and re-instantiate every template on demand at runtime.
Are you sure? Expanding templates can affect the parsing of subsequent code, as this example illustrates: http://yosefk.com/c++fqa/web-vs-c++.html#misfeature-3 http://yosefk.com/c++fqa/web-vs-c++.html#misfeature-3 You pretty much have to expand them at compile time.
(This sort of complexity illustrates why I prefer generics to templates, incidentally.)
- catnaroek 11y agoWhat I meant is: (0) Expand the templates at compile-time, in order to type-check the code. (1) Don't generate target language code for each specific instantiation, though. (2) Re-expand the templates (or some representation of them) at runtime. It's a very silly implementation strategy, of course. But I don't see why it's fundamentally impossible to do this - it's just undesirable. And, yes, I agree about generics being better.
- haberman 11y agoShameless plug, I wrote a blog article explaining the yosefk example above more explicitly: http://blog.reverberate.org/2013/08/parsing-c-is-literally-undecidable.html http://blog.reverberate.org/2013/08/parsing-c-is-literally-u...