这里所描述的是GNU编译器。
assert:
assert是运行时断言,如果在编译时定义了NDEBUG宏,则assert语句会被忽略掉(丢弃)。
在代码中写assert,debug版本不定义NDEBUG,release版本定义NDEBUG,这就是assert的使用场景。
static_assert:
static_assert 是编译时断言,用来判断编译时的constexpr,如果断言中是false,则编译错误。
static_assert(sizeof(void *) == 4, "64-bit code generation is not supported.");
还常在模板定义中使用。