Bug 975246 - Part1 - Implement operator->* in nsRefPtr. r=nfroyd, r=gerald

This commit is contained in:
James Cheng 2015-07-29 19:47:00 +02:00
parent 9e348de2d0
commit 43f57cf317

View File

@ -251,19 +251,31 @@ public:
return get();
}
// This operator is needed for gcc <= 4.0.* and for Sun Studio; it
// causes internal compiler errors for some MSVC versions. (It's not
// clear to me whether it should be needed.)
#ifndef _MSC_VER
template <class U, class V>
U&
operator->*(U V::* aMember)
template <typename R, typename... Args>
class Proxy
{
typedef R (T::*member_function)(Args...);
T* mRawPtr;
member_function mFunction;
public:
Proxy(T* aRawPtr, member_function aFunction)
: mRawPtr(aRawPtr),
mFunction(aFunction)
{
}
R operator()(Args... aArgs)
{
return ((*mRawPtr).*mFunction)(mozilla::Forward<Args>(aArgs)...);
}
};
template <typename R, typename... Args>
Proxy<R, Args...> operator->*(R (T::*aFptr)(Args...)) const
{
MOZ_ASSERT(mRawPtr != 0,
"You can't dereference a NULL nsRefPtr with operator->*().");
return get()->*aMember;
return Proxy<R, Args...>(get(), aFptr);
}
#endif
nsRefPtr<T>*
get_address()