[clang] 813f487 - [ADT] Use has_value (NFC)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 19 18:10:21 PDT 2022
Author: Kazu Hirata
Date: 2022-06-19T18:10:13-07:00
New Revision: 813f487228837fa4460c527e81e23fbc8fbf8198
URL: https://github.com/llvm/llvm-project/commit/813f487228837fa4460c527e81e23fbc8fbf8198
DIFF: https://github.com/llvm/llvm-project/commit/813f487228837fa4460c527e81e23fbc8fbf8198.diff
LOG: [ADT] Use has_value (NFC)
This patch switches to has_value within Optional.
Since Optional<clang::FileEntryRef> uses custom storage class, this
patch adds has_entry to MapEntryOptionalStorage.
Added:
Modified:
clang/include/clang/Basic/DirectoryEntry.h
llvm/include/llvm/ADT/Optional.h
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h
index fe18b12769546..0cfdb1d73eef3 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -130,6 +130,7 @@ template <class RefTy> class MapEntryOptionalStorage {
void reset() { MaybeRef = optional_none_tag(); }
+ bool has_value() const { return MaybeRef.hasOptionalValue(); }
bool hasValue() const { return MaybeRef.hasOptionalValue(); }
RefTy &getValue() & {
diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h
index 2f458d5be4b86..62765914eb66c 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -70,12 +70,12 @@ class OptionalStorage {
constexpr OptionalStorage() noexcept : empty() {}
constexpr OptionalStorage(OptionalStorage const &other) : OptionalStorage() {
- if (other.hasValue()) {
+ if (other.has_value()) {
emplace(other.val);
}
}
constexpr OptionalStorage(OptionalStorage &&other) : OptionalStorage() {
- if (other.hasValue()) {
+ if (other.has_value()) {
emplace(std::move(other.val));
}
}
@@ -126,7 +126,7 @@ class OptionalStorage {
}
OptionalStorage &operator=(T const &y) {
- if (hasValue()) {
+ if (has_value()) {
val = y;
} else {
::new ((void *)std::addressof(val)) T(y);
@@ -135,7 +135,7 @@ class OptionalStorage {
return *this;
}
OptionalStorage &operator=(T &&y) {
- if (hasValue()) {
+ if (has_value()) {
val = std::move(y);
} else {
::new ((void *)std::addressof(val)) T(std::move(y));
@@ -145,8 +145,8 @@ class OptionalStorage {
}
OptionalStorage &operator=(OptionalStorage const &other) {
- if (other.hasValue()) {
- if (hasValue()) {
+ if (other.has_value()) {
+ if (has_value()) {
val = other.val;
} else {
::new ((void *)std::addressof(val)) T(other.val);
@@ -159,8 +159,8 @@ class OptionalStorage {
}
OptionalStorage &operator=(OptionalStorage &&other) {
- if (other.hasValue()) {
- if (hasValue()) {
+ if (other.has_value()) {
+ if (has_value()) {
val = std::move(other.val);
} else {
::new ((void *)std::addressof(val)) T(std::move(other.val));
@@ -237,7 +237,7 @@ template <typename T> class OptionalStorage<T, true> {
}
OptionalStorage &operator=(T const &y) {
- if (hasValue()) {
+ if (has_value()) {
val = y;
} else {
::new ((void *)std::addressof(val)) T(y);
@@ -246,7 +246,7 @@ template <typename T> class OptionalStorage<T, true> {
return *this;
}
OptionalStorage &operator=(T &&y) {
- if (hasValue()) {
+ if (has_value()) {
val = std::move(y);
} else {
::new ((void *)std::addressof(val)) T(std::move(y));
@@ -307,19 +307,19 @@ template <typename T> class Optional {
T &value() & { return Storage.getValue(); }
T &getValue() & { return Storage.getValue(); }
- constexpr explicit operator bool() const { return hasValue(); }
- constexpr bool has_value() const { return Storage.hasValue(); }
- constexpr bool hasValue() const { return Storage.hasValue(); }
+ 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(); }
template <typename U> constexpr T value_or(U &&alt) const & {
- return hasValue() ? getValue() : std::forward<U>(alt);
+ return has_value() ? getValue() : std::forward<U>(alt);
}
template <typename U> constexpr T getValueOr(U &&alt) const & {
- return hasValue() ? getValue() : std::forward<U>(alt);
+ return has_value() ? getValue() : std::forward<U>(alt);
}
/// Apply a function to the value if present; otherwise return None.
@@ -335,10 +335,10 @@ template <typename T> class Optional {
T &&operator*() && { return std::move(Storage.getValue()); }
template <typename U> T value_or(U &&alt) && {
- return hasValue() ? std::move(getValue()) : std::forward<U>(alt);
+ return has_value() ? std::move(getValue()) : std::forward<U>(alt);
}
template <typename U> T getValueOr(U &&alt) && {
- return hasValue() ? std::move(getValue()) : std::forward<U>(alt);
+ return has_value() ? std::move(getValue()) : std::forward<U>(alt);
}
/// Apply a function to the value if present; otherwise return None.
@@ -359,7 +359,7 @@ template <typename T, typename U>
constexpr bool operator==(const Optional<T> &X, const Optional<U> &Y) {
if (X && Y)
return *X == *Y;
- return X.hasValue() == Y.hasValue();
+ return X.has_value() == Y.has_value();
}
template <typename T, typename U>
@@ -371,7 +371,7 @@ template <typename T, typename U>
constexpr bool operator<(const Optional<T> &X, const Optional<U> &Y) {
if (X && Y)
return *X < *Y;
- return X.hasValue() < Y.hasValue();
+ return X.has_value() < Y.has_value();
}
template <typename T, typename U>
@@ -414,7 +414,7 @@ template <typename T> constexpr bool operator<(const Optional<T> &, NoneType) {
}
template <typename T> constexpr bool operator<(NoneType, const Optional<T> &X) {
- return X.hasValue();
+ return X.has_value();
}
template <typename T>
More information about the cfe-commits
mailing list