4 ms·
Template instantiation is a simple text replacement tool and it seems to work just fine.
by suprfsat 6y ago
Template instantiation is a simple text replacement tool and it seems to work just fine.
- oblio 6y agoIs that why templates have such user friendly error messages?
- dig1 6y agoI'm afraid it is not :) Template instantiation has way more rules than simple text replacement. Implicit instantiation is a story on its own, not counting that every compiler is free to implement own instantiation logic. Someone said once that the truly portable thing between C++ compilers is only preprocessor :)
- mhh__ 6y agohttps://github.com/dlang/dmd/blob/master/src/dmd/dtemplate.d https://github.com/dlang/dmd/blob/master/src/dmd/dtemplate.d That must be why the implementation of D's templates, which are designed to be easier to implement than C++'s is at least 8337 lines? edit: Clang's clocks in at about 11k lines (.cpp alone), I'm too scared to find out for GCC.
- formerly_proven 6y agoGCC's cp/pt.c is around 30k lines. But I don't expect the implementation of templates to be this localized, sure, most of it is probably in that module, but a lot will be strewn about the code base, too.
- tylerhou 6y agoBecause of compile-time evaluation and/or template pattern matching, C++ template instantiation is Turing complete. So it's basically as far away from "simple text replacement tool" as you could possibly be.