зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1648044 - Add Maybe<T&>::refEquals methods. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D80845
This commit is contained in:
Родитель
e30a7e3356
Коммит
6fbe4dd29b
|
@ -744,6 +744,12 @@ class Maybe<T&> {
|
|||
return val;
|
||||
}
|
||||
|
||||
bool refEquals(const Maybe<T&>& aOther) const {
|
||||
return mValue == aOther.mValue;
|
||||
}
|
||||
|
||||
bool refEquals(const T& aOther) const { return mValue == &aOther; }
|
||||
|
||||
private:
|
||||
T* mValue = nullptr;
|
||||
};
|
||||
|
|
|
@ -1265,7 +1265,7 @@ static bool TestReference() {
|
|||
}
|
||||
|
||||
{
|
||||
int foo = 42;
|
||||
int foo = 42, bar = 42;
|
||||
Maybe<int&> some = SomeRef(foo);
|
||||
|
||||
MOZ_RELEASE_ASSERT(!some.isNothing());
|
||||
|
@ -1273,6 +1273,12 @@ static bool TestReference() {
|
|||
MOZ_RELEASE_ASSERT(some);
|
||||
MOZ_RELEASE_ASSERT(&some.ref() == &foo);
|
||||
|
||||
MOZ_RELEASE_ASSERT(some.refEquals(foo));
|
||||
MOZ_RELEASE_ASSERT(some.refEquals(SomeRef(foo)));
|
||||
MOZ_RELEASE_ASSERT(!some.refEquals(Nothing()));
|
||||
MOZ_RELEASE_ASSERT(!some.refEquals(bar));
|
||||
MOZ_RELEASE_ASSERT(!some.refEquals(SomeRef(bar)));
|
||||
|
||||
some.ref()++;
|
||||
MOZ_RELEASE_ASSERT(43 == foo);
|
||||
|
||||
|
@ -1281,7 +1287,7 @@ static bool TestReference() {
|
|||
}
|
||||
|
||||
{
|
||||
int foo = 42;
|
||||
int foo = 42, bar = 42;
|
||||
Maybe<int&> some;
|
||||
some.emplace(foo);
|
||||
|
||||
|
@ -1290,6 +1296,12 @@ static bool TestReference() {
|
|||
MOZ_RELEASE_ASSERT(some);
|
||||
MOZ_RELEASE_ASSERT(&some.ref() == &foo);
|
||||
|
||||
MOZ_RELEASE_ASSERT(some.refEquals(foo));
|
||||
MOZ_RELEASE_ASSERT(some.refEquals(SomeRef(foo)));
|
||||
MOZ_RELEASE_ASSERT(!some.refEquals(Nothing()));
|
||||
MOZ_RELEASE_ASSERT(!some.refEquals(bar));
|
||||
MOZ_RELEASE_ASSERT(!some.refEquals(SomeRef(bar)));
|
||||
|
||||
some.ref()++;
|
||||
MOZ_RELEASE_ASSERT(43 == foo);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче