Boost logo

Boost :

From: davidbrownell98006 (david_brownell_at_[hidden])
Date: 2002-01-28 20:19:42


I am trying to use BOOST_STATIC_ASSERT, but I think that my problem
is either with my compiler (VC 7.0 - aka VS.NET) or my understanding
of template template parameters. I would like the following code to
compile without errors. The code is pretty straight forward, so I
will just post it rather than trying to explain it in plain English.

Thanks in advance for your help, and please be gentle if this is
simply a stupid question :)

David Brownell

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

#include "boost\static_assert.hpp"

#define COMPILE_LESS_DESIRABLE_CODE 1

template <unsigned int Number>
struct Size
{
    enum { SIZE = Number };
};

template <
            class SizeClass,
            template <class> class APolicy
>
struct AClass : public APolicy<SizeClass>
{
};

template <class SizeClass>
struct PolicyNumber1
{
#if COMPILE_LESS_DESIRABLE_CODE
    enum { SizeClassSize = SizeClass::SIZE };
    BOOST_STATIC_ASSERT(SizeClassSize == 1);
#else //COMPILE_LESS_DESIRABLE_CODE
    BOOST_STATIC_ASSERT(SizeClass::SIZE == 1);
#endif //COMPILE_LESS_DESIRABLE_CODE
};

template <class SizeClass>
struct PolicyNumber2
{
#if COMPILE_LESS_DESIRABLE_CODE
    enum { SizeClassSize = SizeClass::SIZE };
    BOOST_STATIC_ASSERT(SizeClassSize == 2);
#else //COMPILE_LESS_DESIRABLE_CODE
    BOOST_STATIC_ASSERT(SizeClass::SIZE == 2);
#endif //COMPILE_LESS_DESIRABLE_CODE
};

int main(void)
{
    AClass<Size<1>, PolicyNumber1> c1;
    AClass<Size<2>, PolicyNumber2> c2;
    return(true);
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk