[llvm] 556bcc7 - [ADT] Rename value to val (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 18 20:19:25 PDT 2022
Author: Kazu Hirata
Date: 2022-06-18T20:19:18-07:00
New Revision: 556bcc782101804b2d168a6868ddf06b963a4878
URL: https://github.com/llvm/llvm-project/commit/556bcc782101804b2d168a6868ddf06b963a4878
DIFF: https://github.com/llvm/llvm-project/commit/556bcc782101804b2d168a6868ddf06b963a4878.diff
LOG: [ADT] Rename value to val (NFC)
I'd like to introduce functions, such as value, value_or, has_value,
etc to make llvm::Optional look more like std::optional. Renaming
value to val avoids name conflicts.
Differential Revision: https://reviews.llvm.org/D128125
Added:
Modified:
llvm/include/llvm/ADT/Optional.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h
index f74e5e3b4799..9570cfe4624d 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -60,7 +60,7 @@ template <typename T,
class OptionalStorage {
union {
char empty;
- T value;
+ T val;
};
bool hasVal = false;
@@ -71,22 +71,22 @@ class OptionalStorage {
constexpr OptionalStorage(OptionalStorage const &other) : OptionalStorage() {
if (other.hasValue()) {
- emplace(other.value);
+ emplace(other.val);
}
}
constexpr OptionalStorage(OptionalStorage &&other) : OptionalStorage() {
if (other.hasValue()) {
- emplace(std::move(other.value));
+ emplace(std::move(other.val));
}
}
template <class... Args>
constexpr explicit OptionalStorage(in_place_t, Args &&...args)
- : value(std::forward<Args>(args)...), hasVal(true) {}
+ : val(std::forward<Args>(args)...), hasVal(true) {}
void reset() noexcept {
if (hasVal) {
- value.~T();
+ val.~T();
hasVal = false;
}
}
@@ -95,37 +95,37 @@ class OptionalStorage {
T &getValue() &noexcept {
assert(hasVal);
- return value;
+ return val;
}
constexpr T const &getValue() const &noexcept {
assert(hasVal);
- return value;
+ return val;
}
T &&getValue() &&noexcept {
assert(hasVal);
- return std::move(value);
+ return std::move(val);
}
template <class... Args> void emplace(Args &&...args) {
reset();
- ::new ((void *)std::addressof(value)) T(std::forward<Args>(args)...);
+ ::new ((void *)std::addressof(val)) T(std::forward<Args>(args)...);
hasVal = true;
}
OptionalStorage &operator=(T const &y) {
if (hasValue()) {
- value = y;
+ val = y;
} else {
- ::new ((void *)std::addressof(value)) T(y);
+ ::new ((void *)std::addressof(val)) T(y);
hasVal = true;
}
return *this;
}
OptionalStorage &operator=(T &&y) {
if (hasValue()) {
- value = std::move(y);
+ val = std::move(y);
} else {
- ::new ((void *)std::addressof(value)) T(std::move(y));
+ ::new ((void *)std::addressof(val)) T(std::move(y));
hasVal = true;
}
return *this;
@@ -134,9 +134,9 @@ class OptionalStorage {
OptionalStorage &operator=(OptionalStorage const &other) {
if (other.hasValue()) {
if (hasValue()) {
- value = other.value;
+ val = other.val;
} else {
- ::new ((void *)std::addressof(value)) T(other.value);
+ ::new ((void *)std::addressof(val)) T(other.val);
hasVal = true;
}
} else {
@@ -148,9 +148,9 @@ class OptionalStorage {
OptionalStorage &operator=(OptionalStorage &&other) {
if (other.hasValue()) {
if (hasValue()) {
- value = std::move(other.value);
+ val = std::move(other.val);
} else {
- ::new ((void *)std::addressof(value)) T(std::move(other.value));
+ ::new ((void *)std::addressof(val)) T(std::move(other.val));
hasVal = true;
}
} else {
@@ -163,7 +163,7 @@ class OptionalStorage {
template <typename T> class OptionalStorage<T, true> {
union {
char empty;
- T value;
+ T val;
};
bool hasVal = false;
@@ -179,12 +179,12 @@ template <typename T> class OptionalStorage<T, true> {
OptionalStorage &operator=(OptionalStorage &&other) = default;
template <class... Args>
- constexpr explicit OptionalStorage(in_place_t, Args &&... args)
- : value(std::forward<Args>(args)...), hasVal(true) {}
+ constexpr explicit OptionalStorage(in_place_t, Args &&...args)
+ : val(std::forward<Args>(args)...), hasVal(true) {}
void reset() noexcept {
if (hasVal) {
- value.~T();
+ val.~T();
hasVal = false;
}
}
@@ -193,37 +193,37 @@ template <typename T> class OptionalStorage<T, true> {
T &getValue() &noexcept {
assert(hasVal);
- return value;
+ return val;
}
constexpr T const &getValue() const &noexcept {
assert(hasVal);
- return value;
+ return val;
}
T &&getValue() &&noexcept {
assert(hasVal);
- return std::move(value);
+ return std::move(val);
}
template <class... Args> void emplace(Args &&...args) {
reset();
- ::new ((void *)std::addressof(value)) T(std::forward<Args>(args)...);
+ ::new ((void *)std::addressof(val)) T(std::forward<Args>(args)...);
hasVal = true;
}
OptionalStorage &operator=(T const &y) {
if (hasValue()) {
- value = y;
+ val = y;
} else {
- ::new ((void *)std::addressof(value)) T(y);
+ ::new ((void *)std::addressof(val)) T(y);
hasVal = true;
}
return *this;
}
OptionalStorage &operator=(T &&y) {
if (hasValue()) {
- value = std::move(y);
+ val = std::move(y);
} else {
- ::new ((void *)std::addressof(value)) T(std::move(y));
+ ::new ((void *)std::addressof(val)) T(std::move(y));
hasVal = true;
}
return *this;
More information about the llvm-commits
mailing list