Boost logo

Boost :

From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2004-02-09 12:18:45


David Abrahams wrote:
> Daniel Wallin <dalwan01_at_[hidden]> writes:
>
>
>>>One thing I think we overlooked in the move proposal, though, is the
>>>fact that "only movable and not copyable" class rvalues *still* can't
>>>legally be passed where a const reference is expected, unless the rule
>>>in question is lifted. That seems like a problem to me.
>>
>>That is true if the class would declare regular move constructors with
>>rvalue references. But doesn't the trick used to implement move_ptr
>>apply with the new rvalue references as well? (moving with const&
>>constructor)
>>
>> http://tinyurl.com/3f6sw
>>
>> X x;
>> X y(static_cast<X&&>(x)); // should bind to X(X const&) and not
>> // generate an error?
>>
>>So technically the rule doesn't need to be lifted if we get rvalue
>>references.
>
>
> OK, you're right.
> But that's really awful. :(.

Yeah it would be best if the rule could be lifted, but it isn't really
*that* bad:

   template<class T, class U>
   struct enable_only_move;

   template<class T>
   struct enable_only_move<T, const T>
   {
       typedef typename T::error type;
   };

   template<class T>
   struct enable_only_move<T, T>
   {
       typedef int type;
   };

   // only movable
   class X
   {
   public:
       X() {}
       X(X const&) {}
       X& operator=(X) {}

   private:
       template<class U>
       X(U&, typename enable_only_move<X, U>::type = 0);
   };

-- 
Daniel Wallin

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