[ADT] Use value instead of getValue() (NFC)

Since Optional<clang::FileEntryRef> uses a custom storage class, this
patch adds value to MapEntryOptionalStorage.
This commit is contained in:
Kazu Hirata 2022-06-19 18:34:33 -07:00
parent 813f487228
commit c7987d4948
2 changed files with 31 additions and 19 deletions

View File

@ -133,14 +133,26 @@ public:
bool has_value() const { return MaybeRef.hasOptionalValue(); }
bool hasValue() const { return MaybeRef.hasOptionalValue(); }
RefTy &value() & {
assert(has_value());
return MaybeRef;
}
RefTy &getValue() & {
assert(hasValue());
return MaybeRef;
}
RefTy const &value() const & {
assert(has_value());
return MaybeRef;
}
RefTy const &getValue() const & {
assert(hasValue());
return MaybeRef;
}
RefTy &&value() && {
assert(has_value());
return std::move(MaybeRef);
}
RefTy &&getValue() && {
assert(hasValue());
return std::move(MaybeRef);

View File

@ -300,53 +300,53 @@ public:
void reset() { Storage.reset(); }
constexpr const T *getPointer() const { return &Storage.getValue(); }
T *getPointer() { return &Storage.getValue(); }
constexpr const T &value() const & { return Storage.getValue(); }
constexpr const T &getValue() const & { return Storage.getValue(); }
T &value() & { return Storage.getValue(); }
T &getValue() & { return Storage.getValue(); }
constexpr const T *getPointer() const { return &Storage.value(); }
T *getPointer() { return &Storage.value(); }
constexpr const T &value() const & { return Storage.value(); }
constexpr const T &getValue() const & { return Storage.value(); }
T &value() & { return Storage.value(); }
T &getValue() & { return Storage.value(); }
constexpr explicit operator bool() const { return has_value(); }
constexpr bool has_value() const { return Storage.has_value(); }
constexpr bool hasValue() const { return Storage.has_value(); }
constexpr const T *operator->() const { return getPointer(); }
T *operator->() { return getPointer(); }
constexpr const T &operator*() const & { return getValue(); }
T &operator*() & { return getValue(); }
constexpr const T &operator*() const & { return value(); }
T &operator*() & { return value(); }
template <typename U> constexpr T value_or(U &&alt) const & {
return has_value() ? getValue() : std::forward<U>(alt);
return has_value() ? value() : std::forward<U>(alt);
}
template <typename U> constexpr T getValueOr(U &&alt) const & {
return has_value() ? getValue() : std::forward<U>(alt);
return has_value() ? value() : std::forward<U>(alt);
}
/// Apply a function to the value if present; otherwise return None.
template <class Function>
auto map(const Function &F) const & -> Optional<decltype(F(getValue()))> {
auto map(const Function &F) const & -> Optional<decltype(F(value()))> {
if (*this)
return F(getValue());
return F(value());
return None;
}
T &&value() && { return std::move(Storage.getValue()); }
T &&getValue() && { return std::move(Storage.getValue()); }
T &&operator*() && { return std::move(Storage.getValue()); }
T &&value() && { return std::move(Storage.value()); }
T &&getValue() && { return std::move(Storage.value()); }
T &&operator*() && { return std::move(Storage.value()); }
template <typename U> T value_or(U &&alt) && {
return has_value() ? std::move(getValue()) : std::forward<U>(alt);
return has_value() ? std::move(value()) : std::forward<U>(alt);
}
template <typename U> T getValueOr(U &&alt) && {
return has_value() ? std::move(getValue()) : std::forward<U>(alt);
return has_value() ? std::move(value()) : std::forward<U>(alt);
}
/// Apply a function to the value if present; otherwise return None.
template <class Function>
auto map(const Function &F)
&& -> Optional<decltype(F(std::move(*this).getValue()))> {
&& -> Optional<decltype(F(std::move(*this).value()))> {
if (*this)
return F(std::move(*this).getValue());
return F(std::move(*this).value());
return None;
}
};