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