Boost logo

Boost :

Subject: Re: [boost] std::map::find() wrapper
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2011-05-05 06:52:22


Den 05-05-2011 11:00, Olaf van der Spek skrev:
> On Thu, May 5, 2011 at 1:01 AM, Marsh Ray<marsh_at_[hidden]> wrote:
>> Thus, it is better to use optional<T or&> instead of pointers whenever it
>> supplies the required operations.
>
> When auto is available, the disadvantage of boost::optional is minimal.
> It's clear that some people really prefer boost::optional, so find_opt
> or find_optional could be provided as well.

T* has the distict advantage that it is optimally efficient, even though
that optional<T&> might slightly be more type-safe.

Some dislike "naked" pointers in interfaces. I think a good guide line
is that such pointer is always without ownership, and so

   T* foo()

is quite easy to read IMO. No need for another overload. We might as
well take advantage of the fact that pointers are "optional" by default.
There is no need to complicate things.

-Thorsten


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