Templates undoubtedly take longer.
However, templates are much more powerful and obey C ++ syntax rules, while macros do not work.
The reason that templates take longer is because you may have a recursive template, and all these recurring events must be generated. This is the basis on which loop constructs are built in the Metaprogramming template. Macros, by contrast, cannot call themselves and therefore are limited to one extension.
, , Wikipedia:
template <int N>
struct Factorial
{
enum { value = N * Factorial<N - 1>::value };
};
template <>
struct Factorial<0>
{
enum { value = 1 };
};
void foo()
{
int x = Factorial<4>::value;
int y = Factorial<0>::value;
}
, , (Factorial<4>) 5 . .