220 31729 <136fc743-bc63-48c8-b1d5-dc4084dd13cf@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Complexities caused by using unique_ptr and move semantics
Date: Fri, 24 Mar 2017 15:25:51 -0700 (PDT)
Lines: 145
Approved: news@gmane.org
Message-ID: <136fc743-bc63-48c8-b1d5-dc4084dd13cf@isocpp.org>
References: <46a85060-631b-49e5-94f3-ab07429d8085@isocpp.org>
 <86aeb556-e0d7-4d68-b553-1b4163461473@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2292_1276201536.1490394351178"
X-Trace: blaine.gmane.org 1490394364 22908 195.159.176.226 (24 Mar 2017 22:26:04 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 24 Mar 2017 22:26:04 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBB35Z23DAKGQEX55AR5A@isocpp.org Fri Mar 24 23:25:59 2017
Return-path: <std-proposals+bncBCEKFTV6ZUMBB35Z23DAKGQEX55AR5A@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f72.google.com ([74.125.83.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBB35Z23DAKGQEX55AR5A@isocpp.org>)
	id 1crXeU-0004Im-SR
	for gclcip-std-proposals@m.gmane.org; Fri, 24 Mar 2017 23:25:47 +0100
Original-Received: by mail-pg0-f72.google.com with SMTP id 79sf4370750pgf.2
        for <gclcip-std-proposals@m.gmane.org>; Fri, 24 Mar 2017 15:25:53 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to: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=LRXvFY0jOFnE3RopgapwHarT/JuX3i5sdPueaHXOzRg=;
        b=r1L9lOkp6mxC0CR1jO1GDbXukr4ljXLC0+MI+0Wdz43JT3BdeOIr277Gk5Uzsf6OtZ
         tl6XsZZv/U0sU2s0dpRlihYbRV7tZv3DtRl9mqgxS2wKxCKrNm7jdVKabfVv+s4Y3KIo
         aG1coAcDTGJNv/ZpVkyl0mwB8A5sJdyOdjYwIc41SGiGlFdtwJnkYXaj5mIyw8VrPTb3
         gEODIs/AImYBVzvKRV9ypQakRA8HQvMVc5keFylUsqB1ToW/BL++d4tjJQeS+FcTpTc8
         PkymBZM8U0/2HlYuJ5mFgRshKM1dmiYyw7UGBWMmbASJPr3goe3iMZivA9fm40eL8Nj3
         uW+g==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to: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=LRXvFY0jOFnE3RopgapwHarT/JuX3i5sdPueaHXOzRg=;
        b=HOjkCgyHfAKLhjjbgmuYc2EbTXaOKHAVWD7wZTY87YHk4U4SNknnmuPUaVFCQtQl4W
         H/I7NaWGyumH6USxro8frReT1BxAudKbddmwhVrSlOv5sUW24KlJfUpCmLO98oQt8rNH
         vUi0Kd1PSJCIjPKCN4Ipasxy/gGoeGmRe6riAp5n+ZywxgTrcBpAqL4hN51wN70kZDyh
         AMH+35gImSFkJDsDYf1Vl5ZRV3HMmxtZytmI0qSC9gDLuqBj3U1WWJycRwdQRYEZymra
         WhfdvokQLn49C4gBRoB/VwDDeY4L0kXr7UdAU49RiF1/d3TrcDoDCK2VKcFKFc5FSovS
         4pzg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to: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=LRXvFY0jOFnE3RopgapwHarT/JuX3i5sdPueaHXOzRg=;
        b=VjSOdayqNxJ709CphoJ5nlkWFLPQZ7/VwsbDgchnGaL4rlGAmogwRTWqT7rFyo243E
         9amLifqXmfUbJ8KPnNTLn79XcML9oFQvRnEBp5o4I9OunxRKqoF6r7JPwYrViYeE6j9N
         2RB3RCbnYnxn6/JBs4HDSzFOeKzSYc94hRWe2g9qQUpv+17oDwgYxZNpeRdFiTBpV461
         JyGMkdy+UIjpJHfJMhVp4hzl99tb5vU0jgs0of7+l5GswEEC53gZEweQfjhbncLJeaqf
         2S3wSjBrzjDHJOG5JnBAaKjSLhZSW3cw3131X3N4T7A5MEiJ4MmkZFQ9HktLhimPLDAm
         AGlg==
X-Gm-Message-State: AFeK/H3FplVcEmKAXPybcQGpLnuto/H0exdWWU+q+/QbMnzotgckIUnZfqnkKUOJrS97aQ==
X-Received: by 10.99.103.71 with SMTP id b68mr3483847pgc.28.1490394352614;
        Fri, 24 Mar 2017 15:25:52 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.43.209 with SMTP id u75ls3332743ota.13.gmail; Fri, 24 Mar
 2017 15:25:51 -0700 (PDT)
X-Received: by 10.157.13.75 with SMTP id 69mr1048556oti.3.1490394351688;
        Fri, 24 Mar 2017 15:25:51 -0700 (PDT)
In-Reply-To: <86aeb556-e0d7-4d68-b553-1b4163461473@isocpp.org>
X-Original-Sender: jmckesson@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: <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:31729
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/31729>

------=_Part_2292_1276201536.1490394351178
Content-Type: multipart/alternative; 
	boundary="----=_Part_2293_1425852513.1490394351178"

------=_Part_2293_1425852513.1490394351178
Content-Type: text/plain; charset=UTF-8

On Friday, March 24, 2017 at 5:57:11 PM UTC-4, Sean Middleditch wrote:
>
> On Thursday, March 23, 2017 at 9:38:19 AM UTC-7, Matthew Fioravante wrote:
>>
>> 1. Its too easy to accidentally use a moved from object by mistake
>>
>
> This is a problem with C++'s move semantics (e.g., non-destructive move 
> and unspecific states). These problems have been discussed plenty of times 
> before, particularly in destructive-move threads.
>
> One solution in the works may be contract programming. Some of the 
> proposals allow a function to set a post-condition state on an object which 
> can be verified by a compiler or static analysis in a pre-condition. e.g., 
> unique_ptr might have something like:
>
>   [[post_condition(src): empty]
>   unique_ptr(unique_ptr&& src);
>
>   [[pre_condition(this): !empty]
>   unique_ptr::operator->();
>
> Such a setup can further hypothetically address other issues like 
> accidental dereferencing of default-constructed unique_ptrs. As well as a 
> wide host of other issues.
>  
>
>> 2. unique_ptr<T> and T* being different types can cause pessimizations 
>> because of language rules.
>>
>
> I personally most see this as a problem caused by a lack of generators, or 
> more specifically at the lack of range concepts (which of course are in the 
> works).
>
> You usually don't want to require specifically a vector nor specifically a 
> pointer of any kind. You want to return an object that can be enumerated to 
> produce references to T objects. The vector itself or unique_ptr vs raw 
> pointers is an implementation detail that callers should not have to care 
> about.
>
> With range concepts, this all still has to be a template of course, but 
> you don't have to over-worry about the specifics while using the interface.
>
> With generators, this can be abstracted without templates (though perhaps 
> at a runtime cost).
>
> Basically, you want to write something like:
>
>   iterable<T&> foo::get_things() { return make_iterable(_things, [](auto& 
> p){ return *p; }); }
>
>
That's a really bad tradeoff: type-erasing performance plus the cost of 
filtering, all just to gain some increased genericity. 

But Boost.Range already has something like this: `any_range 
<http://www.boost.org/doc/libs/1_63_0/libs/range/doc/html/range/reference/ranges/any_range.html>`, 
coupled with transforming the input range by a function 
<http://www.boost.org/doc/libs/1_63_0/libs/range/doc/html/range/reference/adaptors/reference/transformed.html>
..

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/136fc743-bc63-48c8-b1d5-dc4084dd13cf%40isocpp.org.

------=_Part_2293_1425852513.1490394351178
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Friday, March 24, 2017 at 5:57:11 PM UTC-4, Sean Middle=
ditch wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">O=
n Thursday, March 23, 2017 at 9:38:19 AM UTC-7, Matthew Fioravante wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-=
left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">1. Its too easy to a=
ccidentally use a moved from object by mistake<br></div></blockquote><div><=
br></div><div>This is a problem with C++&#39;s move semantics (e.g., non-de=
structive move and unspecific states). These problems have been discussed p=
lenty of times before, particularly in destructive-move threads.</div><div>=
<br></div><div>One solution in the works may be contract programming. Some =
of the proposals allow a function to set a post-condition state on an objec=
t which can be verified by a compiler or static analysis in a pre-condition=
.. e.g., unique_ptr might have something like:</div><div><br></div><div>=C2=
=A0 [[post_condition(src): empty]</div><div>=C2=A0 unique_ptr(unique_ptr&am=
p;&amp; src);</div><div><br></div><div>=C2=A0 [[pre_condition(this): !empty=
]</div><div>=C2=A0 unique_ptr::operator-&gt;();</div><div><br></div><div>Su=
ch a setup can further hypothetically address other issues like accidental =
dereferencing of default-constructed unique_ptrs. As well as a wide host of=
 other issues.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr"><div>2. unique_ptr&lt;T&gt; and T* being different types=
 can cause pessimizations because of language rules.</div></div></blockquot=
e><div><br></div><div>I personally most see this as a problem caused by a l=
ack of generators, or more specifically at the lack of range concepts (whic=
h of course are in the works).</div><div><br></div><div>You usually don&#39=
;t want to require specifically a vector nor specifically a pointer of any =
kind. You want to return an object that can be enumerated to produce refere=
nces to T objects. The vector itself or unique_ptr vs raw pointers is an im=
plementation detail that callers should not have to care about.</div><div><=
br></div><div>With range concepts, this all still has to be a template of c=
ourse, but you don&#39;t have to over-worry about the specifics while using=
 the interface.</div><div><br></div><div>With generators, this can be abstr=
acted without templates (though perhaps at a runtime cost).</div><div><br><=
/div><div>Basically, you want to write something like:</div><div><br></div>=
<div>=C2=A0 iterable&lt;T&amp;&gt; foo::get_things() { return make_iterable=
(_things, [](auto&amp; p){ return *p; }); }<br></div><div><br></div><div></=
div></div></blockquote><div><br>That&#39;s a really bad tradeoff: type-eras=
ing performance plus the cost of filtering, all just to gain some increased=
 genericity. <br><br>But Boost.Range already has something like this: `<a h=
ref=3D"http://www.boost.org/doc/libs/1_63_0/libs/range/doc/html/range/refer=
ence/ranges/any_range.html">any_range</a>`, coupled with <a href=3D"http://=
www.boost.org/doc/libs/1_63_0/libs/range/doc/html/range/reference/adaptors/=
reference/transformed.html">transforming the input range by a function</a>.=
<br></div></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/136fc743-bc63-48c8-b1d5-dc4084dd13cf%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/136fc743-bc63-48c8-b1d5-dc4084dd13cf=
%40isocpp.org</a>.<br />

------=_Part_2293_1425852513.1490394351178--

------=_Part_2292_1276201536.1490394351178--

.
