The approach I use is this (seems like "Method 3"):
// template_file.h #pragma once /* YOUR TEMPLATE DECLARATION HERE */ #include <template_file.inline.h>
// template_file.inline.h #pragma once #include <template_file.h> /* DEFINITIONS HERE */
"inline" file is used like a usual .cpp file. This speeds up compilation a lot.
Sadly, I don't remember where I first found this approach.
Edit: you can replace "pragma once" with "#ifndef .., #define ..". Same thing.
For most purposes, this is probably the best way to go. Only one thing:
This line in "template_file.inline.h" is redundant, unless you include "template_file.inline.h" from somewhere else and are not sure if "template_file.h" will be included beforehand. Otherwise the include guards just do their job. In my opinion, it is cleaner to just say that the "*.inline.h" files are not for use outside of "*.h".
@ysg: There is no "*.cpp". The "#include" directive basically inserts the plain text from the included file verbatim. From the compilers view, everything ends up inside the header. The inline files containing the implementation are just for organization.