|
Boost : |
From: Rani Sharoni (rani_sharoni_at_[hidden])
Date: 2004-01-20 13:25:23
Bronek Kozicki wrote:
> Peter Dimov <pdimov_at_[hidden]> wrote:
>> sink( pi ); // error, possibly unintended transfer
>> sink( move(pi) ); // OK, Howard's preferred
>> sink( pi.move() ); // I kind of like it better but it's not
>
> I just came to this idea before reading your post :>
> Small changes to move_ptr implementation will make it work:
> move_ptr move()
> {return move_ptr(*this);}
>
> template <class U>
> friend move_ptr<U> move(move_ptr<U>& p)
> {return p;}
The template part is not necessary due to ADL but you should make such
function available via ordinary lookup (i.e. boost::move) so you are back to
template.
How about the following non-intrusive yet sufficient implementation:
template <class U>
move_ptr<U> move(move_ptr<U>& p)
{ return 1 ? p : move_ptr<U>(); }
It actually works but I'm just kidding because not all compilers agree on
that.
Rani
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk