[ADT] Remove llvm::Optional::transform
authorKazu Hirata <kazu@google.com>
Thu, 15 Dec 2022 17:24:54 +0000 (09:24 -0800)
committerKazu Hirata <kazu@google.com>
Thu, 15 Dec 2022 17:24:54 +0000 (09:24 -0800)
I've removed the last uses of transform on Dec 14, 2022 in commit
230df792e17519071a9ef4dc0fb10132540dfbb8.

Differential Revision: https://reviews.llvm.org/D140082

llvm/include/llvm/ADT/Optional.h
llvm/unittests/ADT/OptionalTest.cpp

index 6702738..2b8940c 100644 (file)
@@ -284,29 +284,12 @@ public:
     return has_value() ? value() : std::forward<U>(alt);
   }
 
-  /// Apply a function to the value if present; otherwise return std::nullopt.
-  template <class Function>
-  auto transform(const Function &F) const & -> Optional<decltype(F(value()))> {
-    if (*this)
-      return F(value());
-    return std::nullopt;
-  }
-
   T &&value() && { 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(value()) : std::forward<U>(alt);
   }
-
-  /// Apply a function to the value if present; otherwise return std::nullopt.
-  template <class Function>
-  auto transform(
-      const Function &F) && -> Optional<decltype(F(std::move(*this).value()))> {
-    if (*this)
-      return F(std::move(*this).value());
-    return std::nullopt;
-  }
 };
 
 template<typename T>
index b192d53..bc344a2 100644 (file)
@@ -573,40 +573,6 @@ TEST(OptionalTest, MoveValueOr) {
   EXPECT_EQ(2u, MoveOnly::Destructions);
 }
 
-TEST(OptionalTest, Transform) {
-  Optional<int> A;
-
-  Optional<int> B = A.transform([&](int N) { return N + 1; });
-  EXPECT_FALSE(B.has_value());
-
-  A = 3;
-  Optional<int> C = A.transform([&](int N) { return N + 1; });
-  EXPECT_TRUE(C.has_value());
-  EXPECT_EQ(4, C.value());
-}
-
-TEST(OptionalTest, MoveTransform) {
-  Optional<MoveOnly> A;
-
-  MoveOnly::ResetCounts();
-  Optional<int> B =
-      std::move(A).transform([&](const MoveOnly &M) { return M.val + 2; });
-  EXPECT_FALSE(B.has_value());
-  EXPECT_EQ(0u, MoveOnly::MoveConstructions);
-  EXPECT_EQ(0u, MoveOnly::MoveAssignments);
-  EXPECT_EQ(0u, MoveOnly::Destructions);
-
-  A = MoveOnly(5);
-  MoveOnly::ResetCounts();
-  Optional<int> C =
-      std::move(A).transform([&](const MoveOnly &M) { return M.val + 2; });
-  EXPECT_TRUE(C.has_value());
-  EXPECT_EQ(7, C.value());
-  EXPECT_EQ(0u, MoveOnly::MoveConstructions);
-  EXPECT_EQ(0u, MoveOnly::MoveAssignments);
-  EXPECT_EQ(0u, MoveOnly::Destructions);
-}
-
 struct EqualTo {
   template <typename T, typename U> static bool apply(const T &X, const U &Y) {
     return X == Y;