Add lvalue and rvalue getters to storage::Result

Reviewers: mtomic, mferencevic

Reviewed By: mtomic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2242
This commit is contained in:
Teon Banek 2019-07-25 15:45:18 +02:00
parent 35587cddbd
commit fc493e36ff

View File

@ -22,26 +22,46 @@ class [[nodiscard]] Result final {
bool HasValue() const { return value_.has_value(); }
bool HasError() const { return error_.has_value(); }
TValue &GetValue() {
TValue &GetValue() & {
CHECK(value_) << "The storage result is an error!";
return *value_;
}
const TValue &GetValue() const {
TValue &&GetValue() && {
CHECK(value_) << "The storage result is an error!";
return std::move(*value_);
}
const TValue &GetValue() const & {
CHECK(value_) << "The storage result is an error!";
return *value_;
}
TValue &operator*() {
const TValue &&GetValue() const && {
CHECK(value_) << "The storage result is an error!";
return std::move(*value_);
}
TValue &operator*() & {
CHECK(value_) << "The storage result is an error!";
return *value_;
}
const TValue &operator*() const {
TValue &&operator*() && {
CHECK(value_) << "The storage result is an error!";
return std::move(*value_);
}
const TValue &operator*() const & {
CHECK(value_) << "The storage result is an error!";
return *value_;
}
const TValue &&operator*() const && {
CHECK(value_) << "The storage result is an error!";
return std::move(*value_);
}
TValue *operator->() {
CHECK(value_) << "The storage result is an error!";
return &*value_;