Boost logo

Boost :

Subject: Re: [boost] [config][mpl][type_traits][integer] BOOST_STATIC_CONSTANT should use constexpr
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-04-21 18:33:32


Le 21/04/13 17:45, John Maddock a écrit :
>> I'm not against this radical alternative, and I even like it. I don't
>> know which compilers need the enum workaround and if Boost should
>> support them.
>
> The list seems to be:
>
> VC7 and earlier
> Vacpp 5.02 and earlier (currently 11.1)
> Sunpro 5.6 and earlier.
> MPW all versions?
>
>> What I want is just that integral_constant use them so that all the
>> traits in Boost conforms to the C++11 standard.
>
> Out of curiosity, can you detect the difference? What can you do with
> constexpr values that you can't with static const ones?
>
Even if most of the uses of integral_constant is to use its member
::value integral constant defines also the operator(), so it is a
nullary functor.

integral_constant<int, 1> a;
constexpr int f();

template <int I>
void g();

template <typename F>
void h(F&& fct) { g<fct()>(); }
h(&f);
h(a);

The last sentence will not compile if the operator() is not a constexpr
and it can not be a constexpr if ::value is not a consexpr, or can it?

As you can see the case is not current, but who know what the user want
to do with boost::integral_constant. The status quo means that it can
not do the same thing that with std::integral_constant.
Note that the operator() has just been proposed for C++14, but there is
however the conversion operator to the value type.

Best,
Vicente


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