Boost logo

Boost :

Subject: [boost] [config] consexpr workaround
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-11-13 03:31:15


Hi,

in order to make easier the introduction of constexpr in a portable way I would like we add a Boost Config workarround. We can define some macros depending on whether BOOST_NO_CONSTEXPR is defined or not.

#if defined(BOOST_NO_CONSTEXPR)
#define BOOST_CONSTEXPR
#define BOOST_CONSTEXPR_OR_CONST const
#else
#define BOOST_CONSTEXPR constexpr
#define BOOST_CONSTEXPR_OR_CONST constexpr
#endif

For most of the constexpr functions or constructors BOOST_CONSTEXPR will work.

constexpr tuple();
=versus=
BOOST_CONSTEXPR tuple();

When used for static constants BOOST_CONSTEXPR_OR_CONST is needed as we need to preserv the const keyword when consexpr is not available.

static constexpr UIntType xor_mask = a;
=versus=
static BOOST_CONSTEXPR_OR_CONST UIntType xor_mask = a;

We could also add a STATIC_CONSTEXPR macro

#define BOOST_STATIC_CONSTEXPR static BOOST_CONSTEXPR_OR_CONST

static constexpr UIntType xor_mask = a;
=versus=
BOOST_STATIC_CONSTEXPR UIntType xor_mask = a;

For this case the existing macro BOOST_STATIC_CONSTANT could be modified to use BOOST_CONSTEXPR_OR_CONST when static const was used.

static constexpr UIntType xor_mask = a;
=versus=
BOOST_STATIC_CONSTANT(UIntType, xor_mask = a);

Can we introduce this workaround?

Best regards,
Vicente

_____________________
Vicente Juan Botet Escribá
http://viboes.blogspot.com/


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