
----- Original Message -----
From: Olaf van der Spek <ml@vdspek.org> To: boost@lists.boost.org 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@yahoo.com> 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().