宏定义, 还可以作为一种对程序对象属性的描述手段来加以使用.
例如: 《编程原本》 (机械工业) P13.
template<typename Op>
requires(BinaryOperation(Op))
Domain(Op) square(const Domain(Op)& x, Op op)
{
return op(x, x);
}
其中" requires() "是一个宏, 定义如下(P251):
#define requires(...)
预编译器对模板函数展开后, require(BinaryOperation(Op)) 被空的内容所取代.
所以, 这里的宏"require" 实际上只起了一个注释的作用.
Binary在此处翻译为"二元".
require(BinaryOperation(Op)) 在此处的作用是告诉使用者, Op是一个二元操作.
另: Domain(Op) 表取Op的定义域.