220 9218 <CAPBZbvwheJnTOn46kf7O2EoGFXZtBBfHUBEB-U_QfjxEP3Bc_A@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: "Billy O'Neal" <billy.oneal@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Allowing overloadable operators to be
 implemented as non-member functions
Date: Sat, 8 Feb 2014 15:03:30 -0800
Lines: 163
Approved: news@gmane.org
Message-ID: <CAPBZbvwheJnTOn46kf7O2EoGFXZtBBfHUBEB-U_QfjxEP3Bc_A@mail.gmail.com>
References: <72c8d66b-9053-455d-8af4-96191d84b0cd@isocpp.org>
 <69a7690f-632f-4ac3-ad76-b56ac59d51f1@isocpp.org> <24fcdc41-d0e1-4641-acb8-e9533ff3ac88@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=089e015383e4d31c0504f1ed1f23
X-Trace: ger.gmane.org 1391900643 13582 80.91.229.3 (8 Feb 2014 23:04:03 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 8 Feb 2014 23:04:03 +0000 (UTC)
To: std-proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDKLBLVE6ADBB2XP3KLQKGQE4JWWBRI@isocpp.org Sun Feb 09 00:04:13 2014
Return-path: <std-proposals+bncBDKLBLVE6ADBB2XP3KLQKGQE4JWWBRI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vb0-f72.google.com ([209.85.212.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDKLBLVE6ADBB2XP3KLQKGQE4JWWBRI@isocpp.org>)
	id 1WCGwW-0002ZX-Ml
	for gclcip-std-proposals@m.gmane.org; Sun, 09 Feb 2014 00:04:12 +0100
Original-Received: by mail-vb0-f72.google.com with SMTP id w20sf11183136vbb.3
        for <gclcip-std-proposals@m.gmane.org>; Sat, 08 Feb 2014 15:04:11 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=67xRGx6R5mqhp21uoonxjGI/cWREgpRYGe6NcaPb3B8=;
        b=Tm5DsMi0G+QZ6DQV0Q9jM6T2MGCogimau9+HXKEsPe9MKShKgItorFO7YUGFQAJkOn
         x3IIhDXSSD6ARYBrLpUg2tMTmR3n/+4kdFpCJrERKZP1+r1i1DCLu9pgeW7mc48UX+Mv
         xa4pGXYOoUc4GPq1RATba6hA7ZPrbVXK9CaKtl6XB3YS+WWPKWm0VdUu/4YelbaorL1Y
         04/heLzK5TqXqx+zgHWYv5q8RiyIj7cAKX+p1Th7k3m1RYq+jwSMxItsFBsRw28TZqYz
         llU1uV4NvALG8L9jFVVcRpXzKaxUk2Eboqx1UtepZyI9wWFgy0FRTYYJvwodrtBoHO7O
         5+Ng==
X-Gm-Message-State: ALoCoQmSyjD4LL7zwCk27H7TSVWfRfFg3Ln6ewIzpZ1dCESqpgU7CaEZ9Sisvfb5f9HJlWlz6AbG
X-Received: by 10.236.19.36 with SMTP id m24mr7367786yhm.14.1391900651686;
        Sat, 08 Feb 2014 15:04:11 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.113.73 with SMTP id iw9ls580719obb.19.gmail; Sat, 08 Feb
 2014 15:04:10 -0800 (PST)
X-Received: by 10.182.28.7 with SMTP id x7mr3886480obg.43.1391900650530;
        Sat, 08 Feb 2014 15:04:10 -0800 (PST)
Original-Received: from mail-oa0-x232.google.com (mail-oa0-x232.google.com [2607:f8b0:4003:c02::232])
        by mx.google.com with ESMTPS id us4si5115813obc.148.2014.02.08.15.04.10
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sat, 08 Feb 2014 15:04:10 -0800 (PST)
Received-SPF: pass (google.com: domain of billy.oneal@gmail.com designates 2607:f8b0:4003:c02::232 as permitted sender) client-ip=2607:f8b0:4003:c02::232;
Original-Received: by mail-oa0-f50.google.com with SMTP id n16so5991033oag.9
        for <std-proposals@isocpp.org>; Sat, 08 Feb 2014 15:04:10 -0800 (PST)
X-Received: by 10.182.196.3 with SMTP id ii3mr19481872obc.11.1391900650312;
 Sat, 08 Feb 2014 15:04:10 -0800 (PST)
Original-Received: by 10.182.87.37 with HTTP; Sat, 8 Feb 2014 15:03:30 -0800 (PST)
In-Reply-To: <24fcdc41-d0e1-4641-acb8-e9533ff3ac88@isocpp.org>
X-Original-Sender: billy.oneal@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of billy.oneal@gmail.com designates 2607:f8b0:4003:c02::232 as
 permitted sender) smtp.mail=billy.oneal@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:9218
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/9218>

--089e015383e4d31c0504f1ed1f23
Content-Type: text/plain; charset=UTF-8

That would have different behavior than the standard conditional operator.
If the left argument can be converted to the right, and the right to the
left, with the same rank, then the program is ill formed.

Billy O'Neal
https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
http://stackoverflow.com/users/82320/billy-oneal


On Sat, Feb 8, 2014 at 2:35 PM, David Stone <deusexsophismata@gmail.com>wrote:

> The conditional operator is a bit trickier. I would also like to overload
> that operator, but the problem is that it has short-circuit evaluation.
> Unless it received special treatment, all arguments would always be
> evaluated once, and the recommendation would be "never overload it", much
> like operator&& and operator|| right now. My actual use case doesn't change
> what the operator means, just the type. Unfortunately, we defined
> std::common_type in terms of operator?:, not the other way around.
> operator?: only works in the case where one of the two possible results can
> be converted to the other, but in my use case, the common type of my
> numeric type is a numeric type that contains the range of both values. This
> has forced me to use the hideous implementation of a macro defined as
>
> ((condition) ? \
>     static_cast<std::common_type_t<decltype(lhs), decltype(rhs)>>(lhs) : \
>     static_cast<std::common_type_t<decltype(lhs), decltype(rhs)>>(rhs))
>
>
> Where std::common_type has been specialized for my integer type to return
> an integer that can hold values that either can hold.
>
> I don't know of a good answer to this problem. It would surprise people to
> write a function where the arguments are not always evaluated exactly once,
> but it would also surprise people to always evaluate both possible results.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--089e015383e4d31c0504f1ed1f23
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">That would have different behavior than the standard condi=
tional operator. If the left argument can be converted to the right, and th=
e right to the left, with the same rank, then the program is ill formed.</d=
iv>

<div class=3D"gmail_extra"><br clear=3D"all"><div><div dir=3D"ltr"><div>Bil=
ly O&#39;Neal</div><div><a href=3D"https://bitbucket.org/BillyONeal/" targe=
t=3D"_blank">https://github.com/BillyONeal/</a></div><div><a href=3D"http:/=
/stackoverflow.com/users/82320/billy-oneal" target=3D"_blank">http://stacko=
verflow.com/users/82320/billy-oneal</a></div>

</div></div>
<br><br><div class=3D"gmail_quote">On Sat, Feb 8, 2014 at 2:35 PM, David St=
one <span dir=3D"ltr">&lt;<a href=3D"mailto:deusexsophismata@gmail.com" tar=
get=3D"_blank">deusexsophismata@gmail.com</a>&gt;</span> wrote:<br><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc s=
olid;padding-left:1ex">

<div dir=3D"ltr">The conditional operator is a bit trickier. I would also l=
ike to overload that operator, but the problem is that it has short-circuit=
 evaluation. Unless it received special treatment, all arguments would alwa=
ys be evaluated once, and the recommendation would be &quot;never overload =
it&quot;, much like operator&amp;&amp; and operator|| right now. My actual =
use case doesn&#39;t change what the operator means, just the type. Unfortu=
nately, we defined std::common_type in terms of operator?:, not the other w=
ay around. operator?: only works in the case where one of the two possible =
results can be converted to the other, but in my use case, the common type =
of my numeric type is a numeric type that contains the range of both values=
.. This has forced me to use the hideous implementation of a macro defined a=
s<br>

<br><div style=3D"border:1px solid rgb(187,187,187);background-color:rgb(25=
0,250,250)"><code><div><span style=3D"color:rgb(102,102,0)">((</span><span>=
condition</span><span style=3D"color:rgb(102,102,0)">)</span><span> </span>=
<span style=3D"color:rgb(102,102,0)">?</span><span> </span><span style=3D"c=
olor:rgb(102,102,0)">\</span><span><br>

=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">static_cast</span><=
span style=3D"color:rgb(102,102,0)">&lt;</span><span>std</span><span style=
=3D"color:rgb(102,102,0)">::</span><span>common_type_t</span><span style=3D=
"color:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(0,0,136)">declty=
pe</span><span style=3D"color:rgb(102,102,0)">(</span><span>lhs</span><span=
 style=3D"color:rgb(102,102,0)">),</span><span> </span><span style=3D"color=
:rgb(0,0,136)">decltype</span><span style=3D"color:rgb(102,102,0)">(</span>=
<span>rhs</span><span style=3D"color:rgb(102,102,0)">)&gt;&gt;(</span><span=
>lhs</span><span style=3D"color:rgb(102,102,0)">)</span><span> </span><span=
 style=3D"color:rgb(102,102,0)">:</span><span> </span><span style=3D"color:=
rgb(102,102,0)">\</span><span><br>

=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">static_cast</span><=
span style=3D"color:rgb(102,102,0)">&lt;</span><span>std</span><span style=
=3D"color:rgb(102,102,0)">::</span><span>common_type_t</span><span style=3D=
"color:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(0,0,136)">declty=
pe</span><span style=3D"color:rgb(102,102,0)">(</span><span>lhs</span><span=
 style=3D"color:rgb(102,102,0)">),</span><span> </span><span style=3D"color=
:rgb(0,0,136)">decltype</span><span style=3D"color:rgb(102,102,0)">(</span>=
<span>rhs</span><span style=3D"color:rgb(102,102,0)">)&gt;&gt;(</span><span=
>rhs</span><span style=3D"color:rgb(102,102,0)">))</span><span><br>

<br></span></div></code></div><br>Where std::common_type has been specializ=
ed for my integer type to return an integer that can hold values that eithe=
r can hold.<br><br>I don&#39;t know of a good answer to this problem. It wo=
uld surprise people to write a function where the arguments are not always =
evaluated exactly once, but it would also surprise people to always evaluat=
e both possible results.<br>

</div><div class=3D"HOEnZb"><div class=3D"h5">

<p></p>

-- <br>
=C2=A0<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--089e015383e4d31c0504f1ed1f23--

.
