但在模板编程中,直接使用static_assert(false, "message")可能会导致问题,因为它会在模板定义时就触发断言。 3.4.2 always_false结构体的魔法 为了解决上述问题,我们可以使用always_false这一技巧。这是一个模板结构体,其值始终为false。 template <typename T>struct always_false {static constexpr bool value = ...
The constant expression can of course depend on template parameters, and that's where the checking comes in: if you put astatic_assertin a template then the compilation will fail if the specified condition is not True, and the error message will be a lot clearer than what you would get o...
我一直在尝试实现类似于static_assertC++ 11标准中定义的方法.主要问题是C++编译器如何将传递给的文本消息static_assert写成const char*?我可以让编译器写一个像这样的消息A_is_not_POD.这就是我所拥有的: #define MY_STATIC_ASSERT(condition, name) \ typedef char name[(condition) ? 1 : -1]; Run Code...
*/ -void -finish_static_assert (tree condition, tree message, location_t location, - bool member_p, bool show_expr_p) +bool +cexpr_str::type_check (location_t location) { tsubst_flags_t complain = tf_warning_or_error; - tree message_sz = NULL_TREE, message_data = NULL_TREE; i...