4 ms·
I'm not an expert on this in any way either, but I think template instantiations end up as 'weak symbols' in object files, so when you link multiple objects tog
by tomn 11y ago
I'm not an expert on this in any way either, but I think template instantiations end up as 'weak symbols' in object files, so when you link multiple objects together that contain the same template instantiations, you only end up with one of them in the final object file.
This of course means that compile times are a bit longer, as a given template may be instantiated by the compiler many times, but in terms of run-time and final object size it should be optimal.
I think this behaviour also makes more sense when you think about inlining -- a lot of template code is actually doing something quite simple under the hood, so by having the compiler instantiate your template each time, you potentially allow it to inline the code qithout relying on a LTO, which may not have been feasible when this whole mess was designed.