Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-05-06 20:56:39


David Abrahams wrote:
> > Looks good. I've applied it.
>
> Maybe we should be treating Sun in the config as though it doesn't
> support in-class static constant initialization (so
> BOOST_STATIC_CONSTANT generates an enum)? It seems like trying to
> track down all these cases piecemeal is going to be a losing battle.

But then Sun is right to complain there, isn't it? It's true that there are
a lot of places where we are using BOOST_STATIC_CONSTANT without the
corresponding and appropriately guarded definition, but if we adopt the
strategy you suggest, in the end, as more and more compilers will enforce
the rule, we will end up with enums everywhere; which kind of defeats the
purpose of the macro - if I thought the enums are the way to go, I would
never use BOOST_STATIC_CONSTANT in the first place.

On a side note, on conforming compilers the need for out-of-class constant
definitions can be greatly reduced if you wrap the constants in MPL's
'bool_', 'int_' et al. classes, e.g. this:

template <unsigned A, unsigned S>
struct alignment_logic
    : mpl::size_t< (A < S ? A : S) > // here
{
};

template< typename T >
struct alignment_of_impl
    : alignment_logic<
          sizeof(detail::alignment_of_hack<T>) - sizeof(T)
        , sizeof(T)
>
{
};

instead of this:

template <unsigned A, unsigned S>
struct alignment_logic
{
    BOOST_STATIC_CONSTANT(std::size_t, value = A < S ? A : S);
};

template< typename T >
struct alignment_of_impl
{
    BOOST_STATIC_CONSTANT(std::size_t, value =
        (::boost::detail::alignment_logic<
            sizeof(detail::alignment_of_hack<T>) - sizeof(T),
            sizeof(T)
>::value));
};

Aleksey


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