It depends on the compiler, but each one I looked at creates a function that can then be called using the parameters of the replaceable template to generate code for each parameter.
as a (very) simple example:
template <typename T> T Max(T a, T b) { return a > b ? a : b; }
when Max<int> and Max<float> called and not nested, the compiler generates (they are specially designed to prevent other problems):
int Max(int a, int b) { return a > b ? a : b; } float Max(float a, float b) { return a > b ? a : b; }
Then it gets stuck at the beginning of the object, and then refers to it, then this is done for some embedded lines (in MSVC)
Necrolis
source share