220 2764 <abe98aca-a573-4790-861f-f13b9da7105e@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: optional references -- take 2
Date: Thu, 7 Feb 2013 00:12:35 -0800 (PST)
Lines: 194
Approved: news@gmane.org
Message-ID: <abe98aca-a573-4790-861f-f13b9da7105e@isocpp.org>
References: <8d57e9e9-e4cc-441c-abeb-e6526531fad5@isocpp.org> <CAOHCbiuw0zezce9kcXVsEcE=mPmp=93zQHSRMzUcNw6u3TCsBQ@mail.gmail.com> <ca43f129-cd55-43d3-89fc-1e4402af0e9f@isocpp.org>
 <3534ECE0-D67E-443E-9593-76B644FDDF6A@gmail.com>
 <3aca8f41-7a21-40d8-9bf9-9c27dfa778f3@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_1604_16439068.1360224755557"
X-Trace: ger.gmane.org 1360224757 25535 80.91.229.3 (7 Feb 2013 08:12:37 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 7 Feb 2013 08:12:37 +0000 (UTC)
Cc: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>, 
	Sean Parent <sean_parent@mac.com>, sean.parent@gmail.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDT2DGOJ34DBB5GDZWEAKGQEHMIODOY@isocpp.org Thu Feb 07 09:12:57 2013
Return-path: <std-proposals+bncBDT2DGOJ34DBB5GDZWEAKGQEHMIODOY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ye0-f200.google.com ([209.85.213.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDT2DGOJ34DBB5GDZWEAKGQEHMIODOY@isocpp.org>)
	id 1U3MbI-0003vs-4L
	for gclcip-std-proposals@m.gmane.org; Thu, 07 Feb 2013 09:12:56 +0100
Original-Received: by mail-ye0-f200.google.com with SMTP id r13sf2977044yen.3
        for <gclcip-std-proposals@m.gmane.org>; Thu, 07 Feb 2013 00:12:36 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-received:x-beenthere:x-received:date:from:to:cc:message-id
         :in-reply-to:references:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-google-group-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=0qtYk20ySk0yiJTPPuUtrnCU/LHWKH5s2SVlUaNhcbY=;
        b=KotYUi+OPVfV/zhQzO6bcAbdkVFQBDXcqeG6ndGFIV0DZrvxcoftBwUj4g6HMwpqhV
         bvHbc3GO0kmqDvbgcNySuQEE628giiOJMTR8nHD/fZkMixOaBIUalMEcxRN3E/9waBN+
         qo5cXoWltGwgqoxF7hndXPHrmrNHnVn7TaQMmv43fyNtUwmiV9fLdYulv07Gp6azOXU0
         Q84qImd1pKzlnV5kfMkr1Q2KvewDzp7L+p6bgPpmfCregeBrSAvbmW4Ws2Tg0CtPWGbX
         2AhtfO8gye8TOckuruxdlPL7ltQnQBJ2+i/RKS10ePgJvhKO3sewXN/nxOfzkCqTVDko
         /sAg==
X-Received: by 10.224.176.196 with SMTP id bf4mr668997qab.4.1360224756524;
        Thu, 07 Feb 2013 00:12:36 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.82.112 with SMTP id h16ls695982qey.0.gmail; Thu, 07 Feb
 2013 00:12:36 -0800 (PST)
X-Received: by 10.49.58.140 with SMTP id r12mr23109qeq.35.1360224755950;
        Thu, 07 Feb 2013 00:12:35 -0800 (PST)
In-Reply-To: <3aca8f41-7a21-40d8-9bf9-9c27dfa778f3@isocpp.org>
X-Original-Sender: akrzemi1@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:2764
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/2764>

------=_Part_1604_16439068.1360224755557
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable



W dniu czwartek, 7 lutego 2013 03:40:11 UTC+1 u=BFytkownik Nicol Bolas=20
napisa=B3:
>
>
>
> On Wednesday, February 6, 2013 6:11:37 PM UTC-8, Sean Parent wrote:
>>
>>
>>
>> Sent from my iPad
>>
>> On Feb 5, 2013, at 12:02 PM, Andrzej Krzemie=F1ski <akrz...@gmail.com>=
=20
>> wrote:
>>
>>
>> > mixed assignment is illegal. Use one of the following instead:=20
>>> >=20
>>> > *oi =3D j; // if you want to alter the referred-to object=20
>>> > oi =3D {j}; // if you want to rebind a reference=20
>>> >=20
>>> >>=20
>>> >=20
>>> > Copy constructor and copy assignment are shallow: they only (re)bind =
a=20
>>> > reference. Other operations are deep: this includes comparison (mixed=
=20
>>> or=20
>>> > homogenous)=20
>>> >=20
>>>
>>> Is optional<T&> a RegularType?=20
>>>
>>
>> I am not sure how to answer the question. Different people have slightly=
=20
>> different expectations of a regular type.
>> optional<T&> has:
>>
>>    - default ctor
>>    - destructor
>>    - copy/move constructor (shallow)
>>    - copy/move assignment (shallow)
>>    - equality comparison (deep, provided that T is comparable)
>>
>> Then the answer would be no. The semantics of regular types are well=20
>> defined. See http://www.stepanovpapers.com/DeSt98.pdf. Copies must be=20
>> equal and disjoint. These semantics are not regular. I find it odd that=
=20
>> copying would behave differently than a T& and I'm not sure what this=20
>> construct buys you over a T*.
>>
>
> That's really the question I have about this whole `optional<T&>` thing:=
=20
> what exactly is the use case for this functionality that `T*` can't also=
=20
> cover?
>
=20
This question implies that optional references add no (or too little)=20
value. I agree with it to some extent. First, optional<T> is a useful=20
addition to the standard even w/o optional references. Second, even if=20
optional references are useful, they are needed far less often.=20

What they buy you over raw pointers?

   1. They make the ownership of the memory clear. When you get an optional=
=20
   reference, you are sure you are not responsible for deleting it.
   2. They allow you too smoothly change the signature of your function=20
   from taking T& to taking optional<T&> and you do not need to add=20
   addressof() in all places where the function is called
   3. They allow the usage of optional in "generic contexts".

Personally, I do not find (3) convincing. But people often bring it up. One=
=20
convincing use case, already mentioned in this thread is provided here:=20
https://groups.google.com/a/isocpp.org/d/msg/std-proposals/cXneqUj-5oo/zCnK=
bHCGsxgJ

Also, the "generic use" does not require optional references. One can=20
implement it oneself using a=20
trick described here:=20
http://kojot.sggw.waw.pl/~akrzemi1/optional/tr2.optional.proposal.html#rati=
onale.refs

Regarding (1) and (2), I happened to use optional reference in these=20
contexts and found them more elegant than pointers. But for these usages I=
=20
never needed any kind of optional reference assignment.

--=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/?hl=3Den.



------=_Part_1604_16439068.1360224755557
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable

<br><br>W dniu czwartek, 7 lutego 2013 03:40:11 UTC+1 u=BFytkownik Nicol Bo=
las napisa=B3:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br><br>On Wedne=
sday, February 6, 2013 6:11:37 PM UTC-8, Sean Parent wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc =
solid;padding-left:1ex"><div dir=3D"auto"><div><br><br>Sent from my iPad</d=
iv><div><br>On Feb 5, 2013, at 12:02 PM, Andrzej Krzemie=F1ski &lt;<a>akrz.=
...@gmail.com</a>&gt; wrote:<br><br></div><blockquote type=3D"cite"><div><br=
><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bord=
er-left:1px #ccc solid;padding-left:1ex">&gt; mixed assignment is illegal. =
Use one of the following instead:
<br>&gt;
<br>&gt; *oi =3D j; // if you want to alter the referred-to object
<br>&gt; oi =3D {j}; // if you want to rebind a reference
<br>&gt;
<br>&gt;&gt;
<br>&gt;
<br>&gt; Copy constructor and copy assignment are shallow: they only (re)bi=
nd a
<br>&gt; reference. Other operations are deep: this includes comparison (mi=
xed or
<br>&gt; homogenous)
<br>&gt;
<br>
<br>Is optional&lt;T&amp;&gt; a RegularType?
<br></blockquote><div><br>I am not sure how to answer the question. Differe=
nt people have slightly different expectations of a regular type.<br>option=
al&lt;T&amp;&gt; has:<br><ul><li>default ctor</li><li>destructor<br></li><l=
i>copy/move constructor (shallow)</li><li>copy/move assignment (shallow)</l=
i><li>equality comparison (deep, provided that T is comparable)</li></ul></=
div></div></blockquote><div>Then the answer would be no. The semantics of r=
egular types are well defined. See&nbsp;<a href=3D"http://www.stepanovpaper=
s.com/DeSt98.pdf" target=3D"_blank">http://www.stepanovpapers.<wbr>com/DeSt=
98.pdf</a>.&nbsp;Copies must be equal and disjoint. These semantics are not=
 regular. I find it odd that copying would behave differently than a T&amp;=
 and I'm not sure what this construct buys you over a T*.</div></div></bloc=
kquote><div><br>That's really the question I have about this whole `optiona=
l&lt;T&amp;&gt;` thing: what exactly is the use case for this functionality=
 that `T*` can't also cover?</div></blockquote><div>&nbsp;</div><div>This q=
uestion implies that optional references add no (or too little) value. I ag=
ree with it to some extent. First, optional&lt;T&gt; is a useful addition t=
o the standard even w/o optional references. Second, even if optional refer=
ences are useful, they are needed far less often. <br><br>What they buy you=
 over raw pointers?<br><ol><li>They make the ownership of the memory clear.=
 When you get an optional reference, you are sure you are not responsible f=
or deleting it.</li><li>They allow you too smoothly change the signature of=
 your function from taking T&amp; to taking optional&lt;T&amp;&gt; and you =
do not need to add addressof() in all places where the function is called</=
li><li>They allow the usage of optional in "generic contexts".</li></ol><p>=
Personally, I do not find (3) convincing. But people often bring it up. One=
 convincing use case, already mentioned in this thread is provided here: <a=
 href=3D"https://groups.google.com/a/isocpp.org/d/msg/std-proposals/cXneqUj=
-5oo/zCnKbHCGsxgJ" target=3D"_blank">https://groups.google.com/a/<wbr>isocp=
p.org/d/msg/std-<wbr>proposals/cXneqUj-5oo/<wbr>zCnKbHCGsxgJ</a></p><p>Also=
, the "generic use" does not require optional references. One can implement=
 it oneself using a <br>trick described here: http://kojot.sggw.waw.pl/~akr=
zemi1/optional/tr2.optional.proposal.html#rationale.refs</p><p>Regarding (1=
) and (2), I happened to use optional reference in these contexts and found=
 them more elegant than pointers. But for these usages I never needed any k=
ind of optional reference assignment.<br></p></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1604_16439068.1360224755557--

.
