diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -284,29 +284,12 @@ return has_value() ? value() : std::forward(alt); } - /// Apply a function to the value if present; otherwise return std::nullopt. - template - auto transform(const Function &F) const & -> Optional { - if (*this) - return F(value()); - return std::nullopt; - } - T &&value() && { return std::move(Storage.value()); } T &&operator*() && { return std::move(Storage.value()); } template T value_or(U &&alt) && { return has_value() ? std::move(value()) : std::forward(alt); } - - /// Apply a function to the value if present; otherwise return std::nullopt. - template - auto transform( - const Function &F) && -> Optional { - if (*this) - return F(std::move(*this).value()); - return std::nullopt; - } }; template diff --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -573,40 +573,6 @@ EXPECT_EQ(2u, MoveOnly::Destructions); } -TEST(OptionalTest, Transform) { - Optional A; - - Optional B = A.transform([&](int N) { return N + 1; }); - EXPECT_FALSE(B.has_value()); - - A = 3; - Optional C = A.transform([&](int N) { return N + 1; }); - EXPECT_TRUE(C.has_value()); - EXPECT_EQ(4, C.value()); -} - -TEST(OptionalTest, MoveTransform) { - Optional A; - - MoveOnly::ResetCounts(); - Optional 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 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 static bool apply(const T &X, const U &Y) { return X == Y;