Boost logo

Boost :

Subject: Re: [boost] std::map::find() wrapper
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-05-04 09:08:58

Olaf van der Spek wrote:
> On Wed, May 4, 2011 at 2:37 PM, Rob Riggs <rob_at_[hidden]>
> wrote:
> > One of the hallmarks of modern C++ programming is the absence
> > of bare pointers. We have iterators, smart pointers and
> > pointer containers to manage and hide pointers for us. We
> > have a healthy distrust of bare pointers because they are so
> > easily misused.
> I'm not sure what your code looks like, but IMO bare pointers
> are perfectly fine in certain situations.
> Like this one, where no ownership issues are present.

A function that returns a pointer immediately begs the question of ownership. It is perfectly reasonable to think that one should call delete on such a pointer when finished with it. That, of course, would have nasty consequences, but it is the result of returning a pointer.

Returning a boost::optional with a reference to the element conveys two things. First, the reference clearly indicates that the container maintains ownership. Second, there may be no value. Whether the limitations of optional when using reference types is a problem in this context, I'll leave to you (see <>).

Local conventions may dictate that all ownership transfers are done via std::auto_ptr, for example, and never through raw pointers, leaving raw pointers as non-owning, possibly null references. Boost, however, is used in various places with different conventions.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at