Boost logo

Boost :

Subject: Re: [boost] [optional] little addition... optional_move_to?
From: Fernando Cacciola (fernando.cacciola_at_[hidden])
Date: 2009-03-04 10:51:15


Hi again,

> Fernando Cacciola wrote:
>> That is, we can't just yet write that as:
>> template<class T, class U> bool optional_assign( T&, optional<U>&& ) ;
>> as we would a few years from now.
>
> Well, we can achieve almost the same in old C++03, by declaring the
> function as a /member/ of optional<T>. I'd suggest naming it
> "optional_move_to", as follows:

On further thinking, if the optional is an lvalue this would do the
right thing but will have the wrong name o)

So, we need "optional_copy_to()" if we want users to explicitely choose
between move vs copy.

Or, probably better, a single [optional_]assign_to() that magically does
one or the other depending on "this" being and lvalue or rvalue reference

Something which, btw, in C++0x can actually be properly overloaded:

   template<class U> bool optional<T>::assign_to( U& ) & ;
   template<class U> bool optional<T>::assign_to( U& ) && ;

This is getting unsurprisingly closer to the initial proposal from Arno :)

The main difference being the usage of a member function instead in
order to leverage move optimizations in current C++.

Cheers

--
Fernando Cacciola
SciSoft Consulting
http://www.scisoft-consulting.com

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