220 2755 <f5537c87-285f-4b18-a8a3-2ddf80bf2230@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: Wed, 6 Feb 2013 12:08:41 -0800 (PST)
Lines: 214
Approved: news@gmane.org
Message-ID: <f5537c87-285f-4b18-a8a3-2ddf80bf2230@isocpp.org>
References: <8d57e9e9-e4cc-441c-abeb-e6526531fad5@isocpp.org>
 <CAOHCbiuw0zezce9kcXVsEcE=mPmp=93zQHSRMzUcNw6u3TCsBQ@mail.gmail.com>
 <ca43f129-cd55-43d3-89fc-1e4402af0e9f@isocpp.org>
 <CAOHCbivkX3wbRi6dTAcpZ1EmbpOjx_h6VkCqN8KHT0mZ_UWUXQ@mail.gmail.com>
 <13f19963-066b-4170-a6f2-eb90bed29be1@isocpp.org>
 <CAOHCbitBc-bgxOgMZwDqKeK_LAm8NV3HjEnZwA=qeKkYC0KXkw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_371_3319515.1360181322014"
X-Trace: ger.gmane.org 1360181323 18547 80.91.229.3 (6 Feb 2013 20:08:43 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 6 Feb 2013 20:08:43 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDT2DGOJ34DBBS7QZKEAKGQE2SN5CLA@isocpp.org Wed Feb 06 21:09:04 2013
Return-path: <std-proposals+bncBDT2DGOJ34DBBS7QZKEAKGQE2SN5CLA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ve0-f199.google.com ([209.85.128.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDT2DGOJ34DBBS7QZKEAKGQE2SN5CLA@isocpp.org>)
	id 1U3BIl-0006oI-Nl
	for gclcip-std-proposals@m.gmane.org; Wed, 06 Feb 2013 21:09:03 +0100
Original-Received: by mail-ve0-f199.google.com with SMTP id m1sf2714947ves.10
        for <gclcip-std-proposals@m.gmane.org>; Wed, 06 Feb 2013 12:08:44 -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: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=c2GZ+ISZC3LKlgjKj/dJ/gaU0cP+J5mIgyQujiS4Ac4=;
        b=lRfxN6H571wx0MSy9SCsm/RGnYlhjdT6/MNVOH+RVvTRC11ebiTgjyX+Vb8PIQQNA4
         24gQr3uY0yMjG6tEe6dYnDbEI/0SoUzTyhkzzDhv6JCtlV3ZDTqFAXjCBLhubTdezgxk
         g1o+4AjHTTgi1/DzGMFpnYC5tjiaR49s4cSl3CiiAf6zjyvBKUMLdvsAaRLTE4vzDVW7
         imJbyWkktAhHPECfHW3cCIMKAyK1Db6aQr25t8O9vHNh4msCJZox1DVbYaNBAruZlDJc
         pTE9j6Wrknz53uxcBMMtqwikSW7/Yen6wYdXWzMoQPkoOT0HT/1KG+CYvJ309iNUZjpc
         rNUA==
X-Received: by 10.224.76.198 with SMTP id d6mr12591665qak.8.1360181324332;
        Wed, 06 Feb 2013 12:08:44 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.127.142 with SMTP id ng14ls494092qeb.61.gmail; Wed, 06 Feb
 2013 12:08:42 -0800 (PST)
X-Received: by 10.49.15.100 with SMTP id w4mr2637270qec.26.1360181322840;
        Wed, 06 Feb 2013 12:08:42 -0800 (PST)
In-Reply-To: <CAOHCbitBc-bgxOgMZwDqKeK_LAm8NV3HjEnZwA=qeKkYC0KXkw@mail.gmail.com>
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:2755
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/2755>

------=_Part_371_3319515.1360181322014
Content-Type: text/plain; charset=ISO-8859-1



> >> 
> >> that would be consistent with int &. 
> >> I guess it gets confusing with the rebinding? 
> >> 
> >> int alternate = 21; 
> >> int another  = 35; 
> >> oi = alternate; 
> >> assert(target == 21); 
> >> oi = optional<int&>(another); 
> >> oi = 42; 
> >> assert(target != 42); 
> >> assert(another == 42); 
> > 
> > 
> > rebinding mixed assignment is confusing -- true. Non-rebinding one is 
> > inconsistent with the homogenous assignment, though -- this would also 
> be 
> > confusing. 
> > 
> >> 
> >> I could live with mixed assignment.  Moreover, I think it is "more 
> >> correct". 
> > 
> > 
> > Is the above statement correct? You are considering the mixed assignment 
> > because you could live with it? 
> > 
>
> As above, I think optional could be, maybe "strives" to be, Regular. 
> Mixed-ops don't count with Regular.  Regular only deals with T op T. 
> So mixed-ops can differ. 
> Furthermore, having mixed-assignment be Reference is consistent with int 
> &. 
> Basically mixed assignment is always "I will pass this on to my 
> value_type, and it will do whatever it wants with it". 
> Which is consistent with *really mixed* assignment - ie when the value 
> is neither T nor optional<T>.  ie: 
>
> T t; 
> U u; 
> optional<T> ot = something_not_empty; 
>
> ot = u; 
>
> What does that do?  Is it the same as: 
>
> *ot = u; 
>
> ie calls T::operator=(U) (assuming it exists)? 
>
> So when T is int &, it would call, in effect, "int&::operator=(int)". 
> Which is non-rebinding. 
>


Let me just add one observation about mixed assignment. There is always 
this case where you are assigning to a disengaged optional reference. In 
that case assigning value is not possible because there is nothing to 
assign it to, so you have to rebind the reference. This makes the mixed 
assignment behave like assign_nonrebind(): 

void assign_norebind(optional<T&>& optref, T& obj)
{
   if (optref) *optref = obj;
   else        optref.emplace(obj);
}

Which, as you observed, "is 2 totally different semantics ('targetting' vs 
'set-value-of-target') rolled into one."


-- 

--- 
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/?hl=en.



------=_Part_371_3319515.1360181322014
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;">&gt;&gt;
<br>&gt;&gt; that would be consistent with int &amp;.
<br>&gt;&gt; I guess it gets confusing with the rebinding?
<br>&gt;&gt;
<br>&gt;&gt; int alternate =3D 21;
<br>&gt;&gt; int another &nbsp;=3D 35;
<br>&gt;&gt; oi =3D alternate;
<br>&gt;&gt; assert(target =3D=3D 21);
<br>&gt;&gt; oi =3D optional&lt;int&amp;&gt;(another);
<br>&gt;&gt; oi =3D 42;
<br>&gt;&gt; assert(target !=3D 42);
<br>&gt;&gt; assert(another =3D=3D 42);
<br>&gt;
<br>&gt;
<br>&gt; rebinding mixed assignment is confusing -- true. Non-rebinding one=
 is
<br>&gt; inconsistent with the homogenous assignment, though -- this would =
also be
<br>&gt; confusing.
<br>&gt;
<br>&gt;&gt;
<br>&gt;&gt; I could live with mixed assignment. &nbsp;Moreover, I think it=
 is "more
<br>&gt;&gt; correct".
<br>&gt;
<br>&gt;
<br>&gt; Is the above statement correct? You are considering the mixed assi=
gnment
<br>&gt; because you could live with it?
<br>&gt;
<br>
<br>As above, I think optional could be, maybe "strives" to be, Regular.
<br>Mixed-ops don't count with Regular. &nbsp;Regular only deals with T op =
T.
<br>So mixed-ops can differ.
<br>Furthermore, having mixed-assignment be Reference is consistent with in=
t &amp;.
<br>Basically mixed assignment is always "I will pass this on to my
<br>value_type, and it will do whatever it wants with it".
<br>Which is consistent with *really mixed* assignment - ie when the value
<br>is neither T nor optional&lt;T&gt;. &nbsp;ie:
<br>
<br>T t;
<br>U u;
<br>optional&lt;T&gt; ot =3D something_not_empty;
<br>
<br>ot =3D u;
<br>
<br>What does that do? &nbsp;Is it the same as:
<br>
<br>*ot =3D u;
<br>
<br>ie calls T::operator=3D(U) (assuming it exists)?
<br>
<br>So when T is int &amp;, it would call, in effect, "int&amp;::operator=
=3D(int)".
<br>Which is non-rebinding.
<br></blockquote><br><br>Let me just add one observation about mixed assign=
ment. There is always this case where you are assigning to a disengaged opt=
ional reference. In that case assigning value is not possible because there=
 is nothing to assign it to, so you have to rebind the reference. This make=
s the mixed assignment behave like assign_nonrebind(): <br><br><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> assign_norebind</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">optional</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&amp;&gt;&amp;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> optref</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> obj</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp;</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">optref</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>optref </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> obj</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp;</spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">else</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; &nbsp; &nbsp;=
 &nbsp;optref</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">emplac=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">obj</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span></div></code></div><br>Which, as you =
observed, "is 2 totally different semantics ('targetting' vs 'set-value-of-=
target') rolled into one."<br><br>
<br>

<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_371_3319515.1360181322014--

.
