220 37290 <CAANG=kUmThSamFisncxMCaqFd6Ze7GWH-q+TjMn4YfFTn2T8+w@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 09:02:16 +0000
Lines: 203
Approved: news@gmane.org
Message-ID: <CAANG=kUmThSamFisncxMCaqFd6Ze7GWH-q+TjMn4YfFTn2T8+w@mail.gmail.com>
References: <1fea07df-46a6-4df2-865a-849be8f8d129@isocpp.org> <CAANG=kVsGNaXGZLtbNm=9cJxjLXwu0cgL=p_kYa1TCRSKfNCvg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="0000000000006fca9705671f4913"
X-Trace: blaine.gmane.org 1520758867 21960 195.159.176.226 (11 Mar 2018 09:01:07 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 11 Mar 2018 09:01:07 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDRYVJ6TVYBRBLXBSPKQKGQEJYJEJXY@isocpp.org Sun Mar 11 10:01:03 2018
Return-path: <std-proposals+bncBDRYVJ6TVYBRBLXBSPKQKGQEJYJEJXY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f71.google.com ([74.125.83.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDRYVJ6TVYBRBLXBSPKQKGQEJYJEJXY@isocpp.org>)
	id 1euwqe-0005P5-KN
	for gclcip-std-proposals@m.gmane.org; Sun, 11 Mar 2018 10:00:56 +0100
Original-Received: by mail-pg0-f71.google.com with SMTP id e19sf321337pga.1
        for <gclcip-std-proposals@m.gmane.org>; Sun, 11 Mar 2018 01:03:03 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1520758983; cv=pass;
        d=google.com; s=arc-20160816;
        b=K2eQT7JHpxWTon0LSx6ryoGaZZON+WdGRxnf1lcrqZmrzFbfGt+yyDTN4OiqAUM7gK
         9ndHGJx1jNQQiuFHSWQ9aPvOtWRAup9rKDJRT49bmxkA5nrrnQRWUigRxdLQUkfywYCl
         uREM1cuT5nOXLbJK+i8oAqq9u3v3hLd1Z+eZfZ5PusjFOyNr/vGauhaE5ZKlttKWq9S7
         9Gg2yK4Oa3kCB2xdjpgPJNoM1kLqGRNrHo7tfud8MSDdPMMpl6Bn3mNVNRJyg9mrSLDX
         Qw2WEsoh06Qerpi2FYe55rDRiaUR4DfQ0OudyQYf2/IAgd+Ce4xVN1/ShfRau/zvGlyx
         mn/g==
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=oiaUtu5LfDQUqVb0UMNdXMdTN5OH++c49Rid7gkaLro=;
        b=DoqMsKfOiDB8eLVckOAPWCT1zNnbTtrpYXwt6zTXF0sr3oYdVCB7HEgNuiOjebjGIK
         sLuOrlo4S7ptdZglbO4t1JUAQ353a4m/aKT0foN1sheTh2W9orOxekMK8rze3qyIocWJ
         o7jxr6S7auo5kVQ/CzSM1PJvzyw37z2RAnpo7TMAbt0bbjq05Ec/gVhg7/JCrFpop3hQ
         Rmk60G6pxMV8NMXxySA3iJiGvjUDGGkf90YS0BWt7n9ercmmp5kBiPldTXeFP6zd6ofA
         J6/wgX/YDDVRh33QJWUYeTPxr4vcSUOHH2why9jceChNl5UDPq0E02+OOPG0HuUn0yLj
         P4cA==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZTupg8rY;
       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=oiaUtu5LfDQUqVb0UMNdXMdTN5OH++c49Rid7gkaLro=;
        b=DLHGRHjH65/yq8pc8E3v5fOwIESDFL6gSK3qb4xJM2imN6UK2wsfKErTxZkX+y3Lu4
         XD9d4CEvbEwLtm2tabA/VP1iwtysOTA+CxGIOY9eExqD0sQuAkBRThMOKL7mz7v+1s+7
         d4Aeq0N7d+67tYE1AnCzoCcGj648lXMLsiRJ7xlPcXh7STTxgeagjvMKsf8uAXdzLHa6
         vs6HDpHTty6gMjO48bcTSQgs7ahFi8H0TYUUtNEUkhPorxF30Q0jxkGqgE8ygkmVBjZC
         bUAIN0HAfAV6KN8D4VC5DDDcKPvjBwXC/G5Vx1DzJslC3KZj5bt+RjEN0Iq24UOsR2yY
         yk5A==
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=oiaUtu5LfDQUqVb0UMNdXMdTN5OH++c49Rid7gkaLro=;
        b=sglBTA7tutyNI2CErlmKJo16JmE5LJ+nRLVRmX3WR9csNdEMVKHNVVE3nTAoX+5Wdg
         dg49E1A77NoMCH2GBOH7NG+YnCJhDBQcIp8aoz/XRQ0t1goWVvH/3gqBTGOqjI7xbllR
         csk/cT0KKwQUSYxmqhRGGJOItwiEHM5Y4kvxwkfG6HwroG1PPLAwum1rFjO8BjpSRCrS
         6DKeYnS6tynNOBEVsIBFRu1oEzJWxSF82L0L0O/Rn5lc1SssYbCBqoSfGwab+t6qz13U
         19nsnJx+EAofz+IeOXMmlo5xtFpymh0OA9R4BM2QbXH6gPonbk6z6s7pp4lnWIzZo3D7
         lqQg==
X-Gm-Message-State: AElRT7GE6yk5mnQ5jvhXmZ+eZ8B7i8hNof3ou3gbqe/IwDn0YTPHWdz5
	z1KBGs9ZkfugSlWGBkoYVGbNew==
X-Google-Smtp-Source: AG47ELuqmhY/VveM93ZjQUJnGH/UIwUEJHpv3vTUbJc0ZASDiia9TKWAlpRjNyGFaJo+EuPnDvNSZA==
X-Received: by 2002:a17:902:854b:: with SMTP id d11-v6mr979454plo.47.1520758983078;
        Sun, 11 Mar 2018 01:03:03 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.101.96.6 with SMTP id m6ls2239108pgu.7.gmail; Sun, 11 Mar 2018
 01:02:37 -0800 (PST)
X-Received: by 10.99.160.67 with SMTP id u3mr814043pgn.389.1520758957660;
        Sun, 11 Mar 2018 01:02:37 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1520758957; cv=none;
        d=google.com; s=arc-20160816;
        b=I7sAHGn8+797lbbkEBedtCAgSjrtZLM3AkN2bfvQV7meEo5+ctowNpQKjC5GJHPe25
         wFVGI8afeX/uYEKK3CM3Rfu0dynMGP1XUM6n8LAUPtNuN7/3q6LO7083/eX0KBkbIQZB
         0sAtVieJ+gINIeQQUbIWSYpiYs6i5hZAGV61UZdn3Z6cvFy8pEXQjk+WzdaZGPLSVqwe
         SQGusO054PZEndwAMXHOWugfKdDpz19SDImeH/Gh4sDS3c9+HoterfXmULwzVQ5n3DXY
         YP8V4UWBcH3G1sqa35ChuqTQ4OXPoDsBMblah1hqMlVNSc+ySGidKILPeTafwXKiyosv
         wbWw==
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=OVuiYXoq0E4Ae6dKRIA7CJbTNnPFMjnIxTwlinT/KWs=;
        b=v6zMAgu3UmIEXHMU117Jg/l5Aocro3WhDJs4tj5wcaOYJ/ZDROHwp94o2gSV0t/Xbh
         wam55u1NUEfu4KxFJiq5Xm0Mgg7fOH66yFQNek/uOLWaIaujrdPoY3IwCJ9AwItAlPIn
         3gxLab/dR+UAVdvAGhO53vS982qEoiUn9e0S5+ERzwu/LLmwHLaO3p5+wuhzqJloMDT4
         14wjEy2cCSVVNie7P9I8FNc9CKyGXI04mWSFsywSK7GW8R2jGePE+qwCgwkzkTNBDPTr
         NwrAkx8nsoi+1ODEBvqTS7ctdmQ8tYNYYJV1F6tKC1yV4fhVKKwcXGTeDZZ6pXUPr7Zf
         Y5MQ==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZTupg8rY;
       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 a15-v6sor272574pll.46.2018.03.11.01.02.37
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Sun, 11 Mar 2018 01:02:37 -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 2002:a17:902:b582:: with SMTP id a2-v6mr4450414pls.353.1520758957262;
 Sun, 11 Mar 2018 01:02:37 -0800 (PST)
Original-Received: by 10.236.133.141 with HTTP; Sun, 11 Mar 2018 01:02:16 -0800 (PST)
In-Reply-To: <CAANG=kVsGNaXGZLtbNm=9cJxjLXwu0cgL=p_kYa1TCRSKfNCvg@mail.gmail.com>
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=ZTupg8rY;       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:37290
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37290>

--0000000000006fca9705671f4913
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

In my morning fog I forgot I needed to specify that it was the version of
assert where you only evaluate the message portion if the condition failed.
Not the standard assert.

On Sun, Mar 11, 2018 at 8:58 AM, Ga=C5=A1per A=C5=BEman <gasper.azman@gmail=
..com>
wrote:

> There is a binary form of the conditional operator that is a gnu extensio=
n:
>
> void foo(int *x) {
>   x =3D x?:new int;
> }
>
> It's defined as
>
> CEXPR ?: FEXPR;
>
> and rewritten into
>
> {
>    auto&& x =3D 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 easi=
er
> 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 =3D=3D nullptr) {
>>     x =3D 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 =3D x || new int;
>> }
>>
>> or even (ducks for cover)
>>
>> void foo(int *x) {
>>   x ||=3D new int;
>> }
>>
>> would be nice.
>>
>> Currently, if I am not mistaken, || (excluding user-defined overloads) i=
s
>> 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 pointe=
rs
>> 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-h=
and
>> one is false.  Then the whole point as I see it would be lost - the abov=
e
>> examples would merely leak memory.
>>
>> - Jefferson Carpenter
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> 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/is
>> ocpp.org/d/msgid/std-proposals/1fea07df-46a6-4df2-865a-
>> 849be8f8d129%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1fea07df-4=
6a6-4df2-865a-849be8f8d129%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>

--=20
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 e=
mail 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%3DkUmThSamFisncxMCaqFd6Ze7GWH-q%2BTjMn4YfF=
Tn2T8%2Bw%40mail.gmail.com.

--0000000000006fca9705671f4913
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">In my morning fog I forgot I needed to specify that it was=
 the version of assert where you only evaluate the message portion if the c=
ondition failed. Not the standard assert.</div><div class=3D"gmail_extra"><=
br><div class=3D"gmail_quote">On Sun, Mar 11, 2018 at 8:58 AM, Ga=C5=A1per =
A=C5=BEman <span dir=3D"ltr">&lt;<a href=3D"mailto:gasper.azman@gmail.com" =
target=3D"_blank">gasper.azman@gmail.com</a>&gt;</span> wrote:<br><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex"><div dir=3D"ltr"><div dir=3D"auto"><div>There is a bi=
nary form of the conditional operator that is a gnu extension:</div><div><b=
r></div><div>void foo(int *x) {</div><div>=C2=A0 x =3D x?:new int;</div><di=
v>}</div><div><br></div><div>It&#39;s defined as</div><div><br></div><div>C=
EXPR ?: FEXPR;</div><div><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) { return x; } else { return FEXPR; }</div><div>}</div><div=
><br></div><div>Perhaps you could propose that instead, as it&#39;s far mor=
e general. It&#39;s a GNU extension because certain macros (assert comes to=
 mind) are much easier to implement if you have it.</div><span class=3D"HOE=
nZb"><font color=3D"#888888"><div><br></div><div>G</div></font></span><div>=
<div class=3D"h5"><div><div dir=3D"auto"><br></div><div dir=3D"auto"><br></=
div><br><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Sun, Mar 11, 201=
8, 08:38  &lt;<a href=3D"mailto:jeffersoncarpenter2@gmail.com" target=3D"_b=
lank">jeffersoncarpenter2@gmail.com</a><wbr>&gt; wrote:<br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol=
id;padding-left:1ex"><div dir=3D"ltr">Not sure how this will be received --=
 I haven&#39;t posted here much.=C2=A0 Just thought it would be worth menti=
oning this idea.<br><br>Suppose you have an API that you want to optionally=
 allocate storage for your user.=C2=A0 They can either pass in a pointer to=
 some existing allocated space, or pass in a null pointer and space is allo=
cated for them.<br><br>void foo(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 p=
ointer overload.=C2=A0 Then you could write the more succinct<br><br>void f=
oo(int *x) {<br>=C2=A0 x =3D x || new int;<br>}<br><br>or even (ducks for c=
over)<br><br>void foo(int *x) {<br>=C2=A0 x ||=3D new int;<br>}<br><br>woul=
d be nice.<br><br>Currently, if I am not mistaken, || (excluding user-defin=
ed overloads) is a boolean-only operator.=C2=A0 It is indeed the case that =
nullptr is the only value that becomes false when cast to a boolean, and al=
l other pointer values become true.=C2=A0 So I don&#39;t see how adding an =
|| overload for pointers would break any existing code.<br><br>The main thi=
ng that would make this a no-go would be if the semantics of || required th=
at both operands be evaluated -- whether or not the left-hand one is false.=
=C2=A0 Then the whole point as 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@isoc<wbr>pp.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/is<wbr>ocpp.org/d/msgid/std-=
proposals<wbr>/1fea07df-46a6-4df2-865a-<wbr>849be8f8d129%40isocpp.org</a>.<=
br>
</blockquote></div></div></div></div></div></div>
</blockquote></div><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">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%3DkUmThSamFisncxMCaqFd6Ze7GWH-q=
%2BTjMn4YfFTn2T8%2Bw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAANG%3DkUm=
ThSamFisncxMCaqFd6Ze7GWH-q%2BTjMn4YfFTn2T8%2Bw%40mail.gmail.com</a>.<br />

--0000000000006fca9705671f4913--

.
