220 20678 <d871b34e-cb96-4826-b52f-72fa0fdb104e@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 17:34:20 -0700 (PDT)
Lines: 115
Approved: news@gmane.org
Message-ID: <d871b34e-cb96-4826-b52f-72fa0fdb104e@isocpp.org>
References: <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_665_1464794827.1442968460559"
X-Trace: ger.gmane.org 1442968465 32241 80.91.229.3 (23 Sep 2015 00:34:25 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 23 Sep 2015 00:34:25 +0000 (UTC)
Cc: joewoodbury@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCBMHLUN7EEBBDPHQ6YAKGQEHQZYUXA@isocpp.org Wed Sep 23 02:34:25 2015
Return-path: <std-proposals+bncBCBMHLUN7EEBBDPHQ6YAKGQEHQZYUXA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qg0-f69.google.com ([209.85.192.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCBMHLUN7EEBBDPHQ6YAKGQEHQZYUXA@isocpp.org>)
	id 1ZeY0u-0000kd-Ow
	for gclcip-std-proposals@m.gmane.org; Wed, 23 Sep 2015 02:34:24 +0200
Original-Received: by qgev79 with SMTP id v79sf9560971qge.0
        for <gclcip-std-proposals@m.gmane.org>; Tue, 22 Sep 2015 17:34:23 -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=Ze6UPu7Zl7ER+Fs09Tnj2YthKh4sbe93Cc+BqKp/fIQ=;
        b=XUMXNykYvR74a3VCSrFCyFe9augqnn8alQwNTV/DWSJ7krH41PXPVWBhpHN5xuLzMs
         /80BYjuE+uooy1a2mQyDllFCtSKT8yYdc0Bm3XG8ZyFaMrePO5TBsiQb9RBeRtU3g1e9
         Qbjd9SWcnCtXh2hukD1IfUer1FIjJ5d0KZYVT0zs8vI3BqBvmqCDa5aAXGZYSKfjdWz4
         ZC16ETvxb0h83RTzmn1vdTaCMn6nf7yImn9AVGa435I8XD/rlpsLcSpOHiG9Fm1/84f0
         7BCXmtwVncLBjzP7Rfyc2g73HrytBO9Z9f9Rsg+d9qb8CxeG/t34CtfIjVGfUZbGFVl0
         Ji1Q==
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=Ze6UPu7Zl7ER+Fs09Tnj2YthKh4sbe93Cc+BqKp/fIQ=;
        b=fmcPRVcFlAwyVMbGw3ZaSE5jzHvghx+9bOVNfqUITNQ6LriUfsIxiGqac3/TpEm+3S
         XYbcmBsFtJag6qNsZ0scXIdZ+XRtm0eCHeSgNkwh6kYMN6ZrOtzub7gP/B47l4Fw4fX5
         cUGwKUUsjrBUIos5wT9uuSs8lsDQD6QCyf3xg7mN4crKmHFcDdXoQq6kVjxy3eFoDxIi
         NN/VACuG7Zd8VD1RDax+/bd8cmNKB9gsLiN20eBzNtbs2Dh0XazN9JApVxz5dyN8uSU3
         nc6Ugibt645oVkNH6quxyeTrlrsQ6zLWNhv6qvLCzmEzCgwlp7OeiZTmlRDJK10uPzLs
         kYGQ==
X-Gm-Message-State: ALoCoQkIAwPgY50iaw2LcDkouH+36FVyqewewVjzrLQpg6eKQ6GGk/fJuXQPQkOjNhzE9YUseXNb
X-Received: by 10.13.202.195 with SMTP id m186mr25882851ywd.55.1442968463628;
        Tue, 22 Sep 2015 17:34:23 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.41.8 with SMTP id b8ls297631igl.9.canary; Tue, 22 Sep 2015
 17:34:21 -0700 (PDT)
X-Received: by 10.50.143.5 with SMTP id sa5mr8103igb.1.1442968461584;
        Tue, 22 Sep 2015 17:34:21 -0700 (PDT)
In-Reply-To: <4c3e2ee7-2159-4e93-a439-7d5c94c38c9c@isocpp.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:20678
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20678>

------=_Part_665_1464794827.1442968460559
Content-Type: multipart/alternative; 
	boundary="----=_Part_666_883898929.1442968460560"

------=_Part_666_883898929.1442968460560
Content-Type: text/plain; charset=UTF-8

Here in interesting example I just encountered:

strLen is passed into a function along with pStr. After nullptr checks, the 
following is done:

            size_t tmpStrLen = wcslen(pStr);
            if (strLen > tmpStrLen)
                strLen = tmpStrLen;

Using the ?: operator, you could do:

            strLen = wcslen(pStr) < strLen ?: strLen;

Again, a trivial example, but one in actual code.



On Tuesday, September 22, 2015 at 10:03:47 AM UTC-7, joewo...@gmail.com 
wrote:
>
> 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_666_883898929.1442968460560
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Here in interesting example I just encountered:<br><br>str=
Len is passed into a function along with pStr. After nullptr checks, the fo=
llowing is done:<br><br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 size_t tmpStrLen =3D wcslen(pStr);<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (strLen &gt; tmpStrLen)<br>=C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 strLen =3D tmp=
StrLen;<br><br>Using the ?: operator, you could do:<br><br>=C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 strLen =3D wcslen(pStr) &lt; strL=
en ?: strLen;<br><br>Again, a trivial example, but one in actual code.<br><=
br><br><br>On Tuesday, September 22, 2015 at 10:03:47 AM UTC-7, joewo...@gm=
ail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>Checking for null and then doing one thing is a common task. null-conditio=
nal and null-coalescing operators would be a nice solution.<br><br>For exam=
ple, given the following pointer:<br><br>=C2=A0=C2=A0=C2=A0 unique_ptr&lt;C=
onnection&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 ni=
ce alternative would be:<br><br>=C2=A0=C2=A0=C2=A0 connection ?: connection=
-&gt;SendMessage(msg);<br><br>I&#39;ve had situations where if anything res=
olves 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;Se=
ndMessage(msg);<br><br>Likewise:<br><br>=C2=A0=C2=A0=C2=A0 bool success =3D=
 connection ?: false;<br><br><br></div></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_666_883898929.1442968460560--
------=_Part_665_1464794827.1442968460559--

.
