220 25488 <f92d4647-9aca-4471-bdc2-c7caba2e2128@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: isocppgroup@denisbider.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Relocation as a solution for the valueless
 variant problem?
Date: Fri, 8 Apr 2016 15:30:51 -0700 (PDT)
Lines: 468
Approved: news@gmane.org
Message-ID: <f92d4647-9aca-4471-bdc2-c7caba2e2128@isocpp.org>
References: <b4feb52d-4cd0-475f-9f3d-6694564bc1b0@isocpp.org>
 <4187538d-68fa-4582-ba26-f406479abe67@isocpp.org>
 <eafd831f-85d2-430c-9969-7d084e6d28d2@isocpp.org>
 <CALQmNFggBQSADjEqS7pEzcdPSStGJfXkJdX0d2CwW_TmwqA=yQ@mail.gmail.com>
 <105d82bc-e1cf-4795-894c-112cd591c3af@isocpp.org>
 <CALQmNFja3Kt1XRR8S7Qr3rOktChVzuDGO7ZtSaQpsWaohU6wAA@mail.gmail.com>
 <4f31b957-05be-47cf-a1ca-03f33a9900c0@isocpp.org>
 <CALQmNFgoV-Rg4T6+KqMFt6vNa7GCDpU=jVLRcnK4dDd+eBby8A@mail.gmail.com>
 <30181f63-7189-494d-9294-3f8b8759308f@isocpp.org>
 <d7eee27f-bdfc-45b0-9c29-508dd01975b3@isocpp.org>
 <cad96977-d5d4-4eea-8169-ae1ceb8b6477@isocpp.org>
 <456f6164-031c-4ccc-ba25-39fcb5714b98@isocpp.org>
 <96061c41-6f44-468b-b5ec-fb1fd6fad4b7@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1119_1497625205.1460154651741"
X-Trace: ger.gmane.org 1460154657 12257 80.91.229.3 (8 Apr 2016 22:30:57 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 8 Apr 2016 22:30:57 +0000 (UTC)
Cc: isocppgroup@denisbider.com, barry.revzin@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD5LNK7YQYJRBHPCUC4AKGQE4N5OSWQ@isocpp.org Sat Apr 09 00:30:56 2016
Return-path: <std-proposals+bncBD5LNK7YQYJRBHPCUC4AKGQE4N5OSWQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f200.google.com ([209.85.161.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD5LNK7YQYJRBHPCUC4AKGQE4N5OSWQ@isocpp.org>)
	id 1aoevW-0006If-Vu
	for gclcip-std-proposals@m.gmane.org; Sat, 09 Apr 2016 00:30:55 +0200
Original-Received: by mail-yw0-f200.google.com with SMTP id o131sf212141758ywc.2
        for <gclcip-std-proposals@m.gmane.org>; Fri, 08 Apr 2016 15:30:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=Gz9BsjHM0GglfmkPu2R0g8qszF7p+kP3BIuKJXFJT2A=;
        b=L7SOLAwjHds/v5+Li4krwXKxChco0uEzRqJLmVmZBn5CZARvFml7O4RGjS2V4CMJ4I
         JA2d1AGmpMYoplcpk6aa6peb0hgVN3jZl0D23FY4XD8zOXBB5G8r9T1froHB9fgPyQgg
         HtmXXYLh+pr0bfA3r+29hNJ/D2rMiV3pM9dtwOThky/fSZqcxDzVmgpikT7Z5RjXfLm/
         j4RVyDDvSAmpAeGx9kuTag5FeMUb33JtYrlAUVO7OzqCpGzkHcvLWWddrWHEJE5JaqIb
         Q10d3gjFS7tHQJwm/Vqc+Le15vsqjDbQMj8by4ay/u08mQ6jMBHZPtWpFF3KXBqMOSo1
         Oi+w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=Gz9BsjHM0GglfmkPu2R0g8qszF7p+kP3BIuKJXFJT2A=;
        b=RKaOtL+AC8F/K8sbEgSy4RFWx8RkhkDdgcoVFmMqIXPiTvPzV4e1bFr5IcxBxzpDoR
         RyqBEPTd02cfd2IKxW1+UuGe1i2SLqCu0dHy7thXF7/uLEHzinkzQUV2kMqM3rhsGnw6
         AVMNotGCw+OPyP21S2pPze47n4wxOPwCZBVzrE7GyQxXIf77x2hQ/50R7bzY7ytz9Qpr
         BkWoVZYY22nZb6uKsG2dUmgOR4CmGQZtQk+sd8MQNCFltmgakcvy0t8jpKDsLoPKGRIa
         BVzJPeGI+EVb8Hq0ZjwuEB1NikYU19gt7nQbrd1kXTlxdc5ZbOZxB9d/4XLECGKDPXOc
         5LqA==
X-Gm-Message-State: AD7BkJIFYnX2jcD0SYqv7i0MrMJGECL3aiUQ328zndGUbG8xa42fuXqHmtTVkHwx6Ie0eA==
X-Received: by 10.31.6.210 with SMTP id 201mr7184025vkg.3.1460154653997;
        Fri, 08 Apr 2016 15:30:53 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.39.48 with SMTP id m16ls333730igk.8.canary; Fri, 08 Apr
 2016 15:30:52 -0700 (PDT)
X-Received: by 10.50.155.72 with SMTP id vu8mr150748igb.5.1460154652902;
        Fri, 08 Apr 2016 15:30:52 -0700 (PDT)
In-Reply-To: <96061c41-6f44-468b-b5ec-fb1fd6fad4b7@isocpp.org>
X-Original-Sender: isocppgroup@denisbider.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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:25488
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/25488>

------=_Part_1119_1497625205.1460154651741
Content-Type: multipart/alternative; 
	boundary="----=_Part_1120_17427712.1460154651742"

------=_Part_1120_17427712.1460154651742
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Or, since we have this problem already when distinguishing between move and=
=20
copy construction: how about a family of special blessed functions, like=20
this?

template <typename T> T const& require_copy     (T const&);template <typena=
me T> T&&      require_move     (T&);template <typename T> T&       require=
_relocate (T&);


Each of these would require the compiler to flag the returned reference,=20
and perform a compile-time verification that the reference does in fact end=
=20
up being passed to a copy constructor; move constructor; or relocator,=20
respectively.

This would be useful even without relocate. It would allow code like this:

BigObj MakeBigObj() {
  BigObj x;
  x.This();
  x.That();
  return std::require_move(x);}


.... to verify that what's happening is indeed move construction - not copy=
=20
construction, by accident.


On Friday, April 8, 2016 at 3:44:24 PM UTC-6, isocp...@denisbider.com wrote=
:

> You are quite correct. This aspect is being implied, rather than being=20
> addressed.
> =20
> I am toying with the following text - currently rather informal:
>
> "Move optimization=20
>
> When a type is relocatable; then in situations where an implementation=20
> would otherwise move an object value to an object of same type by invokin=
g=20
> a move constructor, followed by destruction of the moved-from object; and=
=20
> where no use of the moved-from object occurs between move and destruction=
;=20
> the implementation may instead invoke the type=E2=80=99s relocator, elidi=
ng the=20
> move constructor and destructor.
> This move optimization *must* occur when move construction followed by=20
> destruction would otherwise be used when returning a relocatable type by=
=20
> value from a function, into a new object of same type."
>
> =20
> This would require relocation for return by value, if relocation is=20
> available and copy elision isn't. This would be similar to how move vs.=
=20
> copy construction is already chosen right now.=20
> =20
> It would also open the door for a compiler to detect when an object is=20
> being moved to a new location, followed by destruction in the previous=20
> location. In this case, the compiler *could* use relocation (move=20
> destruction), but is not forced to.
> =20
> An open concern here is whether this would be, in practice, too subtle.=
=20
> For example, a developer might want to ensure that relocation is used,=20
> instead of move construction + destruction:
> =20
>
> std::unique_ptr<Thing> MakeThing() {
>   std::list<int> lst =3D ...;
>   InitializeList(lst);
>   return std::make_unique<Thing>(std::move(lst));
>     // Is this copy construction, move construction, or relocation?}
>
> =20
> On the one hand, currently, we do not have syntax that the developer coul=
d=20
> use to ensure move construction is used, rather than copy construction. T=
he=20
> developer just has to use syntax that allows for move construction, and=
=20
> then count on that a move constructor is available.
> =20
> Suppose that we have relocation, and the compiler has determined to use=
=20
> relocation in the above example.
> =20
> Then, someone modifies the above function as follows:
> =20
>
> std::unique_ptr<Thing> MakeThing() {
>   std::list<int> lst =3D ...;
>   InitializeList(lst);
>   auto thing =3D std::make_unique<Thing>(std::move(lst));
>   ReuseListForOtherPurpose(lst);
>   return thing;}
>
> =20
> Now, this definitely no longer uses relocation, because *lst* is=20
> being used again.
>
> Is this a concern? How do we prevent this?
>
> To avoid introducing a keyword, one way could be to add a blessed standar=
d=20
> library function, say *std::final_reference*:=20
>
> std::unique_ptr<Thing> MakeThing() {
>   std::list<int> lst =3D ...;
>   InitializeList(lst);
>   auto thing =3D std::make_unique<Thing>(std::final_reference(lst));
>   ReuseListForOtherPurpose(lst);  // Error: use of "lst" after final_refe=
rence
>   return thing;}
>
>
> This would require a compiler to detect the reuse of "lst" after it's use=
d=20
> in *std::final_reference*, and flag an error when "lst" is reused.
>
> An alternative to a blessed function would be a new keyword, e.g.=20
> "final_reference".
>
> Thoughts? Ideas?
>
> =20
> On Friday, April 8, 2016 at 2:46:35 PM UTC-6, barry....@gmail.com wrote:
>
>> > If your relocation support can't even perform relocation in this most=
=20
>>> simple of cases:
>>> =20
>>> =20
>>> How does it *not* handle that case? If std::list has a relocator, the=
=20
>>> compiler can just call the relocator in this case:
>>> =20
>>>
>>>   std::list<T> SomeFunc() {
>>>     std::list<T> lt =3D ...
>>>     ...
>>>     return lt; // no special syntax needed; compiler calls relocator >>=
list<T>
>>>   }
>>>
>>> =20
>>> What prevents the compiler from doing this?
>>>
>> =20
>> As far as I can tell, your proposal doesn't say anything about this case=
,=20
>> or about automatic objects at all. Your invocation section only addresse=
s=20
>> the use-case of "relocating" one pointer to another.=20
>> =20
>> You should take advantage of the feedback opportunity to improve your=20
>> proposal. There's no need to be so defensive.=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/f92d4647-9aca-4471-bdc2-c7caba2e2128%40isocpp.or=
g.

------=_Part_1120_17427712.1460154651742
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Or, since we have this problem already when distingui=
shing between move and copy construction: how=C2=A0about=C2=A0a family of=
=C2=A0special blessed functions, like this?</div><div><br></div><div><pre s=
tyle=3D"background: rgb(246, 248, 255); color: rgb(0, 0, 32);"><span style=
=3D"color: rgb(32, 0, 128); font-weight: bold;">template</span> <span style=
=3D"color: rgb(64, 96, 128);">&lt;</span><span style=3D"color: rgb(32, 0, 1=
28); font-weight: bold;">typename</span> T<span style=3D"color: rgb(64, 96,=
 128);">&gt;</span> T <span style=3D"color: rgb(32, 0, 128); font-weight: b=
old;">const</span><span style=3D"color: rgb(48, 128, 128);">&amp;</span> re=
quire_copy     <span style=3D"color: rgb(48, 128, 128);">(</span>T <span st=
yle=3D"color: rgb(32, 0, 128); font-weight: bold;">const</span><span style=
=3D"color: rgb(48, 128, 128);">&amp;</span><span style=3D"color: rgb(48, 12=
8, 128);">)</span><span style=3D"color: rgb(64, 96, 128);">;</span>
<span style=3D"color: rgb(32, 0, 128); font-weight: bold;">template</span> =
<span style=3D"color: rgb(64, 96, 128);">&lt;</span><span style=3D"color: r=
gb(32, 0, 128); font-weight: bold;">typename</span> T<span style=3D"color: =
rgb(64, 96, 128);">&gt;</span> T<span style=3D"color: rgb(48, 128, 128);">&=
amp;</span><span style=3D"color: rgb(48, 128, 128);">&amp;</span>      requ=
ire_move     <span style=3D"color: rgb(48, 128, 128);">(</span>T<span style=
=3D"color: rgb(48, 128, 128);">&amp;</span><span style=3D"color: rgb(48, 12=
8, 128);">)</span><span style=3D"color: rgb(64, 96, 128);">;</span>
<span style=3D"color: rgb(32, 0, 128); font-weight: bold;">template</span> =
<span style=3D"color: rgb(64, 96, 128);">&lt;</span><span style=3D"color: r=
gb(32, 0, 128); font-weight: bold;">typename</span> T<span style=3D"color: =
rgb(64, 96, 128);">&gt;</span> T<span style=3D"color: rgb(48, 128, 128);">&=
amp;</span>       require_relocate <span style=3D"color: rgb(48, 128, 128);=
">(</span>T<span style=3D"color: rgb(48, 128, 128);">&amp;</span><span styl=
e=3D"color: rgb(48, 128, 128);">)</span><span style=3D"color: rgb(64, 96, 1=
28);">;</span>

</pre></div><div><br></div><div>Each of these would require the compiler to=
 flag the returned reference, and perform a compile-time verification that =
the reference does in fact end up being passed to a copy constructor; move =
constructor; or relocator, respectively.</div><div><br></div><div>This woul=
d be useful even without relocate. It would allow code like this:</div><div=
><br></div><div><pre style=3D"background: rgb(246, 248, 255); color: rgb(0,=
 0, 32);">BigObj MakeBigObj<span style=3D"color: rgb(48, 128, 128);">(</spa=
n><span style=3D"color: rgb(48, 128, 128);">)</span> <span style=3D"color: =
rgb(64, 96, 128);">{</span>
  BigObj x<span style=3D"color: rgb(64, 96, 128);">;</span>
  x<span style=3D"color: rgb(48, 128, 128);">.</span>This<span style=3D"col=
or: rgb(48, 128, 128);">(</span><span style=3D"color: rgb(48, 128, 128);">)=
</span><span style=3D"color: rgb(64, 96, 128);">;</span>
  x<span style=3D"color: rgb(48, 128, 128);">.</span>That<span style=3D"col=
or: rgb(48, 128, 128);">(</span><span style=3D"color: rgb(48, 128, 128);">)=
</span><span style=3D"color: rgb(64, 96, 128);">;</span>
  <span style=3D"color: rgb(32, 0, 128); font-weight: bold;">return</span> =
<span style=3D"color: rgb(0, 102, 238);">std</span><span style=3D"color: rg=
b(64, 96, 128);">::</span>require_move<span style=3D"color: rgb(48, 128, 12=
8);">(</span>x<span style=3D"color: rgb(48, 128, 128);">)</span><span style=
=3D"color: rgb(64, 96, 128);">;</span>
<span style=3D"color: rgb(64, 96, 128);">}</span>

</pre></div><div><br></div><div>... to verify that what&#39;s happening is =
indeed move construction -=C2=A0not copy construction, by accident.<br></di=
v><div><br></div><div><br>On Friday, April 8, 2016 at 3:44:24 PM UTC-6, iso=
cp...@denisbider.com wrote:</div><blockquote class=3D"gmail_quote" style=3D=
"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, =
204, 204); border-left-width: 1px; border-left-style: solid;"><div dir=3D"l=
tr"><div>You are quite correct.=C2=A0This aspect is being implied, rather t=
han being addressed.</div><div><div>=C2=A0</div></div><div>I am toying with=
 the following text - currently rather informal:</div><blockquote><h2 style=
=3D"margin: 12pt 0in 0pt;"><font color=3D"#2e74b5" face=3D"Calibri Light" s=
ize=3D"4">&quot;Move optimization</font></h2><font color=3D"#000000" face=
=3D"Times New Roman" size=3D"3">

</font><p style=3D"margin: 8pt 0in; text-align: justify;"><font color=3D"#0=
00000" face=3D"Calibri" size=3D"3">When a type is relocatable; then
in situations where an implementation would otherwise move an object value =
to
an object of same type by invoking a move constructor, followed by destruct=
ion
of the moved-from object; and where no use of the moved-from object occurs =
between
move and destruction; the implementation may instead invoke the type=E2=80=
=99s relocator,
eliding the move constructor and destructor.</font></p><font color=3D"#0000=
00"><font face=3D"Times New Roman" size=3D"3">

</font><span style=3D"line-height: 107%; font-family: &quot;Calibri&quot;,s=
ans-serif; font-size: 11pt;">This move optimization <b>must</b> occur when =
move construction followed by destruction would otherwise
be used when returning a relocatable type by value from a function, into a =
new object
of same type.&quot;</span></font></blockquote><div>=C2=A0</div><div>This wo=
uld require relocation for return by value, if relocation is available and =
copy elision isn&#39;t. This would be similar to how move vs. copy construc=
tion is already chosen right now. </div><div><div>=C2=A0</div></div><div>It=
 would also open the door for a compiler to detect when an object is being =
moved to a new location, followed by destruction in the previous location.=
=C2=A0In this case, the compiler <em>could</em>=C2=A0use relocation (move d=
estruction), but is not forced to.</div><div><div>=C2=A0</div></div><div>An=
 open concern here is whether this would be, in practice, too subtle. For e=
xample, a developer might want to ensure that relocation is used, instead o=
f move construction + destruction:</div><div><div>=C2=A0</div></div><div><p=
re style=3D"background: rgb(246, 248, 255); color: rgb(0, 0, 32);"><span st=
yle=3D"color: rgb(89, 89, 121);"><pre style=3D"background: rgb(246, 248, 25=
5); color: rgb(0, 0, 32);"><span style=3D"color: rgb(0, 102, 238);">std</sp=
an><span style=3D"color: rgb(64, 96, 128);">::</span><span style=3D"color: =
rgb(0, 48, 96);">unique_ptr</span><span style=3D"color: rgb(64, 96, 128);">=
&lt;</span>Thing<span style=3D"color: rgb(64, 96, 128);">&gt;</span> MakeTh=
ing<span style=3D"color: rgb(48, 128, 128);">(</span><span style=3D"color: =
rgb(48, 128, 128);">)</span> <span style=3D"color: rgb(64, 96, 128);">{</sp=
an>
  <span style=3D"color: rgb(0, 102, 238);">std</span><span style=3D"color: =
rgb(64, 96, 128);">::</span><span style=3D"color: rgb(0, 48, 96);">list</sp=
an><span style=3D"color: rgb(64, 96, 128);">&lt;</span><span style=3D"color=
: rgb(32, 0, 128); font-weight: bold;">int</span><span style=3D"color: rgb(=
64, 96, 128);">&gt;</span> lst <span style=3D"color: rgb(48, 128, 128);">=
=3D</span> <span style=3D"color: rgb(48, 128, 128);">.</span><span style=3D=
"color: rgb(48, 128, 128);">.</span><span style=3D"color: rgb(48, 128, 128)=
;">.</span><span style=3D"color: rgb(64, 96, 128);">;</span>
  InitializeList<span style=3D"color: rgb(48, 128, 128);">(</span>lst<span =
style=3D"color: rgb(48, 128, 128);">)</span><span style=3D"color: rgb(64, 9=
6, 128);">;</span>
  <span style=3D"color: rgb(32, 0, 128); font-weight: bold;">return</span> =
<span style=3D"color: rgb(0, 102, 238);">std</span><span style=3D"color: rg=
b(64, 96, 128);">::</span>make_unique<span style=3D"color: rgb(64, 96, 128)=
;">&lt;</span>Thing<span style=3D"color: rgb(64, 96, 128);">&gt;</span><spa=
n style=3D"color: rgb(48, 128, 128);">(</span><span style=3D"color: rgb(0, =
102, 238);">std</span><span style=3D"color: rgb(64, 96, 128);">::</span><sp=
an style=3D"color: rgb(0, 48, 96);">m<wbr>ove</span><span style=3D"color: r=
gb(48, 128, 128);">(</span>lst<span style=3D"color: rgb(48, 128, 128);">)</=
span><span style=3D"color: rgb(48, 128, 128);">)</span><span style=3D"color=
: rgb(64, 96, 128);">;</span>
    <span style=3D"color: rgb(89, 89, 121);">// Is this copy construction, =
move construction, or relocation?</span>
<span style=3D"color: rgb(64, 96, 128);">}</span>

</pre></span></pre></div><div><div>=C2=A0</div></div><div>On the one hand, =
currently, we do not have syntax that the developer could use to ensure mov=
e construction is used,=C2=A0rather than=C2=A0copy construction. The develo=
per just has to use syntax that allows for move construction, and then coun=
t on that a move constructor is available.</div><div><div>=C2=A0</div></div=
><div>Suppose that we have relocation, and the compiler has determined to u=
se relocation in the above example.</div><div><div>=C2=A0</div></div><div>T=
hen, someone modifies=C2=A0the above=C2=A0function as follows:</div><div><d=
iv>=C2=A0</div></div><div><pre style=3D"background: rgb(246, 248, 255); col=
or: rgb(0, 0, 32);"><span style=3D"color: rgb(0, 102, 238);">std</span><spa=
n style=3D"color: rgb(64, 96, 128);">::</span><span style=3D"color: rgb(0, =
48, 96);">unique_ptr</span><span style=3D"color: rgb(64, 96, 128);">&lt;</s=
pan>Thing<span style=3D"color: rgb(64, 96, 128);">&gt;</span> MakeThing<spa=
n style=3D"color: rgb(48, 128, 128);">(</span><span style=3D"color: rgb(48,=
 128, 128);">)</span> <span style=3D"color: rgb(64, 96, 128);">{</span>
  <span style=3D"color: rgb(0, 102, 238);">std</span><span style=3D"color: =
rgb(64, 96, 128);">::</span><span style=3D"color: rgb(0, 48, 96);">list</sp=
an><span style=3D"color: rgb(64, 96, 128);">&lt;</span><span style=3D"color=
: rgb(32, 0, 128); font-weight: bold;">int</span><span style=3D"color: rgb(=
64, 96, 128);">&gt;</span> lst <span style=3D"color: rgb(48, 128, 128);">=
=3D</span> <span style=3D"color: rgb(48, 128, 128);">.</span><span style=3D=
"color: rgb(48, 128, 128);">.</span><span style=3D"color: rgb(48, 128, 128)=
;">.</span><span style=3D"color: rgb(64, 96, 128);">;</span>
  InitializeList<span style=3D"color: rgb(48, 128, 128);">(</span>lst<span =
style=3D"color: rgb(48, 128, 128);">)</span><span style=3D"color: rgb(64, 9=
6, 128);">;</span>
  <span style=3D"color: rgb(32, 0, 128); font-weight: bold;">auto</span> th=
ing <span style=3D"color: rgb(48, 128, 128);">=3D</span> <span style=3D"col=
or: rgb(0, 102, 238);">std</span><span style=3D"color: rgb(64, 96, 128);">:=
:</span>make_unique<span style=3D"color: rgb(64, 96, 128);">&lt;</span>Thin=
g<span style=3D"color: rgb(64, 96, 128);">&gt;</span><span style=3D"color: =
rgb(48, 128, 128);">(</span><span style=3D"color: rgb(0, 102, 238);">std</s=
pan><span style=3D"color: rgb(64, 96, 128);">::</span><span style=3D"color:=
 rgb(0, 48, 96);">m<wbr>ove</span><span style=3D"color: rgb(48, 128, 128);"=
>(</span>lst<span style=3D"color: rgb(48, 128, 128);">)</span><span style=
=3D"color: rgb(48, 128, 128);">)</span><span style=3D"color: rgb(64, 96, 12=
8);">;</span>
  ReuseListForOtherPurpose<span style=3D"color: rgb(48, 128, 128);">(</span=
>lst<span style=3D"color: rgb(48, 128, 128);">)</span><span style=3D"color:=
 rgb(64, 96, 128);">;</span>
  <span style=3D"color: rgb(32, 0, 128); font-weight: bold;">return</span> =
thing<span style=3D"color: rgb(64, 96, 128);">;</span>
<span style=3D"color: rgb(64, 96, 128);">}</span>

</pre></div><div><div>=C2=A0</div></div><div><div>Now, this definitely no l=
onger uses relocation,=C2=A0because <em>lst</em> is being=C2=A0used again.<=
/div><div><br></div><div>Is this a concern? How do we prevent this?</div><d=
iv><br></div><div>To avoid introducing a keyword, one way could be to add a=
 blessed standard library function, say <em>std::final_reference</em>: </di=
v><div><br></div><div><pre style=3D"background: rgb(246, 248, 255); color: =
rgb(0, 0, 32);"><span style=3D"color: rgb(0, 102, 238);">std</span><span st=
yle=3D"color: rgb(64, 96, 128);">::</span><span style=3D"color: rgb(0, 48, =
96);">unique_ptr</span><span style=3D"color: rgb(64, 96, 128);">&lt;</span>=
Thing<span style=3D"color: rgb(64, 96, 128);">&gt;</span> MakeThing<span st=
yle=3D"color: rgb(48, 128, 128);">(</span><span style=3D"color: rgb(48, 128=
, 128);">)</span> <span style=3D"color: rgb(64, 96, 128);">{</span>
  <span style=3D"color: rgb(0, 102, 238);">std</span><span style=3D"color: =
rgb(64, 96, 128);">::</span><span style=3D"color: rgb(0, 48, 96);">list</sp=
an><span style=3D"color: rgb(64, 96, 128);">&lt;</span><span style=3D"color=
: rgb(32, 0, 128); font-weight: bold;">int</span><span style=3D"color: rgb(=
64, 96, 128);">&gt;</span> lst <span style=3D"color: rgb(48, 128, 128);">=
=3D</span> <span style=3D"color: rgb(48, 128, 128);">.</span><span style=3D=
"color: rgb(48, 128, 128);">.</span><span style=3D"color: rgb(48, 128, 128)=
;">.</span><span style=3D"color: rgb(64, 96, 128);">;</span>
  InitializeList<span style=3D"color: rgb(48, 128, 128);">(</span>lst<span =
style=3D"color: rgb(48, 128, 128);">)</span><span style=3D"color: rgb(64, 9=
6, 128);">;</span>
  <span style=3D"color: rgb(32, 0, 128); font-weight: bold;">auto</span> th=
ing <span style=3D"color: rgb(48, 128, 128);">=3D</span> <span style=3D"col=
or: rgb(0, 102, 238);">std</span><span style=3D"color: rgb(64, 96, 128);">:=
:</span>make_unique<span style=3D"color: rgb(64, 96, 128);">&lt;</span>Thin=
g<span style=3D"color: rgb(64, 96, 128);">&gt;</span><span style=3D"color: =
rgb(48, 128, 128);">(</span><span style=3D"color: rgb(0, 102, 238);">std</s=
pan><span style=3D"color: rgb(64, 96, 128);">::</span>f<wbr>inal_reference<=
span style=3D"color: rgb(48, 128, 128);">(</span>lst<span style=3D"color: r=
gb(48, 128, 128);">)</span><span style=3D"color: rgb(48, 128, 128);">)</spa=
n><span style=3D"color: rgb(64, 96, 128);">;</span>
  ReuseListForOtherPurpose<span style=3D"color: rgb(48, 128, 128);">(</span=
>lst<span style=3D"color: rgb(48, 128, 128);">)</span><span style=3D"color:=
 rgb(64, 96, 128);">;</span>  <span style=3D"color: rgb(89, 89, 121);">// E=
rror: use of &quot;lst&quot; after final_reference</span>
  <span style=3D"color: rgb(32, 0, 128); font-weight: bold;">return</span> =
thing<span style=3D"color: rgb(64, 96, 128);">;</span>
<span style=3D"color: rgb(64, 96, 128);">}</span>

</pre></div><div><br></div></div><div><div>This would require a compiler to=
 detect the reuse of &quot;lst&quot; after it&#39;s used in=C2=A0<em>std::f=
inal_reference</em>, and flag an error when &quot;lst&quot; is reused.</div=
><div><br></div><div>An alternative to a blessed function would be a new ke=
yword, e.g. &quot;final_reference&quot;.</div><div><br></div><div>Thoughts?=
 Ideas?</div><div><br></div><div>=C2=A0</div></div><div><div>On Friday, Apr=
il 8, 2016 at 2:46:35 PM UTC-6, <a>barry....@gmail.com</a> wrote:</div></di=
v><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; pad=
ding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1=
px; border-left-style: solid;"><blockquote class=3D"gmail_quote" style=3D"m=
argin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 20=
4, 204); border-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr=
"><div>&gt; If your relocation support can&#39;t even perform relocation in=
 this most simple of cases:<div>=C2=A0</div></div><div><div>=C2=A0</div></d=
iv><div>How does it <em>not</em> handle that case? If std::list has a reloc=
ator, the compiler can just call the relocator in this case:</div><div><fon=
t color=3D"#666600"></font><div><font color=3D"#666600"></font>=C2=A0</div>=
</div><div><font color=3D"#666600"><pre style=3D"background: rgb(246, 248, =
255); color: rgb(0, 0, 32);">  <span style=3D"color: rgb(0, 102, 238);">std=
</span><span style=3D"color: rgb(64, 96, 128);">::</span><span style=3D"col=
or: rgb(0, 48, 96);">list</span><span style=3D"color: rgb(64, 96, 128);">&l=
t;</span>T<span style=3D"color: rgb(64, 96, 128);">&gt;</span> SomeFunc<spa=
n style=3D"color: rgb(48, 128, 128);">(</span><span style=3D"color: rgb(48,=
 128, 128);">)</span> <span style=3D"color: rgb(64, 96, 128);">{</span>
    <span style=3D"color: rgb(0, 102, 238);">std</span><span style=3D"color=
: rgb(64, 96, 128);">::</span><span style=3D"color: rgb(0, 48, 96);">list</=
span><span style=3D"color: rgb(64, 96, 128);">&lt;</span>T<span style=3D"co=
lor: rgb(64, 96, 128);">&gt;</span> lt <span style=3D"color: rgb(48, 128, 1=
28);">=3D</span> <span style=3D"color: rgb(48, 128, 128);">.</span><span st=
yle=3D"color: rgb(48, 128, 128);">.</span><span style=3D"color: rgb(48, 128=
, 128);">.</span>
    <span style=3D"color: rgb(48, 128, 128);">.</span><span style=3D"color:=
 rgb(48, 128, 128);">.</span><span style=3D"color: rgb(48, 128, 128);">.</s=
pan>
    <span style=3D"color: rgb(32, 0, 128); font-weight: bold;">return</span=
> lt<span style=3D"color: rgb(64, 96, 128);">;</span> <span style=3D"color:=
 rgb(89, 89, 121);">// no special syntax needed; compiler calls relocator &=
gt;&gt;list&lt;T&gt;</span>
  <span style=3D"color: rgb(64, 96, 128);">}</span>

</pre></font></div><div><div>=C2=A0</div></div><div>What prevents the compi=
ler from doing this?</div></div></blockquote><div><div>=C2=A0</div></div><d=
iv>As far as I can tell, your proposal doesn&#39;t say anything about this =
case, or about automatic objects at all. Your invocation section only addre=
sses the use-case of &quot;relocating&quot; one pointer to another.=C2=A0</=
div><div><div>=C2=A0</div></div><div>You should take advantage of the feedb=
ack opportunity to improve your proposal. There&#39;s no need to be so defe=
nsive.=C2=A0</div></blockquote></div></blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f92d4647-9aca-4471-bdc2-c7caba2e2128%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f92d4647-9aca-4471-bdc2-c7caba2e2128=
%40isocpp.org</a>.<br />

------=_Part_1120_17427712.1460154651742--
------=_Part_1119_1497625205.1460154651741--

.
