Referring to this pointer in a static assert?
        Posted  
        
            by 
                Tyson Jacobs
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Tyson Jacobs
        
        
        
        Published on 2013-06-28T22:19:41Z
        Indexed on 
            2013/06/28
            22:21 UTC
        
        
        Read the original article
        Hit count: 392
        
Is it possible to write a static assert referring to the 'this' pointer? I do not have c++11 available, and BOOST_STATIC_ASSERT doesn't work.
struct blah
{
   void func() {BOOST_STATIC_ASSERT(sizeof(*this));}
};
Produces:
error C2355: 'this' : can only be referenced inside non-static member functions
error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE'
In MSVC 2008.
Motivation:
#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);}
© Stack Overflow or respective owner