Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2001-03-11 19:58:13


The BOOST_STATIC_CONSTANT macro was added to <boost/config.hpp> two days
ago. I think it has a slight inefficiency. Here's a copy:

//==========================================================================

// BOOST_STATIC_CONSTANT workaround ------------------------------------- //
// On compilers which don't allow in-class initialization of static integral
// constant members, we must use enums as a workaround if we want the
// constants to be available at compile-time. This macro gives us a
// convenient way to declare such constants.
#ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
# define BOOST_STATIC_CONSTANT(type, assignment) enum { assignment }
#else
# define BOOST_STATIC_CONSTANT(type, assignment) static const type
assignment
#endif

//==========================================================================

It is used like:

//==========================================================================

    BOOST_STATIC_CONSTANT( ::std::size_t, bit_count = Bits );

//==========================================================================

My question is: why do we make the user explicitly add the "="? What's
wrong with (excuse any line-wrap my e-mail client adds):

//==========================================================================

#ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
# define BOOST_STATIC_CONSTANT(type, object, value) enum { object = (value)
}
#else
# define BOOST_STATIC_CONSTANT(type, object, value) static type const object
= (value)
#endif

//==========================================================================

(I moved the "const" to follow the type, since that always works[1].) Is
there some subtle point of macro definitions that keeps this from working,
or did we make a silly oversight? If it was an oversight, can we change the
macro to this form? Yes, I know that I'm asking for an incompatible change,
but the macro is only a few days old, so I don't think that there's too much
code to change. Within Boost 1.21.0 itself, the macro (name) appears 207
times in 12 files. It could be updated in approximately a day, probably by
a team of people with CVS write access. (I'll change them if you guys
insist, but I would have to send Beman a ZIP file to merge into CVS.)

[1] Pointers need the "const" after the other parts of the type, otherwise
the "const" would affect the base type instead. It doesn't really matter in
this case since only integral and enumerated types can be used as static
constants.

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

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