Bug 857645. Make it possible to copy-initialize an nsCOMPtr<T> from an already_AddRefed<U> as long as U inherits from T. r=ehsan

This commit is contained in:
Boris Zbarsky 2013-04-05 00:57:39 -04:00
Родитель 681e05f0f8
Коммит 0611604263
1 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@ -20,6 +20,8 @@
*/
#include "mozilla/Attributes.h"
#include "mozilla/TypeTraits.h"
#include "mozilla/Assertions.h"
// Wrapping includes can speed up compiles (see "Large Scale C++ Software Design")
#ifndef nsDebug_h___
@ -548,6 +550,18 @@ class nsCOMPtr MOZ_FINAL
NSCAP_ASSERT_NO_QUERY_NEEDED();
}
template<typename U>
nsCOMPtr( const already_AddRefed<U>& aSmartPtr )
: NSCAP_CTOR_BASE(static_cast<T*>(aSmartPtr.mRawPtr))
// construct from |dont_AddRef(expr)|
{
// But make sure that U actually inherits from T
MOZ_STATIC_ASSERT((mozilla::IsBaseOf<T, U>::value),
"U is not a subclass of T");
NSCAP_LOG_ASSIGNMENT(this, static_cast<T*>(aSmartPtr.mRawPtr));
NSCAP_ASSERT_NO_QUERY_NEEDED();
}
nsCOMPtr( const nsQueryInterface qi )
: NSCAP_CTOR_BASE(0)
// construct from |do_QueryInterface(expr)|