220 20705 <2711C197-0E67-4ADB-83A1-2D7B15E21693@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Null -conditional and -coalescing operators
Date: Wed, 23 Sep 2015 17:31:54 +0800
Lines: 92
Approved: news@gmane.org
Message-ID: <2711C197-0E67-4ADB-83A1-2D7B15E21693@gmail.com>
References: <4c3e2ee7-2159-4e93-a439-7d5c94c38c9c@isocpp.org> <d871b34e-cb96-4826-b52f-72fa0fdb104e@isocpp.org> <2081160.jZretSXBOl@tjmaciei-mobl4>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_49C9D21C-13B2-4AC7-A590-9C0B299084F3"
X-Trace: ger.gmane.org 1443000736 31943 80.91.229.3 (23 Sep 2015 09:32:16 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 23 Sep 2015 09:32:16 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBEHDRGYAKGQEYE2X2BQ@isocpp.org Wed Sep 23 11:32:03 2015
Return-path: <std-proposals+bncBCW25A7E3QCRBEHDRGYAKGQEYE2X2BQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-io0-f200.google.com ([209.85.223.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBEHDRGYAKGQEYE2X2BQ@isocpp.org>)
	id 1ZegPC-000379-HE
	for gclcip-std-proposals@m.gmane.org; Wed, 23 Sep 2015 11:32:02 +0200
Original-Received: by ioiz6 with SMTP id z6sf68304536ioi.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 23 Sep 2015 02:32:01 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:content-type:message-id:mime-version
         :subject:date:references:to: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=TMIxDGZbODtkrJ/EEmXQhZVfYHkdeZwwYyHp+ibaJgU=;
        b=Ce7oxLrJZfmkGFraAImVLZPc2wabnfRkgMz2woypkt+r2PtLRzrxHFSH/yuKuG4cSx
         CsJbVuCzyw5tAPLwSr2Ned6mjsgJiS0qg3u1ebTDOaWBgq/S//WEbVASM4r+EUQ90M3A
         liE+aeCcQYF4Pi1U47DAGs9dCq8dAxt8XDATC3GD396nZvMqO6Ej16yoUhaBrAXcNmVJ
         Rcfg5JL73SAq1Km3UE+X5MeRV2SdshUdz5OYSP93eKGRJ1j9lq9mtdz4nVHv3Ai4zrmv
         uttXeVVLFNpYtM5D2cMzKYTd4yVncv05MV7baejMmN3e6UIFb6j6zwNEair0+XGjECp2
         /VFw==
X-Gm-Message-State: ALoCoQnYNzOSm888izU7n23HcTuDdHFXyBQxcUk5Ti34X1T25A1KUnIs6e9wgg2EivxaDt1XgCtE
X-Received: by 10.50.225.102 with SMTP id rj6mr7376483igc.9.1443000721439;
        Wed, 23 Sep 2015 02:32:01 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.79.201 with SMTP id l9ls395858igx.19.gmail; Wed, 23 Sep
 2015 02:32:00 -0700 (PDT)
X-Received: by 10.50.8.3 with SMTP id n3mr22603642iga.26.1443000720546;
        Wed, 23 Sep 2015 02:32:00 -0700 (PDT)
Original-Received: from mail-pa0-x235.google.com (mail-pa0-x235.google.com. [2607:f8b0:400e:c03::235])
        by mx.google.com with ESMTPS id hh18si16064088igb.55.2015.09.23.02.32.00
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 23 Sep 2015 02:32:00 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c03::235 as permitted sender) client-ip=2607:f8b0:400e:c03::235;
Original-Received: by pacex6 with SMTP id ex6so35949285pac.0
        for <std-proposals@isocpp.org>; Wed, 23 Sep 2015 02:32:00 -0700 (PDT)
X-Received: by 10.66.144.135 with SMTP id sm7mr36956413pab.106.1443000720006;
        Wed, 23 Sep 2015 02:32:00 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.183])
        by smtp.gmail.com with ESMTPSA id zf5sm6847220pbc.36.2015.09.23.02.31.58
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 23 Sep 2015 02:31:59 -0700 (PDT)
In-Reply-To: <2081160.jZretSXBOl@tjmaciei-mobl4>
X-Mailer: Apple Mail (2.2104)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c03::235 as permitted
 sender) smtp.mailfrom=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (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:20705
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20705>

--Apple-Mail=_49C9D21C-13B2-4AC7-A590-9C0B299084F3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

All this confusion aside, it would be nice to have such a thing in the libr=
ary. It would be on a similar level of abstraction as std::exchange.

Not tested, but it might look something like this:

template< typename alternative, typename value >
alternative value_or( value && v, alternative && a ) {
    if ( v ) return std::forward< value >( v );
    else return std::forward< alternative >( a );
}

Given such a facility, experimental::optional shouldn=E2=80=99t need a memb=
er value_or. This one does work a bit differently, but the goal is the same=
..

It would be better if it returned by reference. This would be enabled by my=
 lifetime extension proposal (bit.ly/genlife <http://bit.ly/genlife>) and m=
arking both parameters as export.

Unlike the OP, the second argument gets evaluated even if it=E2=80=99s not =
used. Hopefully at some point the language will support user-defined short-=
circuit operators via lazy argument evaluation. In the big picture, the def=
iciency is minor.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_49C9D21C-13B2-4AC7-A590-9C0B299084F3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">All this confusion=
 aside, it would be nice to have such a thing in the library. It would be o=
n a similar level of abstraction as <font face=3D"Courier" class=3D"">std::=
exchange</font>.<div class=3D""><br class=3D""></div><div class=3D"">Not te=
sted, but it might look something like this:</div><div class=3D""><br class=
=3D""></div><div class=3D""><font face=3D"Courier" class=3D"">template&lt;&=
nbsp;</font><span style=3D"font-family: Courier;" class=3D"">typename alter=
native,&nbsp;</span><span style=3D"font-family: Courier;" class=3D"">typena=
me value &gt;</span></div><div class=3D""><font face=3D"Courier" class=3D""=
>alternative value_or( value &amp;&amp; v, alternative &amp;&amp; a ) {</fo=
nt></div><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp; if=
 ( v ) return std::forward&lt; value &gt;( v );</font></div><div class=3D""=
><font face=3D"Courier" class=3D"">&nbsp; &nbsp; else return std::forward&l=
t; alternative &gt;( a );</font></div><div class=3D""><font face=3D"Courier=
" class=3D"">}</font></div><div class=3D""><br class=3D""></div><div class=
=3D"">Given such a facility, <font face=3D"Courier" class=3D"">experimental=
::optional</font> shouldn=E2=80=99t need a member <font face=3D"Courier" cl=
ass=3D"">value_or</font>. This one does work a bit differently, but the goa=
l is the same.</div><div class=3D""><br class=3D""></div><div class=3D"">It=
 would be better if it returned by reference. This would be enabled by my l=
ifetime extension proposal (<a href=3D"http://bit.ly/genlife" class=3D"">bi=
t.ly/genlife</a>) and marking both parameters as&nbsp;<font face=3D"Courier=
" class=3D"">export</font>.</div><div class=3D""><br class=3D""></div><div =
class=3D"">Unlike the OP, the second argument gets evaluated even if it=E2=
=80=99s not used. Hopefully at some point the language will support user-de=
fined short-circuit operators via lazy argument evaluation. In the big pict=
ure, the deficiency is minor.</div><div class=3D""><br class=3D""></div></b=
ody></html>

<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 />

--Apple-Mail=_49C9D21C-13B2-4AC7-A590-9C0B299084F3--

.
