220 20629 <mts3m8$22s$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: Tue, 22 Sep 2015 13:38:16 -0400
Lines: 45
Approved: news@gmane.org
Message-ID: <mts3m8$22s$1@ger.gmane.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: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1442943525 2776 80.91.229.3 (22 Sep 2015 17:38:45 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 22 Sep 2015 17:38:45 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBGVEQ2YAKGQE3BTC5TY@isocpp.org Tue Sep 22 19:38:36 2015
Return-path: <std-proposals+bncBC37LBFWUIFBBGVEQ2YAKGQE3BTC5TY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wi0-f199.google.com ([209.85.212.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBGVEQ2YAKGQE3BTC5TY@isocpp.org>)
	id 1ZeRWW-0008Lv-74
	for gclcip-std-proposals@m.gmane.org; Tue, 22 Sep 2015 19:38:36 +0200
Original-Received: by wisv5 with SMTP id v5sf11863382wis.0
        for <gclcip-std-proposals@m.gmane.org>; Tue, 22 Sep 2015 10:38:35 -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=2991eBBBg1UCXCsJxICDoVr1gRJ3BWxdelTH6RpKXK0=;
        b=RVkSChLRJl6ODEmdeUG8UVVzlUSMTzEkCTUxba6Gnhx6C9jhYvh0yI5ka3M4g9o0gV
         Pr9Al+MEW0IlfERiSs5ybLqY5wB3vI2ZZY1vbTOIEFvz5I82zOCzYjHf89X3iRun6mMn
         BBT9hzqf2lq7lbdo5jljh40JsjPaW+qxO4+b+g4sPbikZ16fyz264sc66aA/fbYTVIcH
         E+VHg1s3wi9MxYr9gBci85IqhfA87Kb0rIRptA5FF+elClDTA8vHLe4ABMpOa8xD+W+C
         CB/Cy6f717bbYwEBdXxQjiTwJ9EoIGE4oH+XkMgMetoa7a+UJfvNvujJtw872fXvpU+X
         
X-Gm-Message-State: ALoCoQmxkmvYF0/+jw0EmytDvPJdHWpF/cvH3TWarGNrgH3mkoN49YTUR7pA1fgeD8BnHttulDuR
X-Received: by 10.152.37.161 with SMTP id z1mr2966330laj.8.1442943515317;
        Tue, 22 Sep 2015 10:38:35 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.9.6 with SMTP id v6ls431141laa.23.gmail; Tue, 22 Sep 2015
 10:38:33 -0700 (PDT)
X-Received: by 10.153.4.7 with SMTP id ca7mr10255002lad.90.1442943513176;
        Tue, 22 Sep 2015 10:38:33 -0700 (PDT)
Original-Received: from plane.gmane.org (plane.gmane.org. [80.91.229.3])
        by mx.google.com with ESMTPS id e9si1791184laa.157.2015.09.22.10.38.33
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Tue, 22 Sep 2015 10:38:33 -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 1ZeRWN-0008Ba-95
	for std-proposals@isocpp.org; Tue, 22 Sep 2015 19:38:27 +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>; Tue, 22 Sep 2015 19:38:27 +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>; Tue, 22 Sep 2015 19:38:27 +0200
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 36
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: <4c3e2ee7-2159-4e93-a439-7d5c94c38c9c@isocpp.org>
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:20629
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20629>

On 2015-09-22 13:03, joewoodbury@gmail.com 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/.

.
