void SomeFunctionOrMethod(const scoped_reftrp<SomeClass>& argument);
void SomeFunctionOrMethod(SomeClass* argument);
void SomeFunctionOrMethod(const SomeClass& argument);
You’re correct and I agree.
> I suspect some folks figured the "const-scoped_refptr-ref" might be a useful
> pattern
This is pessimistic, but I bet that the answer is far simpler. I think
this happens most frequently when someone needs to write a function to
operate on some object that’s held in existing code as a
scoped_refptr<SomeClass>. I doubt anyone writing |const
scoped_refptr<SomeClass>&| is actually thinking about reference
counting, they’re just thinking about ferrying an object over to
another function and operating by rote.
Mark
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
* implicit T* and scoped_refptr<T> conversion leads to bugs (see: http://code.google.com/p/chromium/issues/detail?id=28083). If we agree this bug-prone pattern is worth stopping, then we shouldn't use a pattern that encourages implicit conversion.
* const shared_ptr<T>& is a very common, especially within google3 code (googlers can search for this). I can't come up with a good public codesearch link as most of the results are boost/tr1 library implementations instead. As scoped_refptr is fairly similar, then I don't think it's too unreasonable to say that const SmartPtr<T>& is not an uncommon pattern.
* const scoped_refptr<T>& is self-documenting that T is a refcounted object. T* offers no such assistance here.
On Wed, Sep 1, 2010 at 3:54 PM, William Chan (陈智昌) <will...@chromium.org> wrote:* implicit T* and scoped_refptr<T> conversion leads to bugs (see: http://code.google.com/p/chromium/issues/detail?id=28083). If we agree this bug-prone pattern is worth stopping, then we shouldn't use a pattern that encourages implicit conversion.I don't think I completely follow your argument. I happen to agree that implicit conversion between these two things is a potential bug source. That doesn't suggest to me that I should never convert them; it suggests that I should need to do so explicitly, i.e. call functions like "foo(my_ptr.get())".
* const shared_ptr<T>& is a very common, especially within google3 code (googlers can search for this). I can't come up with a good public codesearch link as most of the results are boost/tr1 library implementations instead. As scoped_refptr is fairly similar, then I don't think it's too unreasonable to say that const SmartPtr<T>& is not an uncommon pattern.I have no google3 experience. I imagine I'm not unique on the team. I'm definitely not unique in the general public that can read and contribute to the codebase. I would not use google3 as a reference for any discussion about Chromium code.
* const scoped_refptr<T>& is self-documenting that T is a refcounted object. T* offers no such assistance here.That doesn't matter unless we're actually wanting to modify the refcount, take ownership of the object, etc. When you only need access to an object, and nothing to do with ownership, you should use raw pointers.
When you _do_ need to muck with ownership, passing a "scoped_refptr" in any form is weird and confusing, since the scope is changing.
On Wed, Sep 1, 2010 at 4:01 PM, Peter Kasting <pkas...@google.com> wrote:it suggests that I should need to do so explicitly, i.e. call functions like "foo(my_ptr.get())".Hm, I think you're trading one ugliness for another. Instead of the consistency of using const scoped_refptr<T>&, then you get a lot of .get() and make_scoped_refptr() calls.
Fair enough. Here's a public codesearch link http://www.google.com/codesearch?hl=en&start=80&sa=N&filter=00&q=const+shared_ptr%3C.*%3E%26. Apparently I just had to skip a number of pages to get past boost/tr1 libraries.
When you _do_ need to muck with ownership, passing a "scoped_refptr" in any form is weird and confusing, since the scope is changing.I'm not sure I buy this point. Does this mean you'd be in favor of dropping the copy constructor for scoped_refptr, to force users to use scoped_refptr::get() instead to make it less weird and confusing?
You mean beyond the fact that T derives from base::RefCounted? That’s
huge. That’s everything.