зеркало из https://github.com/mozilla/gecko-dev.git
Merge mozilla-central to inbound. a=backout CLOSED TREE
This commit is contained in:
Коммит
913e7edc65
147
mfbt/Maybe.h
147
mfbt/Maybe.h
|
@ -315,7 +315,11 @@ public:
|
|||
bool isNothing() const { return !mIsSome; }
|
||||
|
||||
/* Returns the contents of this Maybe<T> by value. Unsafe unless |isSome()|. */
|
||||
T value() const;
|
||||
T value() const
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return ref();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the contents of this Maybe<T> by value. If |isNothing()|, returns
|
||||
|
@ -344,8 +348,17 @@ public:
|
|||
}
|
||||
|
||||
/* Returns the contents of this Maybe<T> by pointer. Unsafe unless |isSome()|. */
|
||||
T* ptr();
|
||||
const T* ptr() const;
|
||||
T* ptr()
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return &ref();
|
||||
}
|
||||
|
||||
const T* ptr() const
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return &ref();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the contents of this Maybe<T> by pointer. If |isNothing()|,
|
||||
|
@ -389,12 +402,30 @@ public:
|
|||
return aFunc();
|
||||
}
|
||||
|
||||
T* operator->();
|
||||
const T* operator->() const;
|
||||
T* operator->()
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return ptr();
|
||||
}
|
||||
|
||||
const T* operator->() const
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return ptr();
|
||||
}
|
||||
|
||||
/* Returns the contents of this Maybe<T> by ref. Unsafe unless |isSome()|. */
|
||||
T& ref();
|
||||
const T& ref() const;
|
||||
T& ref()
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return *static_cast<T*>(data());
|
||||
}
|
||||
|
||||
const T& ref() const
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return *static_cast<const T*>(data());
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the contents of this Maybe<T> by ref. If |isNothing()|, returns
|
||||
|
@ -438,8 +469,17 @@ public:
|
|||
return aFunc();
|
||||
}
|
||||
|
||||
T& operator*();
|
||||
const T& operator*() const;
|
||||
T& operator*()
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return ref();
|
||||
}
|
||||
|
||||
const T& operator*() const
|
||||
{
|
||||
MOZ_ASSERT(mIsSome);
|
||||
return ref();
|
||||
}
|
||||
|
||||
/* If |isSome()|, runs the provided function or functor on the contents of
|
||||
* this Maybe. */
|
||||
|
@ -504,7 +544,12 @@ public:
|
|||
* arguments to |emplace()| are the parameters to T's constructor.
|
||||
*/
|
||||
template<typename... Args>
|
||||
void emplace(Args&&... aArgs);
|
||||
void emplace(Args&&... aArgs)
|
||||
{
|
||||
MOZ_ASSERT(!mIsSome);
|
||||
::new (KnownNotNull, data()) T(Forward<Args>(aArgs)...);
|
||||
mIsSome = true;
|
||||
}
|
||||
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& aStream, const Maybe<T>& aMaybe)
|
||||
|
@ -518,88 +563,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
Maybe<T>::value() const
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return ref();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T*
|
||||
Maybe<T>::ptr()
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return &ref();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T*
|
||||
Maybe<T>::ptr() const
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return &ref();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T*
|
||||
Maybe<T>::operator->()
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return ptr();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T*
|
||||
Maybe<T>::operator->() const
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return ptr();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T&
|
||||
Maybe<T>::ref()
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return *static_cast<T*>(data());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T&
|
||||
Maybe<T>::ref() const
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return *static_cast<const T*>(data());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T&
|
||||
Maybe<T>::operator*()
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return ref();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T&
|
||||
Maybe<T>::operator*() const
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(mIsSome);
|
||||
return ref();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename... Args>
|
||||
void
|
||||
Maybe<T>::emplace(Args&&... aArgs)
|
||||
{
|
||||
MOZ_DIAGNOSTIC_ASSERT(!mIsSome);
|
||||
::new (KnownNotNull, data()) T(Forward<Args>(aArgs)...);
|
||||
mIsSome = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some() creates a Maybe<T> value containing the provided T value. If T has a
|
||||
* move constructor, it's used to make this as efficient as possible.
|
||||
|
|
Загрузка…
Ссылка в новой задаче