|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-02-08 11:37:41
Daniel Wallin <dalwan01_at_[hidden]> writes:
> David Abrahams wrote:
>> The example below shows a technique for perfect forwarding that seems
>> to work with GCC 3.3.1. rvalues are always moved automatically, and
>> lvalues are copied.
>
> Like Brian I don't understand how this solves perfect forwarding.
>
>> Except for one rather important case, it works with Comeau (errors
>> only in strict mode). The important case that causes the error
>> clearly violates 12.2/1 of the standard, but see below.
>> <snip>
>> 12.2/1 says that the act of binding an rvalue to a (const) reference
>> creates a temporary (which may be elided). The creation of the
>> temporary requires the existence of a copy ctor with a const&
>> argument. As far as I know, that rule serves no useful purpose, but I
>> may have missed something. *If* my example actually works other than
>> this case, I'd like to try to get the rule lifted, and soon! This is
>> by no means the cleanest route to move semantics, but it's probably
>> the smallest "language extension" we'd ever need to get it, and might
>> even be possible before C++0x
>
> Isn't this the same rule that crippled Andrei's Mojo as well? The
> technique is basically the same, except he had something like:
>
> X(X&) // copy
> X(constant_ref<X>) // copy
> X(rvalue_ref<X>) // move
>
> IIRC this also worked on everything, except when binding rvalues to
> const&.
Sure, but the problem with Andrei's thing, IIRC, was that it was
intrusive on *users* of X. If you wanted to accept an X and be able
to move from it, you had to have an overload for rvalue_ref<X>. In
this case, the class provides moving from rvalues all by itself.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk