220 20623 <4c3e2ee7-2159-4e93-a439-7d5c94c38c9c@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: joewoodbury@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Null -conditional and -coalescing operators
Date: Tue, 22 Sep 2015 10:03:47 -0700 (PDT)
Lines: 81
Approved: news@gmane.org
Message-ID: <4c3e2ee7-2159-4e93-a439-7d5c94c38c9c@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3284_1043426421.1442941427135"
X-Trace: ger.gmane.org 1442941431 2242 80.91.229.3 (22 Sep 2015 17:03:51 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 22 Sep 2015 17:03:51 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCBMHLUN7EEBB5ETQ2YAKGQET7DSHFA@isocpp.org Tue Sep 22 19:03:51 2015
Return-path: <std-proposals+bncBCBMHLUN7EEBB5ETQ2YAKGQET7DSHFA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f198.google.com ([209.85.220.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCBMHLUN7EEBB5ETQ2YAKGQET7DSHFA@isocpp.org>)
	id 1ZeQyr-0006sm-Tl
	for gclcip-std-proposals@m.gmane.org; Tue, 22 Sep 2015 19:03:50 +0200
Original-Received: by qkey1 with SMTP id y1sf19416623qke.0
        for <gclcip-std-proposals@m.gmane.org>; Tue, 22 Sep 2015 10:03:48 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id: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=WS79kbuHmeT4hjzsIrt9MdrDPDxmVQGCacGw8URBLPA=;
        b=gQjJTllNFlM/h2sTbhiDtkqt5s1VE3zQM8VUEoVBwDOe4i+2O9pZ/K9g8XPR/jaO2O
         KMBIbBmtaasK2zgiXAnW9xCSBhj7jEm8Yi3NUPHal9TQp+xiB7Qw0eqrcho4QJ2pIlAn
         6vWjVgsiGBm/WGdsmr6CIBl2Prng1PU2YFE/rWgOvnFX20MrhpeQoObhreU3+9sVZRtB
         Qhhy1kYKKd1NlxMek4DB+HbF7YRP2IC8Ai9zxdAiqaX58gi+L0OtRegfaqaV7wSu+AOm
         QDt7NGSnagmRsAp+miWvsBK49C7OGMSgk1jmP/CYG1TQ40JoOa4tKa20W/hanhVtmPs2
         o3NQ==
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:message-id: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=WS79kbuHmeT4hjzsIrt9MdrDPDxmVQGCacGw8URBLPA=;
        b=AT5zrafbN1YzUo7uc7PbubfcDP7yvyiZRFcHBdjTM9vkzMe16wl9vxAnU/Jo5js4ZJ
         PLhLEtt3bg3sksOBSOklQMbSLNdsZ/OTL2uJWw7kniEj03q73dJaiFrzKPmNYPT/oSbb
         ZzYDqTXK0P/QkYxIaW1xumoNPis7JcTICPzLxG71PE4A+eYThA6zbASZYKEM3kX07M79
         wO3NCnUI4aRjWJLBwbNcPnuJcBmgSiXxcyk/PqZccG5B+sHBnvR485Rhh/xn0uX1Oog7
         fvkPxkeouLeauR4fWcC/gRbuxnvdIl7rxU6sHDcSFF/+aEeT/nucDdmJcsIfYrU8rGSv
         YHRQ==
X-Gm-Message-State: ALoCoQloCdjFswuopdNVr6HnuhzvmdPZF7tO04me8LO633WrEjrQcbral/y7+cMK4ClHlJ/Vm6ne
X-Received: by 10.129.40.83 with SMTP id o80mr22069699ywo.27.1442941428831;
        Tue, 22 Sep 2015 10:03:48 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.132.164 with SMTP id o36ls203997ioi.64.gmail; Tue, 22 Sep
 2015 10:03:47 -0700 (PDT)
X-Received: by 10.50.79.136 with SMTP id j8mr204573igx.16.1442941427925;
        Tue, 22 Sep 2015 10:03:47 -0700 (PDT)
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:20623
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20623>

------=_Part_3284_1043426421.1442941427135
Content-Type: multipart/alternative; 
	boundary="----=_Part_3285_434060113.1442941427135"

------=_Part_3285_434060113.1442941427135
Content-Type: text/plain; charset=UTF-8

Checking for null and then doing one thing is a common task. 
null-conditional and null-coalescing operators would be a nice solution.

For example, given the following pointer:

    unique_ptr<Connection> connection;

This may happen:

    if (connection)
    {
        connection->sendMessage(msg);
    }

A nice alternative would be:

    connection ?: connection->SendMessage(msg);

I've had situations where if anything resolves to false on the left, this 
?: would be useful.

Or even better, to carry the concept forward:

    connection?->SendMessage(msg);

Likewise:

    bool success = connection ?: false;


-- 

--- 
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_3285_434060113.1442941427135
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Checking for null and then doing one thing is a common tas=
k. null-conditional and null-coalescing operators would be a nice solution.=
<br><br>For example, given the following pointer:<br><br>=C2=A0=C2=A0=C2=A0=
 unique_ptr&lt;Connection&gt; connection;<br><br>This may happen:<br><br>=
=C2=A0=C2=A0=C2=A0 if (connection)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 connection-&gt;sendMessage(msg);<br>=C2=A0=C2=A0=
=C2=A0 }<br><br>A nice alternative would be:<br><br>=C2=A0=C2=A0=C2=A0 conn=
ection ?: connection-&gt;SendMessage(msg);<br><br>I&#39;ve had situations w=
here if anything resolves to false on the left, this ?: would be useful.<br=
><br>Or even better, to carry the concept forward:<br><br>=C2=A0=C2=A0=C2=
=A0 connection?-&gt;SendMessage(msg);<br><br>Likewise:<br><br>=C2=A0=C2=A0=
=C2=A0 bool success =3D connection ?: false;<br><br><br></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_3285_434060113.1442941427135--
------=_Part_3284_1043426421.1442941427135--

.
