Merge pull request #3962 from sfc-gh-tclinkenbeard/add-optional-get-overload

Support rvalue reference overload for Optional::get
This commit is contained in:
Xiaoge Su 2020-10-24 23:17:14 -07:00 committed by GitHub
commit 1fe775d393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -242,14 +242,18 @@ public:
}
bool present() const { return impl.has_value(); }
T& get() {
T& get() & {
UNSTOPPABLE_ASSERT(impl.has_value());
return impl.value();
}
T const& get() const {
T const& get() const& {
UNSTOPPABLE_ASSERT(impl.has_value());
return impl.value();
}
T&& get() && {
UNSTOPPABLE_ASSERT(impl.has_value());
return std::move(impl.value());
}
T orDefault(T const& default_value) const { return impl.value_or(default_value); }
// Spaceship operator. Treats not-present as less-than present.