
On Wed, Apr 20, 2011 at 2:54 PM, Olaf van der Spek <ml@vdspek.org> 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.