
On Tue, May 3, 2011 at 8:52 PM, Olaf van der Spek <ml@vdspek.org> wrote:
On Tue, May 3, 2011 at 6:57 PM, Robert Jones <robertgbjones@gmail.com> wrote:
I'd prefer to see it return a boost::optional<T&>
What's the benefit?
Simply that the difficulty you're addressing is the possibility that there's no value to return. Boost.optional expresses that directly.
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.
What problem would that avoid? It'd require the user to do an additional check.
But you'd lose some flexibility. If you return a reference or copy of the pointed-to object you cannot then change the pointer itself, whereas if you return a reference to the pointer you could. It's also a special case, which is best avoided if possible, that doesn't seem to offer any real benefit. - Rob.