|
Boost : |
Subject: Re: [boost] [SPAM (Header)] - Re: [optional] little addition... optional_assign_to, optional_move_to, optional_swap? - Number of numbers in MIME From exceeds maximum threshold
From: Arno Schödl (aschoedl_at_[hidden])
Date: 2009-03-06 17:41:21
> > Thus, until move semantics are practically usable (whether via
> > Boost.Move or C++0x) I would either add the three functions as member
> > functions, or just your optional_assign() as a free function, but not
> > two members and one free standing.
> >
> > What do you think?
>
> FWIW, my vote would go to your first option, adding
> optional_assign_to(T&), optional_move_to(T&), and optional_swap(T&) as
> member functions to optional<T>. But of course, my name isn't Arno!
I am happy with members. Just for my understanding, why are optional_swap and optional_move_to not expessible as free functions?
template< class T, class U >
bool optional_move( T& t, boost::optional<U>& u ) {
if( u ) {
t=*u;
return true;
} else {
return false;
}
};
template< class T >
bool optional_move( T& t, boost::optional<T>& u ) {
if( u ) {
swap( t, *u );
return true;
} else {
return false;
}
};
{
int i;
boost::optional<int> j=1;
optional_move( i, j ); // swaps
}
{
double i;
boost::optional<int> j=1;
optional_move( i, j ); // assigns with implicit conversion
}
What am I missing?
Arno
-- Dr. Arno Schoedl · aschoedl_at_[hidden] Technical Director think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany http://www.think-cell.com · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091 Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk