64,649
社区成员
发帖
与我相关
我的任务
分享
//书中代码片段
template<bool> struct CompileTimeChecker
{
CompileTimeChecker(...);
};
template<> struct CompileTimeChecker<false> { };
#define STATIC_CHECK(expr, msg) \
{\
class ERROR_##msg {}; \
(void)sizeof(CompileTimeChecker<((expr) != 0)>((ERROR_##msg())));\
}
//测试代码
int main()
{
STATIC_CHECK( 1==2, one_is_two );
return 0;
}
template<int> struct CompileTimeError;
template<> struct CompileTimeError<true> {};
#define LOKI_STATIC_CHECK(expr, msg) \
{ Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; }
(void)sizeof(CompileTimeChecker<((expr) != 0)>((ERROR_##msg())));
修改为:
CompileTimeChecker<((expr) != 0)>((ERROR_##msg()));