220 20759 <mu11oa$vmq$1@ger.gmane.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Null -conditional and -coalescing operators
Date: Thu, 24 Sep 2015 10:35:53 -0400
Lines: 68
Approved: news@gmane.org
Message-ID: <mu11oa$vmq$1@ger.gmane.org>
References: <4c3e2ee7-2159-4e93-a439-7d5c94c38c9c@isocpp.org> <CANPtknyyW8iV=ANeHpHvmZxS_mpxHPWcgEmCa4wLf+RugN2xDw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1443105380 32767 80.91.229.3 (24 Sep 2015 14:36:20 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 24 Sep 2015 14:36:20 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBVMUSCYAKGQEWFPZ4PQ@isocpp.org Thu Sep 24 16:36:13 2015
Return-path: <std-proposals+bncBC37LBFWUIFBBVMUSCYAKGQEWFPZ4PQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-la0-f72.google.com ([209.85.215.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBVMUSCYAKGQEWFPZ4PQ@isocpp.org>)
	id 1Zf7d6-0006T1-1z
	for gclcip-std-proposals@m.gmane.org; Thu, 24 Sep 2015 16:36:12 +0200
Original-Received: by laff1 with SMTP id f1sf23551400laf.2
        for <gclcip-std-proposals@m.gmane.org>; Thu, 24 Sep 2015 07:36:06 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:to:from:subject:date:lines:message-id:references
         :mime-version:content-type:user-agent:in-reply-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=7FdiDBWmQ8u4QAi1NFFZFE97QoXLg6UHNAJAFvnsqis=;
        b=Wc0DujFtTBsRnQOpK47aF9BFo9SC1FBVlpy3LpJL9tMXd5iOs9G5qq4qSJN6l0c4f7
         UgiJSCgLFI8JvrbCLkI8a7UXdNP/B9At91LFb/JA0meBY3gGzw7T6GVJiAXUjmlR0QDt
         62LKYHZ9GjpE9E9RvAOgJ4iOEdBEvSUonkpXYrWjGCWaLBAsIGZtKvlENxSIhUFXpMNj
         iGD0CKg1/6ghUShCwnIFsfhddhV2cYgzcQc4+SaLLkH1L3XjtMQ8IaI5hZuqdL4MeLem
         3jwDLjJE7MkkqTfalyZA6ro7EHxsiy4j4XgagxC+OkPFtEFj5PlAe/R61puRWAZKyGTL
         
X-Gm-Message-State: ALoCoQm04AnmfS6IwXStOPvGHjt97rAjRgv5TDfGecuj6qpxI3wdEqq+jC5EMtLX2THUA8tUYow4
X-Received: by 10.112.125.104 with SMTP id mp8mr5868lbb.20.1443105366241;
        Thu, 24 Sep 2015 07:36:06 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.2.193 with SMTP id 1ls129453law.30.gmail; Thu, 24 Sep 2015
 07:36:04 -0700 (PDT)
X-Received: by 10.152.18.167 with SMTP id x7mr3082lad.29.1443105364813;
        Thu, 24 Sep 2015 07:36:04 -0700 (PDT)
Original-Received: from plane.gmane.org (plane.gmane.org. [80.91.229.3])
        by mx.google.com with ESMTPS id jf12si6726085lac.98.2015.09.24.07.36.04
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Thu, 24 Sep 2015 07:36:04 -0700 (PDT)
Received-SPF: pass (google.com: domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as permitted sender) client-ip=80.91.229.3;
Original-Received: from list by plane.gmane.org with local (Exim 4.69)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1Zf7cx-0006OT-68
	for std-proposals@isocpp.org; Thu, 24 Sep 2015 16:36:03 +0200
Original-Received: from tripoint.kitware.com ([66.194.253.20])
        by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Thu, 24 Sep 2015 16:36:03 +0200
Original-Received: from mwoehlke.floss by tripoint.kitware.com with local (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Thu, 24 Sep 2015 16:36:03 +0200
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 59
Original-X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: tripoint.kitware.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
In-Reply-To: <CANPtknyyW8iV=ANeHpHvmZxS_mpxHPWcgEmCa4wLf+RugN2xDw@mail.gmail.com>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as
 permitted sender) smtp.mailfrom=gclcip-std-proposals@m.gmane.org;
       dmarc=fail (p=NONE 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: <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:20759
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20759>

On 2015-09-24 10:03, Peter Koch Larsen wrote:
> On 9/22/15, joewoodbury@gmail.com <joewoodbury@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 could just do
> connection && connection->SendMessage(msg);

....not if SendMessage returns void, you can't. You'd have to use:

  connection && (connection->SendMessage(msg), true);

....which is even worse than:

  if (connection) connection->SendMessage(msg);

Personally, I like my macro ;-).

  iff(connection)->SendMessage(msg);

Alas, it can't solve this case, however:

  written += ?(stream)->write(buffer);


(I'll note that part of the motivation here probably comes from wanting
to dodge draconian coding styles that mandate multiline braces around
ANY conditional body. Which, I'll be honest, I've done myself...
employed ugly hacks to dodge such, I mean; I personally loathe requiring
braces in single-statement conditional bodies.)

-- 
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/.

.
