220 34435 <69cdd486-c450-4ed9-a807-f8c5535103e2@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: leni536@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Copy eliding emplacement functions for containers.
Date: Wed, 20 Sep 2017 03:23:45 -0700 (PDT)
Lines: 303
Approved: news@gmane.org
Message-ID: <69cdd486-c450-4ed9-a807-f8c5535103e2@isocpp.org>
References: <0144b887-c694-4f3e-b368-32645a1562d9@isocpp.org>
 <CAOfiQqn40HxZtT_zCgH2mzNZ-binpgf3+uULrZLNVGDmwYcgSA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_26_734800998.1505903025345"
X-Trace: blaine.gmane.org 1505903026 1316 195.159.176.226 (20 Sep 2017 10:23:46 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 20 Sep 2017 10:23:46 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDXJR44QUQHBBMUDRHHAKGQEBNS6DIY@isocpp.org Wed Sep 20 12:23:41 2017
Return-path: <std-proposals+bncBDXJR44QUQHBBMUDRHHAKGQEBNS6DIY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f197.google.com ([209.85.192.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDXJR44QUQHBBMUDRHHAKGQEBNS6DIY@isocpp.org>)
	id 1ducAO-0008TF-Fb
	for gclcip-std-proposals@m.gmane.org; Wed, 20 Sep 2017 12:23:40 +0200
Original-Received: by mail-pf0-f197.google.com with SMTP id p9sf873641pfd.15
        for <gclcip-std-proposals@m.gmane.org>; Wed, 20 Sep 2017 03:23:48 -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
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=phFNjH+nX96TXpf0xS4HkpJbQpaDWEl1mIcwTAhZWVw=;
        b=o/2dnZk/4+eJlQ8sO7nKuCZ1SjuJslngQeERvfDipygjm6+egLYS529nBWZbBOoprD
         EqsM+aM5YG6asfTSdr7rQEC/A9yNeG+/wxgXRcIkRZVdrPGsUQ2GUa+S2RcJgPn6XxUY
         qSBKfSrsUT+pfKy62xyM7H3y2JorjpAwCZp8xAGJhrgpTDUQEhUrp3a1japllvsemFo8
         bpJs94W4stsjucfotzB2FDJq7o2KvIXRdyf6ntBM9Tr7sgv4RjweMF3mdRnic5SFSxGw
         FhA9Z+M0hCSBZOXVsKWflhwy2+LLdJyhugri9igvBA6Jn4JgDDKopndhf1UPzTzDxZpy
         VBAw==
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
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=phFNjH+nX96TXpf0xS4HkpJbQpaDWEl1mIcwTAhZWVw=;
        b=ZiNzb46v5fuBkUiuO3cckHXvOZRz8LhFKdVbPbwBBu6DDW3mqGwFhmm66wdv3yzYXS
         aKvbvVFMo65JJldKMjY2gMZCiurMM031EIYqvzFxe4X7RTcTESCmqSQWIh59mxiLlQ87
         4G5zskL/pn2OB1q4dYrRjFwCsp90K1ca23dKGDd9NXivhyi+65lnM+6ECfBroSoLxIJS
         XjceFGXbdaUHd9q4s38Hwc2M9Jsa/pof6PHpaiqJ5ZGPIHBTaexTV6e1jOFbr4HAtpMA
         IjLM7ZtIzcESiUQrWn2E6OrQ5ljCV/t2Yc9GrMLJV/5m49gIBJ1MlgI6HpkXj5cOiFlN
         Z1cw==
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=phFNjH+nX96TXpf0xS4HkpJbQpaDWEl1mIcwTAhZWVw=;
        b=TKW/0L8zmkBG40couAc56DqKOJgUZsp1YduJXj5lq6SM00b+zUMZW6uNuhMJlD0913
         ki4wX7RMLhqDefkGh/StNfT5j9OXUcqNc3CBN2rZjjX1FigTLwZcrRRTna7slyRaISWu
         TiTcqpN9R1xcfNKZOGWZf1V+5yOtiGClvkRgmzyR4R2PKR2ZHSApZoyhMF+B8vVutXWC
         RCFA1CC0yE3abkalBTQaPhQpG5nc00Swt4qdm2CYls/OKBN/dT30VhJs85lUKfhDdvWs
         8LWg0zuLGD3NcCqzT7pBh68vOUyB9VG97vM3RG1GWtmZ9De9cwWVN1V/WXIXN+oXno8Z
         OnXg==
X-Gm-Message-State: AHPjjUh/svOdEDX4r+2WPEfeoY00y1x2xN1AZl8TAqBv7nQPxjkxmZ/O
	5tkXgux6ieNbrkOn19SYIZ+xxQ==
X-Google-Smtp-Source: AOwi7QBtArvE3wXggHLlrL4d+HWgxsD/YbLkMMk5xq+ctfL7jtBJOrwJTXUWsqsAmMzF+sEMxK5qlQ==
X-Received: by 10.99.42.141 with SMTP id q135mr965165pgq.50.1505903027412;
        Wed, 20 Sep 2017 03:23:47 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.150.135 with SMTP id y129ls442864iod.32.gmail; Wed, 20 Sep
 2017 03:23:46 -0700 (PDT)
X-Received: by 10.31.48.2 with SMTP id w2mr17158vkw.2.1505903026008;
        Wed, 20 Sep 2017 03:23:46 -0700 (PDT)
In-Reply-To: <CAOfiQqn40HxZtT_zCgH2mzNZ-binpgf3+uULrZLNVGDmwYcgSA@mail.gmail.com>
X-Original-Sender: leni536@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:34435
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/34435>

------=_Part_26_734800998.1505903025345
Content-Type: multipart/alternative; 
	boundary="----=_Part_27_1012542137.1505903025347"

------=_Part_27_1012542137.1505903025347
Content-Type: text/plain; charset="UTF-8"

On Wednesday, September 20, 2017 at 10:34:13 AM UTC+2, Richard Smith wrote:
>
> On 19 September 2017 at 09:37, <len...@gmail.com <javascript:>> wrote:
>
>> Hi,
>>
>> Guaranteed copy elision in C++17 is pretty great. This way I can simply 
>> return by value in my factory functions. Basically these factory functions 
>> act like external constructors (but not perfectly).
>>
>> #include <memory>
>> extern widget factory();
>>
>> int main() {
>>     auto w1 = widget{ factory() };
>>     auto w2 = new widget{ factory() };
>>     auto w3 = std::unique_ptr<widget>{new widget{ factory() }};
>>
>>     return 0;
>> }
>>
>> Basically all three cases have guaranteed copy elision. It would be nice 
>> if we could put elements from these kind of factory functions into a 
>> container and eliding copying at the same time. Now the only interface for 
>> something like this is the emplace* family of functions, but they only work 
>> with constructors. I suggest a function with the following signature.
>>
>> //for vector
>> template <class Func, class... Args>
>> reference emplace_back_from_function(Func func, Args... args);
>>
>> The container then calls placement new inside somewhere:
>> new(pos) value_type{ func(std::forward<Args>(args)...) };
>> Maybe allocators need an updated interface for it too as placement new 
>> through the indirection of allocator_traits::construct brakes guaranteed 
>> copy elision (I think).
>>
>> This way we could make collections of non-copyable and even non-movable 
>> types as guaranteed copy elision is allowed for these too.
>>
>> std::make_shared could have a std::make_shared_from_function counterpart 
>> too. Maybe there are other parts of the standard library that calls 
>> constructors of user specified types that could make advantage of this.
>>
>> Thoughts?
>>
>
> The above design prevents guaranteed copy elision for arguments of 'func'. 
> Instead, there's an even simpler pattern:
>
> template<typename Func>
> reference emplace_using(Func func);
>
> ... that simply does "new(pos) value_type(func());" to construct the 
> value. However, adding one of those per emplace function seems very 
> heavyweight; it would seem nicer to add a wrapper class template that could 
> be passed to ordinary emplace functions, eg:
>
> vec.emplace_back( emplace_using( [&]{ return factory_function(args); } ) );
>
> where emplace_with is a type that wraps a function and implicitly calls it 
> when needed to convert to the return type of the function:
>
> template<typename Func> struct emplace_using {
>   Func func;
>   emplace_using(Func func) : func(std::move(func)) {}
>   operator decltype(auto)() { return func(); }
> };
>

This is really great. I was working on something similar but then I bumped 
into a compiler problem. Clang++ doesn't seem to do guaranteed copy elision 
when implicit conversion is involved. The following fails to compile on 
clang++

#include <memory>

template <typename Func>
struct emplace_using {
    Func func;
    emplace_using(Func func) : func(std::move(func)) {}
    operator decltype(auto)() { return func(); }
};

struct A {
    A(const A&) = delete;
    A(A&&) = delete;
};

A Afactory() { return A{}; }

int main() {
    auto ptr =
        std::make_unique<A>(emplace_using{[]() { return Afactory(); }});
}

It complains about calling the deleted move constructor. However on g++ it 
compiles it without warnings. A similar problem occurs when the move 
constructor is explicitly delegated from an initializer list. Clang++ 
supposedly supports guaranteed copy elision and indeed it works for simple 
cases.
 

> This almost works... the trouble is that perfect forwarding gets in the 
> way (unsurprisingly, since "perfect" forwarding is imperfect for prvalues). 
> allocator::construct will do
>
>   new (loc) T(forward<Arg>(arg)...)
>
> where we need the argument to the constructor to be a *prvalue* of type T. 
> Possibly we could modify the construction logic to use a mechanism that 
> acts like forward<T> for most Ts, but invokes the wrapped function when T 
> is emplace_using<Fn>.
>

I don't fully comprehend the problem described here, but I'm not too 
experienced with value categories and the quirks of not so perfect 
forwarding. Maybe some examples could help.

-- 
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/69cdd486-c450-4ed9-a807-f8c5535103e2%40isocpp.org.

------=_Part_27_1012542137.1505903025347
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, September 20, 2017 at 10:34:13 AM UTC+2, Ric=
hard Smith wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><div><div class=3D"gmail_quote">On 19 September 2017 at 09:37,  <span d=
ir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mai=
lto=3D"5q2hi_1VAgAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javas=
cript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;retu=
rn true;">len...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex"><div dir=3D"ltr">Hi,<br><br>Guaranteed copy elis=
ion in C++17 is pretty great. This way I=20
can simply return by value in my factory functions. Basically these=20
factory functions act like external constructors (but not perfectly).<br><b=
r><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,=
187);border-style:solid;border-width:1px"><code><div><span style=3D"color:r=
gb(136,0,0)">#include</span><span style=3D"color:rgb(0,0,0)"> </span><span =
style=3D"color:rgb(0,136,0)">&lt;memory&gt;</span><span style=3D"color:rgb(=
0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">extern</span><span st=
yle=3D"color:rgb(0,0,0)"> widget factory</span><span style=3D"color:rgb(102=
,102,0)">();</span><span style=3D"color:rgb(0,0,0)"><br><br></span><span st=
yle=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(0,0,0)"> main=
</span><span style=3D"color:rgb(102,102,0)">()</span><span style=3D"color:r=
gb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span style=
=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0=
,136)">auto</span><span style=3D"color:rgb(0,0,0)"> w1 </span><span style=
=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> widge=
t</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:r=
gb(0,0,0)"> factory</span><span style=3D"color:rgb(102,102,0)">()</span><sp=
an style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">=
};</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> w2 =
</span><span style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:=
rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">new</span><span styl=
e=3D"color:rgb(0,0,0)"> widget</span><span style=3D"color:rgb(102,102,0)">{=
</span><span style=3D"color:rgb(0,0,0)"> factory</span><span style=3D"color=
:rgb(102,102,0)">()</span><span style=3D"color:rgb(0,0,0)"> </span><span st=
yle=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">auto</span><span st=
yle=3D"color:rgb(0,0,0)"> w3 </span><span style=3D"color:rgb(102,102,0)">=
=3D</span><span style=3D"color:rgb(0,0,0)"> std</span><span style=3D"color:=
rgb(102,102,0)">::</span><span style=3D"color:rgb(0,0,0)">unique_ptr</span>=
<span style=3D"color:rgb(0,136,0)">&lt;widget&gt;</span><span style=3D"colo=
r:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,136)">new</span><spa=
n style=3D"color:rgb(0,0,0)"> widget</span><span style=3D"color:rgb(102,102=
,0)">{</span><span style=3D"color:rgb(0,0,0)"> factory</span><span style=3D=
"color:rgb(102,102,0)">()</span><span style=3D"color:rgb(0,0,0)"> </span><s=
pan style=3D"color:rgb(102,102,0)">}};</span><span style=3D"color:rgb(0,0,0=
)"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">return</=
span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,10=
2,102)">0</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D=
"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(102,102,0)">}</span>=
<span style=3D"color:rgb(0,0,0)"><br></span></div></code></div><br>Basicall=
y
 all three cases have guaranteed copy elision. It would be nice if we=20
could put elements from these kind of factory functions into a container
 and eliding copying at the same time. Now the only interface for=20
something like this is the emplace* family of functions, but they only=20
work with constructors. I suggest a function with the following=20
signature.<br><span style=3D"color:rgb(0,0,0)"></span><br><span style=3D"co=
lor:rgb(0,0,0)"></span><div style=3D"background-color:rgb(250,250,250);bord=
er-color:rgb(187,187,187);border-style:solid;border-width:1px"><code><div><=
span style=3D"color:rgb(136,0,0)">//for vector</span><span style=3D"color:r=
gb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">template</span><sp=
an style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">=
&lt;</span><span style=3D"color:rgb(0,0,136)">class</span><span style=3D"co=
lor:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,0,102)">Func</span><sp=
an style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)">=
 </span><span style=3D"color:rgb(0,0,136)">class</span><span style=3D"color=
:rgb(102,102,0)">...</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102,0=
)">&gt;</span><span style=3D"color:rgb(0,0,0)"><br>reference emplace_back_f=
rom_function</span><span style=3D"color:rgb(102,102,0)">(</span><span style=
=3D"color:rgb(102,0,102)">Fun<wbr>c</span><span style=3D"color:rgb(0,0,0)">=
 func</span><span style=3D"color:rgb(102,102,0)">,</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,0,102)">Args</span><spa=
n style=3D"color:rgb(102,102,0)">...</span><span style=3D"color:rgb(0,0,0)"=
> args</span><span style=3D"color:rgb(102,102,0)">);</span><span style=3D"c=
olor:rgb(0,0,0)"><br></span></div></code></div><br>The container then calls=
 placement new inside somewhere:<br><div style=3D"background-color:rgb(250,=
250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px"=
><code><div><span style=3D"color:rgb(0,0,136)">new</span><span style=3D"col=
or:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">pos</span><span=
 style=3D"color:rgb(102,102,0)">)</span><span style=3D"color:rgb(0,0,0)"> v=
alue_type</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D=
"color:rgb(0,0,0)"> func</span><span style=3D"color:rgb(102,102,0)">(</span=
><span style=3D"color:rgb(0,0,0)">std</span><span style=3D"color:rgb(102,10=
2,0)">::</span><span style=3D"color:rgb(0,0,0)">forward</span><span style=
=3D"color:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(102,0,102)">A=
rgs</span><span style=3D"color:rgb(102,102,0)">&gt;(</span><span style=3D"c=
olor:rgb(0,0,0)">args</span><span style=3D"color:rgb(102,102,0)">).<wbr>..)=
</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(10=
2,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br></span></div></code=
></div>Maybe
 allocators need an updated interface for it too as placement new=20
through the indirection of allocator_traits::construct brakes guaranteed
 copy elision (I think).<br><br>This way we could make collections of=20
non-copyable and even non-movable types as guaranteed copy elision is=20
allowed for these too.<br><br>std::make_shared could have a=20
std::make_shared_from_function counterpart too. Maybe there are other=20
parts of the standard library that calls constructors of user specified=20
types that could make advantage of this.<br><br>Thoughts?<br></div></blockq=
uote><div><br></div><div>The above design prevents guaranteed copy elision =
for arguments of &#39;func&#39;. Instead, there&#39;s an even simpler patte=
rn:</div><div><br></div><div>template&lt;typename Func&gt;</div><div>refere=
nce emplace_using(Func func);</div><div><br></div><div>... that simply does=
 &quot;new(pos) value_type(func());&quot; to construct the value. However, =
adding one of those per emplace function seems very heavyweight; it would s=
eem nicer to add a wrapper class template that could be passed to ordinary =
emplace functions, eg:</div><div><br></div><div>vec.emplace_back( emplace_u=
sing( [&amp;]{ return factory_function(args); } ) );</div><div><br></div><d=
iv>where emplace_with is a type that wraps a function and implicitly calls =
it when needed to convert to the return type of the function:</div><div><br=
></div><div><div>template&lt;typename Func&gt; struct emplace_using {</div>=
<div>=C2=A0 Func func;</div><div>=C2=A0 emplace_using(Func func) : func(std=
::move(func)) {}</div><div>=C2=A0 operator decltype(auto)() { return func()=
; }</div><div>};</div></div></div></div></div></blockquote><div><br></div><=
div>This is really great. I was working on something similar but then I bum=
ped into a compiler problem. Clang++ doesn&#39;t seem to do guaranteed copy=
 elision when implicit conversion is involved. The following fails to compi=
le on clang++</div><div><br></div><div>#include &lt;memory&gt;<br><br>templ=
ate &lt;typename Func&gt;<br>struct emplace_using {<br>=C2=A0=C2=A0=C2=A0 F=
unc func;<br>=C2=A0=C2=A0=C2=A0 emplace_using(Func func) : func(std::move(f=
unc)) {}<br>=C2=A0=C2=A0=C2=A0 operator decltype(auto)() { return func(); }=
<br>};<br><br>struct A {<br>=C2=A0=C2=A0=C2=A0 A(const A&amp;) =3D delete;<=
br>=C2=A0=C2=A0=C2=A0 A(A&amp;&amp;) =3D delete;<br>};<br><br>A Afactory() =
{ return A{}; }<br><br>int main() {<br>=C2=A0=C2=A0=C2=A0 auto ptr =3D<br>=
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 std::make_unique&lt;A&gt;(emplace_usi=
ng{[]() { return Afactory(); }});</div><div>}</div><div><br></div><div>It c=
omplains about calling the deleted move constructor. However on g++ it comp=
iles it without warnings. A similar problem occurs when the move constructo=
r is explicitly delegated from an initializer list. Clang++ supposedly supp=
orts guaranteed copy elision and indeed it works for simple cases.<br></div=
><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><div><div class=3D"gmail_quote"><div>This almost works... the trouble =
is that perfect forwarding gets in the way (unsurprisingly, since &quot;per=
fect&quot; forwarding is imperfect for prvalues). allocator::construct will=
 do</div><div><br></div><div>=C2=A0 new (loc) T(forward&lt;Arg&gt;(arg)...)=
</div><div><br></div><div>where we need the argument to the constructor to =
be a *prvalue* of type T. Possibly we could modify the construction logic t=
o use a mechanism that acts like forward&lt;T&gt; for most Ts, but invokes =
the wrapped function when T is emplace_using&lt;Fn&gt;.</div></div></div></=
div></blockquote><div><br></div><div>I don&#39;t fully comprehend the probl=
em described here, but I&#39;m not too experienced with value categories an=
d the quirks of not so perfect forwarding. Maybe some examples could help.<=
/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/69cdd486-c450-4ed9-a807-f8c5535103e2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/69cdd486-c450-4ed9-a807-f8c5535103e2=
%40isocpp.org</a>.<br />

------=_Part_27_1012542137.1505903025347--

------=_Part_26_734800998.1505903025345--

.
