[SG10] P0304: constexpr addressof
Agustín Bergé
agustinberge at gmail.com
Mon Mar 14 13:33:46 CET 2016
On 3/14/2016 12:48 AM, Gabriel Dos Reis wrote:
> I suppose there is no hope to get people write simple code? :-)
Is that a contrived way of showing your support for the macro-enabled
simple case and thus a feature-test macro? If so, thank you.
Regards,
--
Agustín K-ballo Bergé
http://talesofcpp.fusionfenix.com
> -------- Original message --------
> From: Richard Smith <richard at metafoo.co.uk>
> Date: 3/13/2016 8:47 PM (GMT-08:00)
> To: Agustín Bergé <agustinberge at gmail.com>
> Cc: "features at isocpp.open-std.org (features at open-std.org)"
> <features at open-std.org>
> Subject: Re: [SG10] P0304: constexpr addressof
>
> On Sun, Mar 13, 2016 at 6:29 PM, Agustín Bergé <agustinberge at gmail.com>
> wrote:
> > On 3/13/2016 10:16 PM, Richard Smith wrote:
> >>
> >> On Fri, Mar 11, 2016 at 11:30 AM, Daniel Krügler
> >> <daniel.kruegler at gmail.com> wrote:
> >>>
> >>> 2016-03-11 20:27 GMT+01:00 Agustín Bergé <agustinberge at gmail.com>:
> >>>>
> >>>> On 3/11/2016 4:14 PM, Nelson, Clark wrote:
> >>>>>
> >>>>> Agustin raised the question of whether there should be a macro to
> >>>>> indicate the presence of the fix for LWG2296. I made a couple of
> >>>>> replies suggesting that, to me, the answer is not obviously "yes".
> >>>>>
> >>>>> So far, no one (not even Agustin) has made any further comment.
> >>>>
> >>>>
> >>>> I said that if there's no macro I'd prefer to leave the code broken.
> >>>> That should have implied my motivation is weak. I think a macro
> fits the
> >>>> bill, but if lacks in popularity I'm not going to push for it.
> >>>
> >>>
> >>> I tentatively agree, I see no need for a feature macro here.
> >>
> >>
> >> I can imagine a macro being useful:
> >>
> >> struct optional {
> >> bool b;
> >> T t;
> >> constexpr T *get() {
> >> return b ?
> >> #if __cpp_constexpr_addressof
> >> std::addressof(t)
> >> #else
> >> &t
> >> #endif
> >> : nullptr;
> >> }
> >> };
> >
> >
> > That's my use case :)
> >
> >> The idea here is that it's more important that get() is constexpr than
> >> that it works if there's an overloaded operator&, so addressof is only
> >> used if it would actually work in a constant expression. Achieving
> >> this result with SFINAE seems difficult.
> >
> >
> > This appears to do the trick, but there's a chance that it is ill-formed:
> >
> > #if 0
> > using std::addressof;
> > #else
> > template <typename T>
> > constexpr T* addressof(T& v) { return &v; }
> > #endif
> >
> > struct is_addressof_constexpr {
> > static int _probe;
> >
> > template <typename T, T* = addressof(_probe)>
>
> If you use "std::addressof" instead of "addressof", I think this
> default template argument has no valid instantiations in C++14, so is
> ill-formed (no diagnostic required). If you don't qualify it, it can
> find the wrong addressof via ADL.
>
> > static std::true_type check(T);
> >
> > static std::false_type check(...);
> >
> > static constexpr bool value =
> > decltype(check(0))::value;
> > };
> >
> > static_assert(is_addressof_constexpr::value, "");
More information about the Features
mailing list