Boost logo

Boost :

Subject: Re: [boost] std::map::find() wrapper
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-05-05 07:57:47


On Thu, May 5, 2011 at 11:52 AM, Thorsten Ottosen <
thorsten.ottosen_at_[hidden]> wrote:

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

"Some" would be me. A good guideline is always to try to raise the
abstraction level of our programming - Boost.optional
seems to me to do that. The guide you suggest may be a good guide, but it
would be better to avoid the need for a guide
at all - if you can say it in code, say it in code.

>
> 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.
>
>
Surely this could be used as an argument for pointers instead of optionals
for every use of optional. Efficiency
taken to this extent seems like the wrong choice - surely we should write
for clarity first and efficiency second,
iff measurement suggests it's a problem.

- Rob.


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