Open Bug 1061769 Opened 10 years ago Updated 2 years ago

Add templated conversion for nsRefPtr

Categories

(Core :: XPCOM, defect)

x86
macOS
defect

Tracking

()

People

(Reporter: jrmuizel, Unassigned)

Details

Attachments

(1 file)

This allows things like:

nsRefPtr<derived> m;
nsRefPtr<base> k;
void foo(nsRefPtr<base>);

k = m;
foo(m);

etc.

This helps avoid ugly code like that in bug 1060918 and matches the semantics of shared_ptr<>
Attachment #8482807 - Flags: review?(nfroyd)
Comment on attachment 8482807 [details] [diff] [review]
Add templated conversion for nsRefPtr

Review of attachment 8482807 [details] [diff] [review]:
-----------------------------------------------------------------

Please add the templated methods alongside the existing methods and run some tests to ensure things work as they should.  I think the overload resolution rules ensure that adding templated methods and non-templated copy/move/operator= should work properly, but I am not 100% sure.

::: xpcom/base/nsAutoPtr.h
@@ +861,5 @@
>    {
>    }
>  
> +  template<class Other>
> +  nsRefPtr(const nsRefPtr<Other>& aSmartPtr)

This change means that we don't declare a copy constructor anymore (the One True Copy Constructor can't be a templated method), which means the compiler is declaring one for us, and that is going to break a lot of things.

@@ +871,5 @@
>      }
>    }
>  
> +  template<class Other>
> +  nsRefPtr(nsRefPtr<Other>&& aRefPtr)

Likewise for the move constructor.

@@ +917,2 @@
>    nsRefPtr<T>&
> +  operator=(const nsRefPtr<Other>& aRhs)

And likewise for operator=.
Attachment #8482807 - Flags: review?(nfroyd) → review-
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: