Boost logo

Boost :

Subject: Re: [boost] [optional] generates unnessesary code for trivial types
From: paul Fultz (pfultz2_at_[hidden])
Date: 2012-02-14 14:52:05

----- Original Message -----
> From: Olaf van der Spek <ml_at_[hidden]>
> To: boost_at_[hidden]
> Cc:
> Sent: Tuesday, February 14, 2012 11:32 AM
> Subject: Re: [boost] [optional] generates unnessesary code for trivial types
> On Tue, Feb 14, 2012 at 5:07 PM, paul Fultz <pfultz2_at_[hidden]> wrote:
>> One disadvantage of using a pointer instead of optional<T&> is
> when I write
>> a functions to serach for an item in a map like this:
>> template<class T, class Map>
>> optional<T&> search_for(Map& m, T& key);
>> Optional lets me call get_value_or() so I can return a value if it cant
> find the key,
>> but using a pointer I can't do that so easily. However, another class
> such as
> Why not?
> get_value_or() for pointers seems trivial.

Except, if T* is going to be used like that, than get_value_or() should be provided
by the library. Still, I think optional<T> as a range is a much more generic solution
to the problem. Its much easier to extend with my own optional types. If optional<T&>
does not give me the semantics I want, I can write my own optional_ref<T> class, and
get_value_or()(or maybe front_or()) will work as long as I provide begin() and end().

Boost list run by bdawes at, gregod at, cpdaniel at, john at