[PATCH] D130140: [ADT] Remove Optional::getValueOr (NFC)
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 19 20:02:47 PDT 2022
kazu created this revision.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch removes getValueOr in favor of value_or.
I was originally planning to deprecate this method, but I cannot put
[[deprecated]] on C++ templates. Therefore, this patch removes
getValueOr outright.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130140
Files:
llvm/include/llvm/ADT/Optional.h
llvm/unittests/ADT/OptionalTest.cpp
Index: llvm/unittests/ADT/OptionalTest.cpp
===================================================================
--- llvm/unittests/ADT/OptionalTest.cpp
+++ llvm/unittests/ADT/OptionalTest.cpp
@@ -210,11 +210,9 @@
TEST(OptionalTest, GetValueOr) {
Optional<int> A;
EXPECT_EQ(42, A.value_or(42));
- EXPECT_EQ(42, A.getValueOr(42));
A = 5;
EXPECT_EQ(5, A.value_or(42));
- EXPECT_EQ(5, A.getValueOr(42));
}
struct MultiArgConstructor {
@@ -605,23 +603,6 @@
EXPECT_EQ(2u, MoveOnly::Destructions);
}
-TEST(OptionalTest, MoveGetValueOr) {
- Optional<MoveOnly> A;
-
- MoveOnly::ResetCounts();
- EXPECT_EQ(42, std::move(A).getValueOr(MoveOnly(42)).val);
- EXPECT_EQ(1u, MoveOnly::MoveConstructions);
- EXPECT_EQ(0u, MoveOnly::MoveAssignments);
- EXPECT_EQ(2u, MoveOnly::Destructions);
-
- A = MoveOnly(5);
- MoveOnly::ResetCounts();
- EXPECT_EQ(5, std::move(A).getValueOr(MoveOnly(42)).val);
- EXPECT_EQ(1u, MoveOnly::MoveConstructions);
- EXPECT_EQ(0u, MoveOnly::MoveAssignments);
- EXPECT_EQ(2u, MoveOnly::Destructions);
-}
-
struct EqualTo {
template <typename T, typename U> static bool apply(const T &X, const U &Y) {
return X == Y;
Index: llvm/include/llvm/ADT/Optional.h
===================================================================
--- llvm/include/llvm/ADT/Optional.h
+++ llvm/include/llvm/ADT/Optional.h
@@ -318,9 +318,6 @@
template <typename U> constexpr T value_or(U &&alt) const & {
return has_value() ? value() : std::forward<U>(alt);
}
- template <typename U> constexpr T getValueOr(U &&alt) const & {
- return has_value() ? value() : std::forward<U>(alt);
- }
/// Apply a function to the value if present; otherwise return None.
template <class Function>
@@ -337,9 +334,6 @@
template <typename U> T value_or(U &&alt) && {
return has_value() ? std::move(value()) : std::forward<U>(alt);
}
- template <typename U> T getValueOr(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>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130140.446020.patch
Type: text/x-patch
Size: 2111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220720/68838340/attachment-0001.bin>
More information about the llvm-commits
mailing list