Boost logo

Boost :

Subject: Re: [boost] [config] consexpr workaround
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-11-15 07:29:50


vicente.botet wrote:
> "John Maddock" <boost.regex_at_[hidden]> 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?
>
> I think I'm missing something. Do you mean that we don't need
> to use constexpr for the variable value?

The purpose of constexpr is to mark something as a compile time constant such that it can be used in other compile time expressions, including types that weren't allowed as compile time constants before. It allows for constant-expression functions, data, and even constructors. Constant-expression data disallows dynamic initialization which const objects can undergo. Without constexpr support, neither constant-expression functions nor constructors are supported, nor is floating point constant-expression data. Thus, const is inappropriate in those cases, so BOOST_CONSTEXPR_OR_CONST cannot be used.

For non-floating point constant-expression data, const could work fairly well, but it permits dynamic initialization, so for platforms supporting constexpr, code would fail to compile that mistakenly compiled on platforms without constexpr support. Thus, BOOST_CONSTEXPR_OR_CONST would lead to maintenance issues. That means library code using BOOST_CONSTEXPR_OR_CONST and client code using that library code must either assume that BOOST_CONSTEXPR_OR_CONST merely means "const" or it must be conditionally compiled to account for either "const" or "constexpr." In that case, BOOST_CONSTEXPR_OR_CONST does nothing to help.

I don't think BOOST_CONSTEXPR_OR_CONST is helpful.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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