Boost logo

Boost :

Subject: Re: [boost] [config] consexpr workaround
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-03-19 03:51:26


2010/11/13 vicente.botet <vicente.botet_at_[hidden]>

> 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
>

Hi,

Could/should BOOST_CONSTEXPR expand to inline in C++03?

If not, could a macro BOOST_CONSTEXPR_OR_INLINE be added?

For one thing, constexpr functions are usually (but maybe not always?) good
candidates for inlines. But also please consider the following example.
Suppose we put the following code in a header file:

struct X { BOOST_CONSTEXPR int fun() const; };

BOOST_CONSTEXPR int X::fun() const { return 0; }

Now if this file is included in multiple .cpp files, this will fail at link
time in C++03 with message "multiple definition of `X::fun()", and it will
link fine in C++11. But when BOOST_CONSTEXPR is inline in C++03, the above
works.

Would making BOOST_CONSTEXPR expand to inline in C++03 do any harm?

Cheers,
Kris


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