Boost logo

Boost :

From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2004-02-08 13:19:47


David Abrahams wrote:
> Daniel Wallin <dalwan01_at_[hidden]> writes:
>>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.

In quite sure this isn't right. AFAICT the only thing that differs in
the two solutions is how you discriminate const lvalues from rvalues.
Andrei did it with two auto_ptr_ref style conversion operators, you do
it with a templated constructor.

With Mojo you would do something like:

   struct X : moveable<X>
   {
       X(X&);
       X(constant_ref<X>);
       X(rvalue_ref<X>); // move constructor
   };

And it would always move from rvalues. The intrusive part was that to
solve the whole "binding rvalues to const&" problem you needed to return
some special wrapper type:

   moved<X> f();

-- 
Daniel Wallin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk