Boost Users :
Subject: Re: [Boost-users] shared_ptr as reference argument
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-03-19 18:49:58
For boost::shared_ptr it's the same. Nothing is copied in both cases. Some
compilers might (which is under doubt) optimize it better. Since const is an
additional information for them, that the object is not going to change
within the called function.
const is definitely a benefit for you, since you can eliminate more errors
at compile time if you try to change the const object. I think a developer
should try to program as restrictive as possible, otherwise you might bring
unforeseen errors in your code. But that gets a bit philosophical.
On Thu, Mar 19, 2009 at 10:57 PM, anony <janezz55_at_[hidden]> wrote:
> Igor R pravi:
> > Passing object by reference means you want to modify it inside the
> > function. If you only want to avoid overhead, pass it by const
> > reference.
> Perhaps I do want to... Call reset() perhaps. Does boost::shared_ptr<>
> const& avoid overhead better than just boost::shared_ptr<T>&?
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