Boost logo

Boost :

Subject: Re: [boost] [optional] little addition - Number of numbers in MIME From exceeds maximum threshold
From: Fernando Cacciola (fernando.cacciola_at_[hidden])
Date: 2009-03-04 07:33:57


Hi Arno,

>>> I'm normally against obscure functions that are meant to save a few
>>> keystrokes. OTOH, while the verbose alternative is perfectly clear and I
>>> wouldn't even consider searching for a shortcut, this particular
>>> shortcut looks clear enough to justify it.
>>>
>>> So, Arno: don't you agree swap is better?
>
>> Would a function like optional<T>::swap_if_initialized(T&) indeed be the
>> preferable one for Arno's use case? It isn't yet entirely clear to me,
>> as it seems that Arno would like to have an implicit conversion, while
>> passing the value from optional<T> to its target.
>
> Sorry for not responding earlier. I don't see how my use case is special
> over regular assignment,

Conceptually, it isn't of course.

> apart from the fact that the
> assignment is conditional.

And which the choice of function name makes it crystal clear.

> Like for any assignment, move optimization
> is certainly appreciated, and my use cases are indeed r-value assignments.
>

Right, except for the fact that move facilities are well known by now
but still waiting around the corner to be used.

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.

swap() OTOH, being conceptually a cross move operation, has been doing
move optimizations on a per-type basis since C++98.

So, from the practical POV of what can be programmed today, swap() has
the potential to move-optimize for free.

Having said that, as Neils noted, optional_assign() can perform
conversions, which has value on itself. So I would in favor of adding
both optional_assign and optional_swap.

Best

--
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