Bug 1129559 - Implement move construction for mozilla::MaybeOneOf; r=jandem

This commit is contained in:
Nick Fitzgerald 2015-02-04 13:34:18 -08:00
Родитель 52c52854d6
Коммит 80d28441f0
1 изменённых файлов: 23 добавлений и 0 удалений

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

@ -51,6 +51,29 @@ public:
MaybeOneOf() : state(None) {}
~MaybeOneOf() { destroyIfConstructed(); }
MaybeOneOf(MaybeOneOf&& rhs)
: state(None)
{
if (!rhs.empty()) {
if (rhs.constructed<T1>()) {
construct<T1>(Move(rhs.as<T1>()));
rhs.as<T1>().~T1();
} else {
construct<T2>(Move(rhs.as<T2>()));
rhs.as<T2>().~T2();
}
rhs.state = None;
}
}
MaybeOneOf &operator=(MaybeOneOf&& rhs)
{
MOZ_ASSERT(this != &rhs, "Self-move is prohibited");
this->~MaybeOneOf();
new(this) MaybeOneOf(Move(rhs));
return *this;
}
bool empty() const { return state == None; }
template <class T>