Boost logo

Boost Users :

Subject: Re: [Boost-users] Safe to pass dereferenced anonymous shared_ptr?
From: Scott Mueller (smueller_at_[hidden])
Date: 2013-11-05 23:55:05


I have just one comment. I would recommend returning a unique_ptr instead of a shared_ptr, as you can then use the object as a unique_ptr, be move it into a shared_ptr, or adopt it by other means elsewhere in your data structures. Returning a shared_ptr locks you into keeping the data as a shared_ptr.

Best Regards,

M. Scott Mueller

> On Nov 5, 2013, at 7:56 PM, "Chris Stankevitz" <chrisstankevitz_at_[hidden]> wrote:
> <lines removed, I'm writing this on a phone>
>
> Kris, Scott, Edward,
>
> Thank you for your replies regarding the safe use of the anonymous shared_ptrs.
>
> ===
>
> Kris: FYI my more complex use-case looks like this:
>
> class TCImage
> {
> public:
>
> // Default constructs a black image
> TCImage(unsigned Width, unsigned Height);
> };
>
> boost::shared_ptr<const std::string> GetJpegBytes(const TCImage& Image);
>
> GetJpegBytes generates JPEG bytes for an image and returns them as a
> shared_ptr. The shared_ptr is helpful because these JPEG bytes are
> passed around throughout my system.
>
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net