Closed
Bug 1544860
Opened 6 years ago
Closed 6 years ago
Make it easier to cast from RefPtr<T>/already_AddRefed<T> and RefPtr<U>/already_AddRefed<U>
Categories
(Core :: MFBT, defect)
Core
MFBT
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: beth, Unassigned)
Details
I commonly run into the pattern where a method returns a pointer to a base class but I need to act on the specific subclass (and I know it actually returns that subclass), e.g.:
// inside CompositorOGL:
RefPtr<CompositingRenderTargetOGL> renderTarget;
{
RefPtr<CompositingRenderTarget> genericRenderTarget = CreateRenderTarget(/* ... */);
renderTarget = static_cast<CompositingRenderTargetOGL*>(genericRenderTarget.get());
}
It would be great if I could do something like:
RefPtr<CompositingRenderTargetOGL> renderTarget = CreateRenderTarget(/* ... */)
.static_cast<CompositingRenderTargetOGL>();
This would also have the side effect of getting rid of an AddRef() and Release() pair.
Comment 1•6 years ago
|
||
already_AddRefed has a downcast method for exactly this case:
https://searchfox.org/mozilla-central/source/mfbt/AlreadyAddRefed.h#150-169
| Reporter | ||
Updated•6 years ago
|
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•