|
Boost : |
Subject: Re: [boost] std::map::find() wrapper
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-05-03 12:57:39
On Wed, Apr 20, 2011 at 2:54 PM, Olaf van der Spek <ml_at_[hidden]> wrote:
> Hi,
>
> I've written a small wrapper for std::map::find() (and map-like
> containers/ranges) that returns a pointer to the value if found (or
> NULL if not found).
>
> See https://svn.boost.org/trac/boost/ticket/5227
>
> The advantage is that you don't need the container type name (for
> ::reference), you can initialize the pointer inside an if condition,
> you don't have to compare against ::end() and you don't have to use
> ->second.
>
I'd prefer to see it return a boost::optional<T&>
For containers of pointers to objects, the wrapper could do an
> additional dereference.
>
>
Not a good idea, it's easier to compose than decompose so return a
boost::optional<T*&> and the user deref if they want to.
- Rob.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk