Please refer to the first answer in this question about implementing templates.
Specifically, take note of this quote
A common solution to thi
Does it matter if it's .tpp or any other extension? And why not use a .cpp?
It doesn't matter much which extension is actually used, as long it is different from any of the standard extensions used for C++ translation units.
The reasoning is to have a different file extension as they are usually detected by any C++ build systems for translation units (.cpp
, .cc
, ...). Because translating these as a source file would fail. They have to be #include
d by the corresponding header file containing the template declarations.
But if the implementation file has some funky looking file extension, how does that work in terms of compiling?
It needs to be #include
d to be compiled as mentioned.
Is it as efficient as if the implementations were in a cpp?
Well, not a 100% as efficient regarding compile time like a pure object file generated from a translation unit. It will be compiled again, as soon the header containing the #include
statement changes.
And are the implementations compiled every time I compile whatever source code
#include
s said header?
Yes, they are.