為什么不向visual assist取取經(jīng)呢?
讓boost, c++設(shè)計(jì)新思維統(tǒng)統(tǒng)去見(jiàn)鬼吧。看哥的靜態(tài)斷言的巧妙實(shí)現(xiàn)吧。
可以在下列范圍內(nèi)使用(已經(jīng)在vc,gcc中測(cè)試):
在名字空間域中使用 ;
在函數(shù)域中使用 ;
在類域中使用 ;
在類模板中使用 。
在函數(shù)模板中使用 。
比boost強(qiáng)大的是關(guān)鍵是還能支持c語(yǔ)言,不使用模版使得編譯時(shí)間大大縮短!!還能夠打印自定義的錯(cuò)誤信息(我想這比啥都強(qiáng))。
注意:gcc 的c編譯器居然允許0除以0的結(jié)果作為數(shù)組長(zhǎng)度。此時(shí)只有警告,但是程序啟動(dòng)就會(huì)立即產(chǎn)生浮點(diǎn)數(shù)異常,退出。g++工作正常。vc的c編譯器工作正常。
#define JOIN(x,y) x ## y
#define JOIN_1(x,y) JOIN(x, y)
#define JOIN_2(x,y) JOIN_1(x, y)
/*It's the begin of all error message.*/
#define ERRORMSG_BEGIN ATTENTION__The_assertion_error_is__
/*
*To fetch a error if testnum==0||testnum==false, by divide 0.
*Cast to int to avoid warning caused by bool division.
*/
#define IF_ERROR(testnum) (((int)(testnum))/((int)(testnum)))
/*
*The errormsg only support following characters: [a-zA-Z0-9] and '_'.
*Because it's a part of variable's name.
*Example:STATIC_ASSERT(sizeof(int) <= sizeof(short), The_sizeof_int_is_larger_than_short__)
*For above example, (Most) compilers can print error include following message:
ATTENTION__The_assertion_error_is__The_sizeof_int_is_larger_than_short__234
*The number in the end is the linenumber of the position of the macro been called.
*/
#ifndef NDEBUG
#ifndef _MSC_VER
#define STATIC_ASSERT(testnum, errormsg) static char JOIN_2(JOIN_1(ERRORMSG_BEGIN,errormsg),__LINE__)[IF_ERROR(testnum)];
#else
#define STATIC_ASSERT(testnum, errormsg) static char JOIN_1(ERRORMSG_BEGIN,errormsg)[IF_ERROR(testnum)];
#endif
#else
#define STATIC_ASSERT(testnum, errormsg)
#endif
//有看不懂英文的請(qǐng)留言咨詢。
正好2000年是閏年,不然你慘了。不過(guò)正好100年內(nèi)不錯(cuò),不管了。
還有那個(gè)夏時(shí)令的標(biāo)志最好清空設(shè)置
ret_time->tm_isdst = 0;
多謝先生了。