template <int N>
struct Factorial {
enum { value = N * Factorial<N - 1>::value };
};
template <>
struct Factorial<0> {
enum { value = 1 };
};
const int x = Factorial<4>::value; // == 24
const int y = Factorial<0>::value; // == 1
プリコンパイルの後、コンパイラが生成したものを魔法のように見ることができた場合、実際には次のようになります。
const int x = 24;
const int y = 1;
struct Factorial
そして、これらの , 倍数の実際の定義が表示されるでしょうか? もしそうなら、彼らはどのように見えますか?私は、メタプログラミング プロセスのこの部分に頭を悩ませようとしています。