<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 &lt;richard@metafoo.co.uk&gt; </div><div>Date: 3/13/2016  8:47 PM  (GMT-08:00) </div><div>To: Agustín Bergé &lt;agustinberge@gmail.com&gt; </div><div>Cc: "features@isocpp.open-std.org (features@open-std.org)" &lt;features@open-std.org&gt; </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é &lt;agustinberge@gmail.com&gt; wrote:<br>&gt; On 3/13/2016 10:16 PM, Richard Smith wrote:<br>&gt;&gt;<br>&gt;&gt; On Fri, Mar 11, 2016 at 11:30 AM, Daniel Krügler<br>&gt;&gt; &lt;daniel.kruegler@gmail.com&gt; wrote:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; 2016-03-11 20:27 GMT+01:00 Agustín Bergé &lt;agustinberge@gmail.com&gt;:<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; On 3/11/2016 4:14 PM, Nelson, Clark wrote:<br>&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt; Agustin raised the question of whether there should be a macro to<br>&gt;&gt;&gt;&gt;&gt; indicate the presence of the fix for LWG2296. I made a couple of<br>&gt;&gt;&gt;&gt;&gt; replies suggesting that, to me, the answer is not obviously "yes".<br>&gt;&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;&gt; So far, no one (not even Agustin) has made any further comment.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; I said that if there's no macro I'd prefer to leave the code broken.<br>&gt;&gt;&gt;&gt; That should have implied my motivation is weak. I think a macro fits the<br>&gt;&gt;&gt;&gt; bill, but if lacks in popularity I'm not going to push for it.<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; I tentatively agree, I see no need for a feature macro here.<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; I can imagine a macro being useful:<br>&gt;&gt;<br>&gt;&gt; struct optional {<br>&gt;&gt;&nbsp;&nbsp;&nbsp; bool b;<br>&gt;&gt;&nbsp;&nbsp;&nbsp; T t;<br>&gt;&gt;&nbsp;&nbsp;&nbsp; constexpr T *get() {<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return b ?<br>&gt;&gt; #if __cpp_constexpr_addressof<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::addressof(t)<br>&gt;&gt; #else<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;t<br>&gt;&gt; #endif<br>&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : nullptr;<br>&gt;&gt;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt; };<br>&gt;<br>&gt;<br>&gt; That's my use case :)<br>&gt;<br>&gt;&gt; The idea here is that it's more important that get() is constexpr than<br>&gt;&gt; that it works if there's an overloaded operator&amp;, so addressof is only<br>&gt;&gt; used if it would actually work in a constant expression. Achieving<br>&gt;&gt; this result with SFINAE seems difficult.<br>&gt;<br>&gt;<br>&gt; This appears to do the trick, but there's a chance that it is ill-formed:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #if 0<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; using std::addressof;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #else<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; template &lt;typename T&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; constexpr T* addressof(T&amp; v) { return &amp;v; }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #endif<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; struct is_addressof_constexpr {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static int _probe;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; template &lt;typename T, T* = addressof(_probe)&gt;<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>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static std::true_type check(T);<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static std::false_type check(...);<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static constexpr bool value =<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; decltype(check(0))::value;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; };<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; static_assert(is_addressof_constexpr::value, "");<br>&gt;<br>&gt;<br>&gt; Regards,<br>&gt; --<br>&gt; Agustín K-ballo Bergé<br>&gt; 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>