Boost logo

Boost :

Subject: Re: [boost] [config] consexpr workaround
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2010-11-13 07:16:41


On 13/11/10 09:40, John Maddock wrote:
>> For this case the existing macro BOOST_STATIC_CONSTANT could be
>> modified to use BOOST_CONSTEXPR_OR_CONST when static const was used.
>
> I don't see how that can work:
>
> * If the type being initialized is known to be an integer type then we
> can use BOOST_STATIC_CONSTANT and we wouldn't gain anything from using
> constexp?

One small thing you gain is that there will be an error if someone
misuses BOOST_STATIC_CONSTANT thus (outside a class body):

int f() {
  return 0;
}

BOOST_STATIC_CONSTANT(int, b = f());

whereas at present there is no such error for the 'static const'
implementation, only the 'enum' implementation.

> * If the type being initialized might not be an integer type, then we
> can use constexp or a static const declaration, but we can't use
> BOOST_STATIC_CONSTANT (because it may be implemented in terms of an enum).

If you only intend to support compilers on which it is not implemented
as an enum, it might be reasonable to use it for non-integer types
(though one would have to take care of static initialization order...).

John Bytheway


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