220 37288 <CAANG=kVsGNaXGZLtbNm=9cJxjLXwu0cgL=p_kYa1TCRSKfNCvg@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: =?UTF-8?B?R2HFoXBlciBBxb5tYW4=?= <gasper.azman@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Pointer overload for ||
Date: Sun, 11 Mar 2018 08:58:46 +0000
Lines: 170
Approved: news@gmane.org
Message-ID: <CAANG=kVsGNaXGZLtbNm=9cJxjLXwu0cgL=p_kYa1TCRSKfNCvg@mail.gmail.com>
References: <1fea07df-46a6-4df2-865a-849be8f8d129@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="94eb2c11d754e1238605671f3c11"
X-Trace: blaine.gmane.org 1520758626 3715 195.159.176.226 (11 Mar 2018 08:57:06 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 11 Mar 2018 08:57:06 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDRYVJ6TVYBRBW67SPKQKGQEIJIWVCY@isocpp.org Sun Mar 11 09:57:02 2018
Return-path: <std-proposals+bncBDRYVJ6TVYBRBW67SPKQKGQEIJIWVCY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f198.google.com ([209.85.192.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDRYVJ6TVYBRBW67SPKQKGQEIJIWVCY@isocpp.org>)
	id 1euwms-0000qm-0z
	for gclcip-std-proposals@m.gmane.org; Sun, 11 Mar 2018 09:57:02 +0100
Original-Received: by mail-pf0-f198.google.com with SMTP id x7sf4001550pfd.19
        for <gclcip-std-proposals@m.gmane.org>; Sun, 11 Mar 2018 00:59:09 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1520758748; cv=pass;
        d=google.com; s=arc-20160816;
        b=B8vdqV9FfunajOeDLRnodiB/5LfdWMBzo0cMOkm93AcuvIDhhpzxDxTerucutuomhE
         jlw4yM97QfCm0+MGt46bw0a40d1ArsUAJXkcYjBYhFYTgci+w1DHxdn+Q04Acx8TfE97
         91xzjOVNtADwtUPRgceJPvlDO9gqeQGlfglg9+DU+ej/c8lGOXJnIPCLX82DaZltq4o1
         iFfxayup2cbimjrz8iJ9OS9NGXXy/i9tpVaiTlXHD8+zVINncyrWwEzZ5P7BcxGXDMeS
         OWb6Nt8BJqwyI1HYNhX86IsbTLizIMs6iwoRkTqKj7t+NipKz+lOEHKLejkVK0SMSleX
         /jUQ==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date
         :from:references:in-reply-to:mime-version:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=i8+WAGK29lVqgOeFbEbNCwcLy5IfYrSvwXQbUZVLAvg=;
        b=c4omdRCznJ3uQIE4TzN+ScJ/201/SaT9jCwSYua+AqPxrPGDupIaiacH8NaHizpWAc
         mLMyuEgxh57DxDRaohAmt6sai0Abs7U0GXZ6ZpgfqvOxhFgtMj5zEqiHMLO3puEPhMqx
         Fpp1ngBE1oPhjzObRyuU5CK4a3ja50TV7NxzBCKw53dEc/KIvEZTynVBcLEEtlSOhL8R
         tI5mZ+gayyUIGMcw0c6gx4WczuoLQkcV7yVop//aKCPmYz/bi+voVKuGVtuy9ARIIWsc
         hB5yv8UZicOu+RzuZAbY3izCwG11Em1h5vSj9Gcc5oP33o8XVyhgkKfynarT2mqOQIMx
         gZLQ==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=XpBxEq7f;
       spf=pass (google.com: domain of gasper.azman@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=gasper.azman@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=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;
        bh=i8+WAGK29lVqgOeFbEbNCwcLy5IfYrSvwXQbUZVLAvg=;
        b=0W1odMVMZx1JvVi8C90gd+lv3yFU7+nqcQxDLiqte10/pTZCwLJSFS19/FPxHFVDy/
         Me2VExBmiTelDkp3kJ0UzQRu8ByncN8Ei58ZKY/iRwNYaYo9Ai7CCyRBlD424CIkoAfV
         9UUOXoNQaJTyrOeL5oZSognwugcbG8KjRUxh0ctDzMgvSPs13OWyKN+oQb8LsU9gzdnk
         lNu9XgAB0IzkUrZqVGhcmfWpQXlf61yB2B2lkqAeckexrUyGzle/DUb9e+FJVZQPjXo5
         jd9avZ+vOVyI+6/aMfj9VHSD9bjGV/xCVF5UunyaxEZyDdpKayQeQJTYhSJFPhBbYZtC
         MbEQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        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:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=i8+WAGK29lVqgOeFbEbNCwcLy5IfYrSvwXQbUZVLAvg=;
        b=JeBtwXmULL1DF0KCdFqJBzzjsqU2zhyRim6bY00cd4kuoYgbdhzJp0f1zeyIVC7TuX
         JsntOnAqlWbRmgMC4sLntffDem5NbWdauZl4MisQM1Yjgju45VOuB67636VKouRu66sc
         rcCGEekihrQfx58MkS69sz44BYPyMh4FG1z80QLxAmgQMPG3ta1BDDkx20lI6kZ25VTa
         E9TJ8nTzKcDah6tTgFIWDRM8qAxDjz/wlhOnoiJzGZZ6vu/VryfGh7e5IuYlNiur5Wtv
         8vLv9gf88vMQun7AsCEvW3PWlvL/Y+qvRLdMJKCaxuO5vm1VO3b3j7MDZKN/eJvEyenR
         g3kA==
X-Gm-Message-State: AElRT7GauFqZtrrl+XgBZWNo3xRjDrfuJxA/vg0Mua7CQbiEQpnAMhQr
	9cL9XmRRqux2hPXPaRDUamP+ig==
X-Google-Smtp-Source: AG47ELsaTXkd8giz5sNdcQRum/pEWsreG/H0Cx22or6UB2dS2igyU2X1RqduX21UAMIcm/yt2dyKEw==
X-Received: by 10.99.0.75 with SMTP id 72mr896671pga.84.1520758748633;
        Sun, 11 Mar 2018 00:59:08 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a17:902:aa03:: with SMTP id be3-v6ls4181736plb.2.gmail; Sun,
 11 Mar 2018 00:59:07 -0800 (PST)
X-Received: by 2002:a17:902:8f8f:: with SMTP id z15-v6mr4429674plo.315.1520758747213;
        Sun, 11 Mar 2018 00:59:07 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1520758747; cv=none;
        d=google.com; s=arc-20160816;
        b=pqBbBwcYxcO2U7wc6+qlirMmKOTXxrsprRQ3/ff4OcRGXVYg42GqeU1UIj6WBMUi9D
         XFWxZBDbQuTHZML1mxbTYQoajmuC/y+e5Ik93Yv0JgmdgKklN9LPuFD8iWtfxKwaFR4Y
         eyw7SOZsefoySdu0z4VoTlNI4fhsGqsuB/GCmqEuMGhcc6B1XR3MBIx7RYCAuZV8BJ9Z
         eAibLFHa7q+zrVRBKejKxHPEG7pYu9B0orIzLQBNkrKCxZeXjKQ6fM7bWexcOPJGU3mJ
         rv59z4xmMyKR1kPIs9QRSZTnfBdObjjlJmPBLkkfj1yCCdbqi5hnVInSNoOA6vVP9y42
         8nJQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:references:in-reply-to:mime-version
         :dkim-signature:arc-authentication-results;
        bh=fL0M9P4Pod2i9/92f/KC1UP8hqdo/Xms2kfVl2hTAPM=;
        b=hM9GOf/uUwNeZcPq9zNoRoB64JCj8RcNlqZwAtZEOzxmcSGCNERzcxHUwmRhoUdYmm
         9xBzmNB+8JHCRfvfkXrWqXmuXBm+C7usadAQ+HIIxIlGt7xUbbQyxbkrSqK1bHuiZL+0
         tYXMtqNmptxxovZhw7SKzZdTLfWzNC9akibO4TsaZbe2tqSvULfaFjKfQ6UFsKb+ctjh
         Db5pf7+hMCBtERAt7CDG811smT+QGk+INXsacgl88vDumadAVDEyofI9/RMKuM3ZNw9K
         LCcH8gpnZ9rCmE2C4w9bFXIECQxqz1Ce2zJ7CnD7MjLmryAudDJ3VbVnDZ7fykH2P4Hf
         sX0Q==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=XpBxEq7f;
       spf=pass (google.com: domain of gasper.azman@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=gasper.azman@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id j10sor1445776pfe.78.2018.03.11.00.59.07
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Sun, 11 Mar 2018 00:59:07 -0800 (PST)
Received-SPF: pass (google.com: domain of gasper.azman@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 10.98.196.84 with SMTP id y81mr4243629pff.11.1520758746586;
 Sun, 11 Mar 2018 00:59:06 -0800 (PST)
Original-Received: by 10.236.133.141 with HTTP; Sun, 11 Mar 2018 00:58:46 -0800 (PST)
In-Reply-To: <1fea07df-46a6-4df2-865a-849be8f8d129@isocpp.org>
X-Original-Sender: gasper.azman@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=XpBxEq7f;       spf=pass
 (google.com: domain of gasper.azman@gmail.com designates 209.85.220.41 as
 permitted sender) smtp.mailfrom=gasper.azman@gmail.com;       dmarc=pass
 (p=NONE sp=QUARANTINE 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-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:37288
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37288>

--94eb2c11d754e1238605671f3c11
Content-Type: text/plain; charset="UTF-8"

There is a binary form of the conditional operator that is a gnu extension:

void foo(int *x) {
  x = x?:new int;
}

It's defined as

CEXPR ?: FEXPR;

and rewritten into

{
   auto&& x = CEXPR;
   if (x) { return x; } else { return FEXPR; }
}

Perhaps you could propose that instead, as it's far more general. It's a
GNU extension because certain macros (assert comes to mind) are much easier
to implement if you have it.

G




On Sun, Mar 11, 2018, 08:38 <jeffersoncarpenter2@gmail.com> wrote:

> Not sure how this will be received -- I haven't posted here much.  Just
> thought it would be worth mentioning this idea.
>
> Suppose you have an API that you want to optionally allocate storage for
> your user.  They can either pass in a pointer to some existing allocated
> space, or pass in a null pointer and space is allocated for them.
>
> void foo(int *x) {
>   if (x == nullptr) {
>     x = new int;
>   }
>   // etc.
> }
>
> Just figured it would be a decent idea if the || operator received a
> pointer overload.  Then you could write the more succinct
>
> void foo(int *x) {
>   x = x || new int;
> }
>
> or even (ducks for cover)
>
> void foo(int *x) {
>   x ||= new int;
> }
>
> would be nice.
>
> Currently, if I am not mistaken, || (excluding user-defined overloads) is
> a boolean-only operator.  It is indeed the case that nullptr is the only
> value that becomes false when cast to a boolean, and all other pointer
> values become true.  So I don't see how adding an || overload for pointers
> would break any existing code.
>
> The main thing that would make this a no-go would be if the semantics of
> || required that both operands be evaluated -- whether or not the left-hand
> one is false.  Then the whole point as I see it would be lost - the above
> examples would merely leak memory.
>
> - Jefferson Carpenter
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/a/
> isocpp.org/d/msgid/std-proposals/1fea07df-46a6-4df2-
> 865a-849be8f8d129%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1fea07df-46a6-4df2-865a-849be8f8d129%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkVsGNaXGZLtbNm%3D9cJxjLXwu0cgL%3Dp_kYa1TCRSKfNCvg%40mail.gmail.com.

--94eb2c11d754e1238605671f3c11
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"auto"><div>There is a binary form of the condi=
tional operator that is a gnu extension:</div><div><br></div><div>void foo(=
int *x) {</div><div>=C2=A0 x =3D x?:new int;</div><div>}</div><div><br></di=
v><div>It&#39;s defined as</div><div><br></div><div>CEXPR ?: FEXPR;</div><d=
iv><br></div><div>and rewritten into</div><div><br></div><div>{</div><div>=
=C2=A0 =C2=A0auto&amp;&amp; x =3D CEXPR;</div><div>=C2=A0 =C2=A0if (x) { re=
turn x; } else { return FEXPR; }</div><div>}</div><div><br></div><div>Perha=
ps you could propose that instead, as it&#39;s far more general. It&#39;s a=
 GNU extension because certain macros (assert comes to mind) are much easie=
r to implement if you have it.</div><div><br></div><div>G</div><div><div di=
r=3D"auto"><br></div><div dir=3D"auto"><br></div><br><br><div class=3D"gmai=
l_quote"><div dir=3D"ltr">On Sun, Mar 11, 2018, 08:38  &lt;<a href=3D"mailt=
o:jeffersoncarpenter2@gmail.com" target=3D"_blank">jeffersoncarpenter2@gmai=
l.com</a><wbr>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr">Not sure how this will be received -- I haven&#39;t posted here mu=
ch.=C2=A0 Just thought it would be worth mentioning this idea.<br><br>Suppo=
se you have an API that you want to optionally allocate storage for your us=
er.=C2=A0 They can either pass in a pointer to some existing allocated spac=
e, or pass in a null pointer and space is allocated for them.<br><br>void f=
oo(int *x) {<br>=C2=A0 if (x =3D=3D nullptr) {<br>=C2=A0=C2=A0=C2=A0 x =3D =
new int;<br>=C2=A0 }<br>=C2=A0 // etc.<br>}<br><br>Just figured it would be=
 a decent idea if the || operator received a pointer overload.=C2=A0 Then y=
ou could write the more succinct<br><br>void foo(int *x) {<br>=C2=A0 x =3D =
x || new int;<br>}<br><br>or even (ducks for cover)<br><br>void foo(int *x)=
 {<br>=C2=A0 x ||=3D new int;<br>}<br><br>would be nice.<br><br>Currently, =
if I am not mistaken, || (excluding user-defined overloads) is a boolean-on=
ly operator.=C2=A0 It is indeed the case that nullptr is the only value tha=
t becomes false when cast to a boolean, and all other pointer values become=
 true.=C2=A0 So I don&#39;t see how adding an || overload for pointers woul=
d break any existing code.<br><br>The main thing that would make this a no-=
go would be if the semantics of || required that both operands be evaluated=
 -- whether or not the left-hand one is false.=C2=A0 Then the whole point a=
s I see it would be lost - the above examples would merely leak memory.<br>=
<br>- Jefferson Carpenter<br></div>

<p></p>

-- <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+unsubscribe@isocpp.org" rel=3D"nore=
ferrer" target=3D"_blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br=
>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" rel=3D"noreferrer" target=3D"_blank">std-proposals@isocpp.org</a>.<br=
>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1fea07df-46a6-4df2-865a-849be8f8d129%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" rel=3D"noreferrer"=
 target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-=
<wbr>proposals/1fea07df-46a6-4df2-<wbr>865a-849be8f8d129%40isocpp.org</a><w=
br>.<br>
</blockquote></div></div></div></div>

<p></p>

-- <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+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkVsGNaXGZLtbNm%3D9cJxjLXwu0cg=
L%3Dp_kYa1TCRSKfNCvg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkVs=
GNaXGZLtbNm%3D9cJxjLXwu0cgL%3Dp_kYa1TCRSKfNCvg%40mail.gmail.com</a>.<br />

--94eb2c11d754e1238605671f3c11--

.
