「C ++プログラミング言語(第4版)」第2.4.3章
static_assert(A、S)Aは定数式です。Aがtrueでない場合、コンパイルは失敗し、Sはコンパイラエラーメッセージとして出力されます。
#define debug qDebug()<<
constexpr int C = 299792458;
void debugValue(int value)
{
const int maxSpeed = 10000000000;
static_assert(maxSpeed < C,"You can't go faster than the speed of light");
debug "value = "<<value;
}
int main(int argc, char *argv[])
{
debugValue(2);
}