14. // C のマクロ (危険)
#define SWAP(x, y, type) { type temporary__; temporary__ = x; x = y; y = temporary__; }
int main(void)
{
int a = 1;
int b = 2;
SWAP(a, b, int);
return 0;
}
プリコンパイラー
int main(void)
{
int a = 1;
int b = 2;
{
int temporary__;
temporary__ = a;
a
= b;
b
= temporary__;
}
return 0;
}
15. int main()
template <int N>
{
struct Factorial
int x = Factorial<3>::value;
{
return 0;
enum { value = N *
Factorial<N 1>::value };
コンパイラー
}
struct Factorial0 { enum { value = 1
}; };
struct Factorial1 { enum { value = 1 * Factorial0::value }; };
};
struct Factorial2 { enum { value = 2 * Factorial1::value }; };
template <>
struct Factorial<0>
{
struct Factorial3 { enum { value = 3 * Factorial2::value }; };
int main()
{
enum { value = 1 };
int x = Factorial3::value;
};
return 0;
}
34. var x
= Expression.Parameter(type: typeof(int));
var y
= Expression.Parameter(type: typeof(int));
var add
= Expression.Add
var lambda = Expression.Lambda
(left: x, right: y);
(add, x, y
Func<int, int, int> newDelegate =
(Func<int, int, int>)lambda.Compile();
);