Why export templates would be useful in C++ Export templates The C++ standard defines the concept of "export templates". These are template classes and functions which are only declared wherever they are used (ie. usually in a header file), while implemented only once in some compilation unit. In other words, you could have a header file like: // the_header_file.hh export template<typename T> void foo(const T& value); And then you could use it somewhere like: #include "the_header_file.hh" int main() { foo(123); foo("456"); } Note how the calling code inside main() doesn't see how the foo() template function has been implemented, like it's usual with regular templates. It only sees a declaration of it. The implementation of foo() can then be put in some source file to be compiled separately. What this means in practice is that the linker will have to launch the compiler in order to compile the instantiations of foo() for each type it's used with. Misconceptions about misconceptions about export templates No, that's not a typo in the heading. Whenever you see discussions about export templates, you will invariably see both some misconceptions about them and also misconceptions about these misconceptions themselves, especially in the cases when someone is arguing why export templates are actually unneeded and useless overhead in the standard (and thus should be removed from there). Invariably people (even expert C++ programmers and designers) will list the wrong reasons why export templates are "useless" and should be removed from the standard. They will typically list misconceptions people have about export templates such as: "Export templates allow hiding template implementations in precompiled closed-source proprietary libraries." "Export templates make compilation faster and object files smaller." etc... Almost invariably, whether these arguments are actually true or not is a matter of argument (and would also depend on the actual implementation of export templates...
First seen: 2025-11-16 04:57
Last seen: 2025-11-16 07:57