Boost logo

Boost :

Subject: Re: [boost] [shared_ptr] calling functions by reference
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-05-29 07:05:36


On Sun, May 29, 2011 at 4:36 AM, Sid Sacek <ssacek_at_[hidden]> wrote:
> This might be a unimportant question and may have already been answered many times before, but I was wondering about functions that take shared pointers as arguments. Is there ever a reason I would not want to use a shared_ptr reference as an argument? I can't think of any, but is there any?

Yes, I think. If the function makes a copy of the argument, passing by
value might allow you to take advantage of move semantics (if the
callee doesn't need the argument anymore), whereas passing by (const)
reference doesn't.

Olaf


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk