Topic: How about std::rref()?


Author: euloanty@live.com
Date: Sun, 9 Feb 2014 03:22:38 -0800 (PST)
Raw View
------=_Part_2432_28548347.1391944958182
Content-Type: text/plain; charset=UTF-8

Today I make my first asio program. So I'm very happy.
However, suddenly I found that maybe C++ RAII still have difficulties.

#define ASIO_STANDALONE
#define _WIN32_WINDOWS 0x400
#include<asio.hpp>
#include<exception>
#include<cstdio>
#include<future>
#include<functional>

asio::io_service sev;
asio::ip::tcp::acceptor
acc(sev,asio::ip::tcp::endpoint(asio::ip::tcp::v4(),1000));

std::string info(65536,'0');


void async_write(asio::ip::tcp::socket soc)   //I want to move an object
to this function to let this function manage its resources.
{
  asio::error_code ign_err;
  asio::write(soc,asio::buffer(info),ign_err);
}
int main()
{
 try
 {
  for(;;)
  {
   asio::ip::tcp::socket socket(sev);
   acc.accept(socket);
   std::async(async_write,std::move(socket));//It can't be compiled.
  }
 }
 catch(std::exception &ex)
 {
  fputs(ex.what(),stderr);
 }
 return 0;
}


std::async(async_write,std::move(socket));//It can't be compiled.

So, do we need std::rref() to make this things true?
I mean:
std::async(async_write,std::rref(std::move(socket)));

--

---
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/.

------=_Part_2432_28548347.1391944958182
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Today I make&nbsp;my first&nbsp;asio program. So I'm =
very&nbsp;happy.</div><div>However, suddenly I found that maybe&nbsp;C++&nb=
sp;RAII still have difficulties.</div><div><br></div><div>#define ASIO_STAN=
DALONE<br>#define _WIN32_WINDOWS 0x400<br>#include&lt;asio.hpp&gt;<br>#incl=
ude&lt;exception&gt;<br>#include&lt;cstdio&gt;<br>#include&lt;future&gt;<br=
>#include&lt;functional&gt;</div><p>asio::io_service sev;<br>asio::ip::tcp:=
:acceptor acc(sev,asio::ip::tcp::endpoint(asio::ip::tcp::v4(),1000));</p><p=
>std::string info(65536,'0');</p><p><br>void async_write(asio::ip::tcp::soc=
ket soc)&nbsp;&nbsp; //I want to move an object to&nbsp;this function to le=
t this function manage its resources.<br>{<br>&nbsp;&nbsp;asio::error_code =
ign_err;<br>&nbsp;&nbsp;asio::write(soc,asio::buffer(info),ign_err);<br>}</=
p><div>int main()<br>{<br>&nbsp;try<br>&nbsp;{<br>&nbsp;&nbsp;for(;;)<br>&n=
bsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;asio::ip::tcp::socket socket(sev);<br>&nbs=
p;&nbsp;&nbsp;acc.accept(socket);<br>&nbsp;&nbsp;&nbsp;std::async(async_wri=
te,std::move(socket));//It can't be compiled.<br>&nbsp;&nbsp;}<br>&nbsp;}<b=
r>&nbsp;catch(std::exception &amp;ex)<br>&nbsp;{<br>&nbsp;&nbsp;fputs(ex.wh=
at(),stderr);<br>&nbsp;}<br>&nbsp;return 0;<br>}</div><div><br></div><div><=
br></div><div>std::async(async_write,std::move(socket));//It can't be compi=
led.</div><div><br></div><div>So, do we need std::rref() to make this thing=
s true?</div><div>I mean:</div><div>std::async(async_write,std::rref(std::m=
ove(socket)));</div></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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2432_28548347.1391944958182--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Sun, 9 Feb 2014 13:08:16 +0100
Raw View
2014-02-09  <euloanty@live.com>:
> Today I make my first asio program. So I'm very happy.
> However, suddenly I found that maybe C++ RAII still have difficulties.
>
> #define ASIO_STANDALONE
> #define _WIN32_WINDOWS 0x400
> #include<asio.hpp>
> #include<exception>
> #include<cstdio>
> #include<future>
> #include<functional>
>
> asio::io_service sev;
> asio::ip::tcp::acceptor
> acc(sev,asio::ip::tcp::endpoint(asio::ip::tcp::v4(),1000));
>
> std::string info(65536,'0');
>
> void async_write(asio::ip::tcp::socket soc)   //I want to move an object to
> this function to let this function manage its resources.
> {
>   asio::error_code ign_err;
>   asio::write(soc,asio::buffer(info),ign_err);
> }
>
> int main()
> {
>  try
>  {
>   for(;;)
>   {
>    asio::ip::tcp::socket socket(sev);
>    acc.accept(socket);
>    std::async(async_write,std::move(socket));//It can't be compiled.
>   }
>  }
>  catch(std::exception &ex)
>  {
>   fputs(ex.what(),stderr);
>  }
>  return 0;
> }
>
>
> std::async(async_write,std::move(socket));//It can't be compiled.
>
> So, do we need std::rref() to make this things true?

No, std::reference_wrapper was carefully designed *not* to allow to
bind to temporaries. Your proposal would essentially conflict with
that policy.

I also don't see any advantage of adding rref, because std::async is
required to accept MoveConstructible arguments. It is possible that
the version of async that you are using has not properly implemented
the resolution of

http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2021

but that is just a guess.

- Daniel

--

---
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/.

.


Author: euloanty@live.com
Date: Sun, 9 Feb 2014 17:02:17 -0800 (PST)
Raw View
------=_Part_2853_11448364.1391994137340
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

No conflict with that policy.=20
For std::rref will not bind to that object. It will own the object(by=20
moving the object from the original function) and then move the object to=
=20
another function (in this example is async_write).

=E5=9C=A8 2014=E5=B9=B42=E6=9C=889=E6=97=A5=E6=98=9F=E6=9C=9F=E6=97=A5UTC+8=
=E4=B8=8B=E5=8D=888=E6=97=B608=E5=88=8616=E7=A7=92=EF=BC=8CDaniel Kr=C3=BCg=
ler=E5=86=99=E9=81=93=EF=BC=9A
>
> 2014-02-09  <eulo...@live.com <javascript:>>:=20
> > Today I make my first asio program. So I'm very happy.=20
> > However, suddenly I found that maybe C++ RAII still have difficulties.=
=20
> >=20
> > #define ASIO_STANDALONE=20
> > #define _WIN32_WINDOWS 0x400=20
> > #include<asio.hpp>=20
> > #include<exception>=20
> > #include<cstdio>=20
> > #include<future>=20
> > #include<functional>=20
> >=20
> > asio::io_service sev;=20
> > asio::ip::tcp::acceptor=20
> > acc(sev,asio::ip::tcp::endpoint(asio::ip::tcp::v4(),1000));=20
> >=20
> > std::string info(65536,'0');=20
> >=20
> > void async_write(asio::ip::tcp::socket soc)   //I want to move an objec=
t=20
> to=20
> > this function to let this function manage its resources.=20
> > {=20
> >   asio::error_code ign_err;=20
> >   asio::write(soc,asio::buffer(info),ign_err);=20
> > }=20
> >=20
> > int main()=20
> > {=20
> >  try=20
> >  {=20
> >   for(;;)=20
> >   {=20
> >    asio::ip::tcp::socket socket(sev);=20
> >    acc.accept(socket);=20
> >    std::async(async_write,std::move(socket));//It can't be compiled.=20
> >   }=20
> >  }=20
> >  catch(std::exception &ex)=20
> >  {=20
> >   fputs(ex.what(),stderr);=20
> >  }=20
> >  return 0;=20
> > }=20
> >=20
> >=20
> > std::async(async_write,std::move(socket));//It can't be compiled.=20
> >=20
> > So, do we need std::rref() to make this things true?=20
>
> No, std::reference_wrapper was carefully designed *not* to allow to=20
> bind to temporaries. Your proposal would essentially conflict with=20
> that policy.=20
>
> I also don't see any advantage of adding rref, because std::async is=20
> required to accept MoveConstructible arguments. It is possible that=20
> the version of async that you are using has not properly implemented=20
> the resolution of=20
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2021=20
>
> but that is just a guess.=20
>
> - Daniel=20
>

--=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/.

------=_Part_2853_11448364.1391994137340
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">No conflict with that policy. <br>For std::rref will not b=
ind to that object. It will&nbsp;own the object(by moving the object from t=
he&nbsp;original function)&nbsp;and then move the object to another functio=
n (in this example is async_write).<br><br>=E5=9C=A8 2014=E5=B9=B42=E6=9C=
=889=E6=97=A5=E6=98=9F=E6=9C=9F=E6=97=A5UTC+8=E4=B8=8B=E5=8D=888=E6=97=B608=
=E5=88=8616=E7=A7=92=EF=BC=8CDaniel Kr=C3=BCgler=E5=86=99=E9=81=93=EF=BC=9A=
<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; paddi=
ng-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px=
; border-left-style: solid;">2014-02-09 &nbsp;&lt;<a onmousedown=3D"this.hr=
ef=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:';retur=
n true;" href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"Ft=
Wbnzbdf58J">eulo...@live.com</a>&gt;:
<br>&gt; Today I make my first asio program. So I'm very happy.
<br>&gt; However, suddenly I found that maybe C++ RAII still have difficult=
ies.
<br>&gt;
<br>&gt; #define ASIO_STANDALONE
<br>&gt; #define _WIN32_WINDOWS 0x400
<br>&gt; #include&lt;asio.hpp&gt;
<br>&gt; #include&lt;exception&gt;
<br>&gt; #include&lt;cstdio&gt;
<br>&gt; #include&lt;future&gt;
<br>&gt; #include&lt;functional&gt;
<br>&gt;
<br>&gt; asio::io_service sev;
<br>&gt; asio::ip::tcp::acceptor
<br>&gt; acc(sev,asio::ip::tcp::<wbr>endpoint(asio::ip::tcp::v4(),<wbr>1000=
));
<br>&gt;
<br>&gt; std::string info(65536,'0');
<br>&gt;
<br>&gt; void async_write(asio::ip::tcp::<wbr>socket soc) &nbsp; //I want t=
o move an object to
<br>&gt; this function to let this function manage its resources.
<br>&gt; {
<br>&gt; &nbsp; asio::error_code ign_err;
<br>&gt; &nbsp; asio::write(soc,asio::buffer(<wbr>info),ign_err);
<br>&gt; }
<br>&gt;
<br>&gt; int main()
<br>&gt; {
<br>&gt; &nbsp;try
<br>&gt; &nbsp;{
<br>&gt; &nbsp; for(;;)
<br>&gt; &nbsp; {
<br>&gt; &nbsp; &nbsp;asio::ip::tcp::socket socket(sev);
<br>&gt; &nbsp; &nbsp;acc.accept(socket);
<br>&gt; &nbsp; &nbsp;std::async(async_write,std::<wbr>move(socket));//It c=
an't be compiled.
<br>&gt; &nbsp; }
<br>&gt; &nbsp;}
<br>&gt; &nbsp;catch(std::exception &amp;ex)
<br>&gt; &nbsp;{
<br>&gt; &nbsp; fputs(ex.what(),stderr);
<br>&gt; &nbsp;}
<br>&gt; &nbsp;return 0;
<br>&gt; }
<br>&gt;
<br>&gt;
<br>&gt; std::async(async_write,std::<wbr>move(socket));//It can't be compi=
led.
<br>&gt;
<br>&gt; So, do we need std::rref() to make this things true?
<br>
<br>No, std::reference_wrapper was carefully designed *not* to allow to
<br>bind to temporaries. Your proposal would essentially conflict with
<br>that policy.
<br>
<br>I also don't see any advantage of adding rref, because std::async is
<br>required to accept MoveConstructible arguments. It is possible that
<br>the version of async that you are using has not properly implemented
<br>the resolution of
<br>
<br><a onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F=
%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Flwg-defects.html%232021\4=
6sa\75D\46sntz\0751\46usg\75AFQjCNGbEyci1bV3xvob_G9xpc5MBRnQvA';return true=
;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fwww.o=
pen-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Flwg-defects.html%232021\46sa\75D\=
46sntz\0751\46usg\75AFQjCNGbEyci1bV3xvob_G9xpc5MBRnQvA';return true;" href=
=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2021" targ=
et=3D"_blank">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/lwg-defects.=
<wbr>html#2021</a>
<br>
<br>but that is just a guess.
<br>
<br>- Daniel
<br></blockquote></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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2853_11448364.1391994137340--

.


Author: David Krauss <potswa@gmail.com>
Date: Mon, 10 Feb 2014 09:43:02 +0800
Raw View
--Apple-Mail=_C915B3E9-014E-4B88-A8EF-E8CC74550BCC
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On Feb 10, 2014, at 9:02 AM, euloanty@live.com wrote:

> No conflict with that policy.=20
> For std::rref will not bind to that object. It will own the object(by mov=
ing the object from the original function) and then move the object to anot=
her function (in this example is async_write).

That wouldn't be a reference, then, but a container. Anyway, that semantic =
is what the linked DR specifies.

Below is my implementation of rref. I've only used it in a few cases, none =
of which survived refactoring. The potential for abuse probably makes it so=
mething better left in the personal toolboxes of power users.

It happily lives inside a bind object. The constructor takes an lvalue refe=
rence because the wrapper object is designed to persist, so it should not w=
rap a temporary. Currently C++ cannot express temporary-only classes, but I=
 would leave it to a variant in such a category to wrap temporaries (can't =
think of a use case, though).

The getter functions effectively require it to be passed to an actual rvalu=
e reference parameter; it will not implicitly convert to a prvalue. This pr=
etty well guarantees that the receiver expects move semantics, despite no s=
td::move ever being specified.

template< typename t >
struct rvalue_reference_wrapper : std::reference_wrapper< t > {
 rvalue_reference_wrapper( t &o ) : std::reference_wrapper< t >( o ) {}
 t &&get() const { return static_cast< t && >( std::reference_wrapper< t >:=
:get() ); }
 operator t&& () const { return get(); }
 operator t& () const =3D delete;
};

template< typename t >
rvalue_reference_wrapper< t > rref( t &o ) { return { o }; }

--=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/.

--Apple-Mail=_C915B3E9-014E-4B88-A8EF-E8CC74550BCC
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dus-ascii"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode=
: space; -webkit-line-break: after-white-space;"><br><div><div>On Feb 10, 2=
014, at 9:02 AM, <a href=3D"mailto:euloanty@live.com">euloanty@live.com</a>=
 wrote:</div><br class=3D"Apple-interchange-newline"><blockquote type=3D"ci=
te"><div dir=3D"ltr">No conflict with that policy. <br>For std::rref will n=
ot bind to that object. It will&nbsp;own the object(by moving the object fr=
om the&nbsp;original function)&nbsp;and then move the object to another fun=
ction (in this example is async_write).<br></div></blockquote><div><br></di=
v><div>That wouldn't be a reference, then, but a container. Anyway, that se=
mantic is what the linked DR specifies.</div><div><br></div><div>Below is m=
y implementation of <font face=3D"Courier">rref</font>. I've only used it i=
n a few cases, none of which survived refactoring. The potential for abuse =
probably makes it something better left in the personal toolboxes of power =
users.</div><div><br></div><div>It happily lives inside a&nbsp;<font face=
=3D"Courier">bind</font>&nbsp;object. The constructor takes an lvalue refer=
ence because the wrapper object is designed to persist, so it should not wr=
ap a temporary. Currently C++ cannot express temporary-only classes, but I =
would leave it to a variant in such a category to wrap temporaries (can't t=
hink of a use case, though).</div><div><br></div><div>The getter functions =
effectively require it to be passed to an actual rvalue reference parameter=
; it will not implicitly convert to a prvalue. This pretty well guarantees =
that the receiver expects move semantics, despite no <font face=3D"Courier"=
>std::move</font> ever being specified.</div><div><br></div><div><div><font=
 face=3D"Courier">template&lt; typename t &gt;</font></div><div><font face=
=3D"Courier">struct rvalue_reference_wrapper : std::reference_wrapper&lt; t=
 &gt; {</font></div><div><font face=3D"Courier"><span class=3D"Apple-tab-sp=
an" style=3D"white-space:pre"> </span>rvalue_reference_wrapper( t &amp;o ) =
: std::reference_wrapper&lt; t &gt;( o ) {}</font></div><div><font face=3D"=
Courier"><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>t=
 &amp;&amp;get() const { return static_cast&lt; t &amp;&amp; &gt;( std::ref=
erence_wrapper&lt; t &gt;::get() ); }</font></div><div><font face=3D"Courie=
r"><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>operato=
r t&amp;&amp; () const { return get(); }</font></div><div><font face=3D"Cou=
rier"><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>oper=
ator t&amp; () const =3D delete;</font></div><div><font face=3D"Courier">};=
</font></div><div><font face=3D"Courier"><br></font></div><div><font face=
=3D"Courier">template&lt; typename t &gt;</font></div><div><font face=3D"Co=
urier">rvalue_reference_wrapper&lt; t &gt; rref( t &amp;o ) { return { o };=
 }</font></div><div><br></div></div></div></body></html>

<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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_C915B3E9-014E-4B88-A8EF-E8CC74550BCC--

.


Author: Thomas Koeppe <tkoeppe@google.com>
Date: Sun, 9 Feb 2014 17:43:53 -0800 (PST)
Raw View
------=_Part_465_25972273.1391996633511
Content-Type: text/plain; charset=UTF-8

Do you have an example implementation of "rref"?

--

---
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/.

------=_Part_465_25972273.1391996633511
Content-Type: text/html; charset=UTF-8

<div dir="ltr">Do you have an example implementation of "rref"?</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 email 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="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

------=_Part_465_25972273.1391996633511--

.


Author: euloanty@live.com
Date: Mon, 10 Feb 2014 01:14:21 -0800 (PST)
Raw View
------=_Part_3293_7479919.1392023661849
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

How about this? Maybe a container.

template<typename t>=20
class rvalue_reference_wrapper=20
{=20
    t rrw;=20
public:=20
    rvalue_reference_wrapper(t&& r):rrw(std::move(r)){}=20
    rvalue_reference_wrapper(const rvalue_reference_wrapper&)=3Ddelete;=20
    rvalue_reference_wrapper& operator=3D(const=20
rvalue_reference_wrapper&)=3Ddelete;=20
    rvalue_reference_wrapper(rvalue_reference_wrapper&&)=3Ddefault;=20
    rvalue_reference_wrapper&=20
operator=3D(rvalue_reference_wrapper&&)=3Ddefault;=20
    t&& get(){return std::move(rrw);}=20
    operator t&&(){return std::move(rrw);}=20
};=20
=20
template<typename t>=20
rvalue_reference_wrapper<t> rref(t&& r)=20
{=20
    return rvalue_reference_wrapper<t>(static_cast<t&&>(r));=20
}

=E5=9C=A8 2014=E5=B9=B42=E6=9C=8810=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=80UTC+=
8=E4=B8=8A=E5=8D=889=E6=97=B643=E5=88=8602=E7=A7=92=EF=BC=8CDavid Krauss=E5=
=86=99=E9=81=93=EF=BC=9A
>
>
> On Feb 10, 2014, at 9:02 AM, eulo...@live.com <javascript:> wrote:
>
> No conflict with that policy.=20
> For std::rref will not bind to that object. It will own the object(by=20
> moving the object from the original function) and then move the object to=
=20
> another function (in this example is async_write).
>
>
> That wouldn't be a reference, then, but a container. Anyway, that semanti=
c=20
> is what the linked DR specifies.
>
> Below is my implementation of rref. I've only used it in a few cases,=20
> none of which survived refactoring. The potential for abuse probably make=
s=20
> it something better left in the personal toolboxes of power users.
>
> It happily lives inside a bind object. The constructor takes an lvalue=20
> reference because the wrapper object is designed to persist, so it should=
=20
> not wrap a temporary. Currently C++ cannot express temporary-only classes=
,=20
> but I would leave it to a variant in such a category to wrap temporaries=
=20
> (can't think of a use case, though).
>
> The getter functions effectively require it to be passed to an actual=20
> rvalue reference parameter; it will not implicitly convert to a prvalue.=
=20
> This pretty well guarantees that the receiver expects move semantics,=20
> despite no std::move ever being specified.
>
> template< typename t >
> struct rvalue_reference_wrapper : std::reference_wrapper< t > {
> rvalue_reference_wrapper( t &o ) : std::reference_wrapper< t >( o ) {}
> t &&get() const { return static_cast< t && >( std::reference_wrapper< t=
=20
> >::get() ); }
> operator t&& () const { return get(); }
> operator t& () const =3D delete;
> };
>
> template< typename t >
> rvalue_reference_wrapper< t > rref( t &o ) { return { o }; }
>
>

--=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/.

------=_Part_3293_7479919.1392023661849
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">How about this? Maybe a container.<br><br>template&lt;type=
name t&gt;
<br>class rvalue_reference_wrapper
<br>{
<br>&nbsp;&nbsp;&nbsp; t rrw;
<br>public:
<br>&nbsp;&nbsp;&nbsp; rvalue_reference_wrapper(t&amp;&amp; r):rrw(std::mov=
e(r)){}
<br>&nbsp;&nbsp;&nbsp; rvalue_reference_wrapper(const rvalue_reference_wrap=
per&amp;)=3Ddelete;
<br>&nbsp;&nbsp;&nbsp; rvalue_reference_wrapper&amp; operator=3D(const rval=
ue_reference_wrapper&amp;)=3Ddelete;
<br>&nbsp;&nbsp;&nbsp; rvalue_reference_wrapper(rvalue_reference_wrapper&am=
p;&amp;)=3Ddefault;
<br>&nbsp;&nbsp;&nbsp; rvalue_reference_wrapper&amp; operator=3D(rvalue_ref=
erence_wrapper&amp;&amp;)=3Ddefault;
<br>&nbsp;&nbsp;&nbsp; t&amp;&amp; get(){return std::move(rrw);}
<br>&nbsp;&nbsp;&nbsp; operator t&amp;&amp;(){return std::move(rrw);}
<br>};
<br>&nbsp;<br>template&lt;typename t&gt;
<br>rvalue_reference_wrapper&lt;t&gt; rref(t&amp;&amp; r)
<br>{
<br>&nbsp;&nbsp;&nbsp; return rvalue_reference_wrapper&lt;t&gt;(static_cast=
&lt;t&amp;&amp;&gt;(r));
<br>}<br><br>=E5=9C=A8 2014=E5=B9=B42=E6=9C=8810=E6=97=A5=E6=98=9F=E6=9C=9F=
=E4=B8=80UTC+8=E4=B8=8A=E5=8D=889=E6=97=B643=E5=88=8602=E7=A7=92=EF=BC=8CDa=
vid Krauss=E5=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
 1ex;"><div style=3D"word-wrap:break-word"><br><div><div>On Feb 10, 2014, a=
t 9:02 AM, <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=
=3D"ZFtQKePz1HYJ" onmousedown=3D"this.href=3D'javascript:';return true;" on=
click=3D"this.href=3D'javascript:';return true;">eulo...@live.com</a> wrote=
:</div><br><blockquote type=3D"cite"><div dir=3D"ltr">No conflict with that=
 policy. <br>For std::rref will not bind to that object. It will&nbsp;own t=
he object(by moving the object from the&nbsp;original function)&nbsp;and th=
en move the object to another function (in this example is async_write).<br=
></div></blockquote><div><br></div><div>That wouldn't be a reference, then,=
 but a container. Anyway, that semantic is what the linked DR specifies.</d=
iv><div><br></div><div>Below is my implementation of <font face=3D"Courier"=
>rref</font>. I've only used it in a few cases, none of which survived refa=
ctoring. The potential for abuse probably makes it something better left in=
 the personal toolboxes of power users.</div><div><br></div><div>It happily=
 lives inside a&nbsp;<font face=3D"Courier">bind</font>&nbsp;object. The co=
nstructor takes an lvalue reference because the wrapper object is designed =
to persist, so it should not wrap a temporary. Currently C++ cannot express=
 temporary-only classes, but I would leave it to a variant in such a catego=
ry to wrap temporaries (can't think of a use case, though).</div><div><br><=
/div><div>The getter functions effectively require it to be passed to an ac=
tual rvalue reference parameter; it will not implicitly convert to a prvalu=
e. This pretty well guarantees that the receiver expects move semantics, de=
spite no <font face=3D"Courier">std::move</font> ever being specified.</div=
><div><br></div><div><div><font face=3D"Courier">template&lt; typename t &g=
t;</font></div><div><font face=3D"Courier">struct rvalue_reference_wrapper =
: std::reference_wrapper&lt; t &gt; {</font></div><div><font face=3D"Courie=
r"><span style=3D"white-space:pre"> </span>rvalue_reference_wrapper( t &amp=
;o ) : std::reference_wrapper&lt; t &gt;( o ) {}</font></div><div><font fac=
e=3D"Courier"><span style=3D"white-space:pre"> </span>t &amp;&amp;get() con=
st { return static_cast&lt; t &amp;&amp; &gt;( std::reference_wrapper&lt; t=
 &gt;::get() ); }</font></div><div><font face=3D"Courier"><span style=3D"wh=
ite-space:pre"> </span>operator t&amp;&amp; () const { return get(); }</fon=
t></div><div><font face=3D"Courier"><span style=3D"white-space:pre"> </span=
>operator t&amp; () const =3D delete;</font></div><div><font face=3D"Courie=
r">};</font></div><div><font face=3D"Courier"><br></font></div><div><font f=
ace=3D"Courier">template&lt; typename t &gt;</font></div><div><font face=3D=
"Courier">rvalue_reference_wrapper&lt; t &gt; rref( t &amp;o ) { return { o=
 }; }</font></div><div><br></div></div></div></div></blockquote></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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3293_7479919.1392023661849--

.


Author: Stack Machine <stackmachine@hotmail.com>
Date: Mon, 10 Feb 2014 12:08:41 -0800 (PST)
Raw View
------=_Part_740_17189625.1392062921855
Content-Type: text/plain; charset=UTF-8

The above problem can be solved by simply moving the value and then taking
it by lvalue reference within the functions. You can then later on move it
if you want to. Allthough I have to agree it's a bit unintuitive, I don't
see a problem with that.

--

---
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/.

------=_Part_740_17189625.1392062921855
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The above problem can be solved by simply moving the value=
 and then taking it by lvalue reference within the functions. You can then =
later on move it if you want to. Allthough I have to agree it's a bit unint=
uitive, I don't see a problem with that.<br></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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_740_17189625.1392062921855--

.


Author: David Krauss <potswa@gmail.com>
Date: Tue, 11 Feb 2014 14:32:09 +0800
Raw View
--Apple-Mail=_342EBDDC-BF33-4F76-8DC8-EE55E32D21F0
Content-Type: text/plain; charset=ISO-8859-1

To reiterate, there's no problem in the first place, in a compiler implementing the resolution of DR 2021. The solution is a simple upgrade (or complain to your vendor).

Providing an rvalue argument the to bind or async is incompatible with receiving an lvalue reference argument. Remember that move does nothing by itself and it's generally incorrect to assume ownership of an lvalue reference parameter.

See the DR.

On Feb 11, 2014, at 4:08 AM, Stack Machine <stackmachine@hotmail.com> wrote:

> The above problem can be solved by simply moving the value and then taking it by lvalue reference within the functions. You can then later on move it if you want to. Allthough I have to agree it's a bit unintuitive, I don't see a problem with that.


--

---
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/.

--Apple-Mail=_342EBDDC-BF33-4F76-8DC8-EE55E32D21F0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dus-ascii"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode=
: space; -webkit-line-break: after-white-space;"><div>To reiterate, there's=
 no problem in the first place, in a compiler implementing the resolution o=
f DR 2021. The solution is a simple upgrade (or complain to your vendor).</=
div><div><br></div><div>Providing an rvalue argument the to <font face=3D"C=
ourier">bind</font> or <font face=3D"Courier">async</font>&nbsp;is incompat=
ible with receiving an lvalue reference argument. Remember that <font face=
=3D"Courier">move</font> does nothing by itself and it's generally incorrec=
t to assume ownership of an lvalue reference parameter.</div><div><br></div=
><div>See the DR.</div><br><div><div>On Feb 11, 2014, at 4:08 AM, Stack Mac=
hine &lt;<a href=3D"mailto:stackmachine@hotmail.com">stackmachine@hotmail.c=
om</a>&gt; wrote:</div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"cite"><div dir=3D"ltr">The above problem can be solved by simply mo=
ving the value and then taking it by lvalue reference within the functions.=
 You can then later on move it if you want to. Allthough I have to agree it=
's a bit unintuitive, I don't see a problem with that.<br></div></blockquot=
e><br></div><br></body></html>

<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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_342EBDDC-BF33-4F76-8DC8-EE55E32D21F0--

.