220 20639 <49724df9-5491-4466-bf18-818e14c9dda9@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: joewoodbury@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Null -conditional and -coalescing operators
Date: Tue, 22 Sep 2015 11:41:49 -0700 (PDT)
Lines: 149
Approved: news@gmane.org
Message-ID: <49724df9-5491-4466-bf18-818e14c9dda9@isocpp.org>
References: <4c3e2ee7-2159-4e93-a439-7d5c94c38c9c@isocpp.org>
 <mts3m8$22s$1@ger.gmane.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_6_1670467107.1442947309489"
X-Trace: ger.gmane.org 1442947314 2676 80.91.229.3 (22 Sep 2015 18:41:54 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 22 Sep 2015 18:41:54 +0000 (UTC)
Cc: mwoehlke.floss@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCBMHLUN7EEBB3WBQ2YAKGQESROCBDY@isocpp.org Tue Sep 22 20:41:54 2015
Return-path: <std-proposals+bncBCBMHLUN7EEBB3WBQ2YAKGQESROCBDY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f199.google.com ([209.85.213.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCBMHLUN7EEBB3WBQ2YAKGQESROCBDY@isocpp.org>)
	id 1ZeSVl-0007ko-92
	for gclcip-std-proposals@m.gmane.org; Tue, 22 Sep 2015 20:41:53 +0200
Original-Received: by igbbp9 with SMTP id bp9sf44470081igb.3
        for <gclcip-std-proposals@m.gmane.org>; Tue, 22 Sep 2015 11:41:52 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:content-type:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=If5kYgr/n4OjNnrro2JQtZFLronVy4NVF7qV5wSLI+I=;
        b=jusiu9pHtkX3PsZL6QCULu283ixquVVKVc/zbKOFLt7wxmtaQCiKbPrwoJ02Zwwcc4
         BckXmh3FfMrE0LP6Ifa+yaMlEY7U/vZQ7jyjgMOYXsTcJFbFov4YOa4u8GrGUDY2WVaD
         ysAQryu0zG8F9SIf86Ra1+PhL2hRCUmOu8t/T4w5ThSTltFXs40SOUs126A5HOj41lxQ
         6L+dDs4pAI0Kub0ewbLx7Bj6W6YFftQtG6Z50/VFjOhoneINrblPkl/1bhU8vK0GKZKj
         x7GOL9Ol3U193Q8P9AsiWVegrJRRRKpAALxa1GLSJdfsMjlU+fdBIw0nLCtZB01NU9tc
         9Ldg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:content-type:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=If5kYgr/n4OjNnrro2JQtZFLronVy4NVF7qV5wSLI+I=;
        b=YTRCJcGdKVUvqNjIYBwsrGZE/NjTN5vIZQ2VrfO5zjQVjg/MX+9FFgkAHSMiEcIC2l
         jyWC6fdXKeza6Sz7bOcvNZLXDyOUR0ny2lHsceFtj2uDL1VMZ9nnAVFHEYYmueUwKIam
         QoEeb13Zyuwqf8EKB9BAd8yDfNPpNz2OOTXm+5msY0q+qNRe50NFIhP8HlKexVnhBW7j
         UzweoiGboXsI5ZmvoR4+MuazfBhubo+RK626gfLK+Zgai9Mul/kMzTe2PAEzTlPvYE0g
         hD+amhcs2XOzuL35WaNRAcUh5/hzjPgjEH1VL+dWcc3HdHrqqO1xGx/NSBCBL48YwBvP
         s3lg==
X-Gm-Message-State: ALoCoQmpTjAzq1L1eE7J4pgsIBUgTy76qTm3qjfFqJ4NY5e98F3ZCJzhYEF51dyNNPP6yEQ7EKfl
X-Received: by 10.182.149.168 with SMTP id ub8mr22493382obb.30.1442947312056;
        Tue, 22 Sep 2015 11:41:52 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.62.4 with SMTP id u4ls239894igr.21.gmail; Tue, 22 Sep 2015
 11:41:50 -0700 (PDT)
X-Received: by 10.50.147.100 with SMTP id tj4mr215290igb.2.1442947310202;
        Tue, 22 Sep 2015 11:41:50 -0700 (PDT)
In-Reply-To: <mts3m8$22s$1@ger.gmane.org>
X-Original-Sender: joewoodbury@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: <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: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:20639
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20639>

------=_Part_6_1670467107.1442947309489
Content-Type: multipart/alternative; 
	boundary="----=_Part_7_1948381328.1442947309489"

------=_Part_7_1948381328.1442947309489
Content-Type: text/plain; charset=UTF-8

My mistake. I had collapsed several examples in order to keep my message 
short and in the process created a bogus example. I apologize.

I had been considering a recent bug where a reference had "contained" a 
nullptr (not in my code!) and wondered if this could be a solution.

I was thinking of another spot of code where an overloaded operator is 
returning either a nullptr or valid pointer. If the former, it assigns 
another value to lvalue.



On Tuesday, September 22, 2015 at 10:38:35 AM UTC-7, Matthew Woehlke wrote:
>
> On 2015-09-22 13:03, joewo...@gmail.com <javascript:> wrote: 
> > Checking for null and then doing one thing is a common task. 
> > 
> >     bool success = connection ?: false; 
>
> That makes no sense; you are assigning the value 'false' to 'success' if 
> 'connection' "is true", but what if it is false? Then what? Nor does it 
> make sense for the declaration to be conditional. 
>
> Rather, you would need to write something like: 
>
>   bool success = connection ? false : true; 
>
> ...which you can do already. Or just use the converted value directly, 
> as Nicol notes. 
>
> >     connection?->SendMessage(msg); 
>
> I think the syntax ought to be more like: 
>
>   ?(connection)->SendMessage(msg); 
>
> ...where '?(expr)' says to evaluate the truth-value of 'expr' and, if 
> true, "return" 'expr', otherwise skip the statement. (I'd avoid 'expr?' 
> as it seems likely to make parsing that vs. 'expr?expr:expr' difficult. 
> Plus, one would expect 'expr?expr' to act more like the trinary, just 
> without the ':expr' part, and not "reuse" the LHS expression.) 
>
> You could also write things like: 
>
>   x = ?(y); // if (y) x = y; 
>
> However, this is a very unusual construct for questionable gain. 
>
> -- 
> Matthew 
>
>

-- 

--- 
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/.

------=_Part_7_1948381328.1442947309489
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">My mistake. I had collapsed several examples in order to k=
eep my message short and in the process created a bogus example. I apologiz=
e.<br><br>I had been considering a recent bug where a reference had &quot;c=
ontained&quot; a nullptr (not in my code!) and wondered if this could be a =
solution.<br><br>I was thinking of another spot of code where an overloaded=
 operator is returning either a nullptr or valid pointer. If the former, it=
 assigns another value to lvalue.<br><br><br><br>On Tuesday, September 22, =
2015 at 10:38:35 AM UTC-7, Matthew Woehlke wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;">On 2015-09-22 13:03, <a href=3D"javascript:" target=3D"_=
blank" gdf-obfuscated-mailto=3D"rToj9SAZBgAJ" rel=3D"nofollow" onmousedown=
=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D=
&#39;javascript:&#39;;return true;">joewo...@gmail.com</a> wrote:
<br>&gt; Checking for null and then doing one thing is a common task.=20
<br>&gt;=20
<br>&gt; =C2=A0 =C2=A0 bool success =3D connection ?: false;
<br>
<br>That makes no sense; you are assigning the value &#39;false&#39; to &#3=
9;success&#39; if
<br>&#39;connection&#39; &quot;is true&quot;, but what if it is false? Then=
 what? Nor does it
<br>make sense for the declaration to be conditional.
<br>
<br>Rather, you would need to write something like:
<br>
<br>=C2=A0 bool success =3D connection ? false : true;
<br>
<br>...which you can do already. Or just use the converted value directly,
<br>as Nicol notes.
<br>
<br>&gt; =C2=A0 =C2=A0 connection?-&gt;SendMessage(msg);
<br>
<br>I think the syntax ought to be more like:
<br>
<br>=C2=A0 ?(connection)-&gt;SendMessage(<wbr>msg);
<br>
<br>...where &#39;?(expr)&#39; says to evaluate the truth-value of &#39;exp=
r&#39; and, if
<br>true, &quot;return&quot; &#39;expr&#39;, otherwise skip the statement. =
(I&#39;d avoid &#39;expr?&#39;
<br>as it seems likely to make parsing that vs. &#39;expr?expr:expr&#39; di=
fficult.
<br>Plus, one would expect &#39;expr?expr&#39; to act more like the trinary=
, just
<br>without the &#39;:expr&#39; part, and not &quot;reuse&quot; the LHS exp=
ression.)
<br>
<br>You could also write things like:
<br>
<br>=C2=A0 x =3D ?(y); // if (y) x =3D y;
<br>
<br>However, this is a very unusual construct for questionable gain.
<br>
<br>--=20
<br>Matthew
<br>
<br></blockquote></div>

<p></p>

-- <br />
<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+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 />
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 />

------=_Part_7_1948381328.1442947309489--
------=_Part_6_1670467107.1442947309489--

.
