是否可以编写引用“this”指针的静态断言?我没有可用的 c++11,并且 BOOST_STATIC_ASSERT 不起作用。
struct blah
{
void func() {BOOST_STATIC_ASSERT(sizeof(*this));}
};
产生:
error C2355: 'this' : can only be referenced inside non-static member functions
error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE'
在 MSVC 2008 中。
动机:
#define CLASS_USES_SMALL_POOL() \
void __small_pool_check() {BOOST_STATIC_ASSERT(sizeof(*this) < SMALL_MALLOC_SIZE;} \
void* operator new(size_t) {return SmallMalloc();} \
void operator delete(void* p) {SmallFree(p);}