[llvm] a5aca5b - Revert "[ADT] Relax type requirements for `is_contained`"
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 11:31:17 PST 2023
Author: Jakub Kuderski
Date: 2023-02-21T14:30:35-05:00
New Revision: a5aca5b2fd978a75fbcc2b72d4c0c569b67653b8
URL: https://github.com/llvm/llvm-project/commit/a5aca5b2fd978a75fbcc2b72d4c0c569b67653b8
DIFF: https://github.com/llvm/llvm-project/commit/a5aca5b2fd978a75fbcc2b72d4c0c569b67653b8.diff
LOG: Revert "[ADT] Relax type requirements for `is_contained`"
This reverts commit 75272d5c1299db93aa619fc9e616832f578726c2.
This fails to compile on the clang-debian-cpp20 buildbot:
https://lab.llvm.org/buildbot#builders/249/builds/945.
Added:
Modified:
llvm/include/llvm/ADT/STLExtras.h
llvm/unittests/ADT/STLExtrasTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 8702024d73d5..a8c54e0d9745 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1870,13 +1870,11 @@ bool is_contained(R &&Range, const E &Element) {
return std::find(adl_begin(Range), adl_end(Range), Element) != adl_end(Range);
}
-/// Returns true iff \p Element exists in \p Set. This overload takes \p Set as
-/// an initializer list and is `constexpr`-friendly.
-template <typename T, typename E>
-constexpr bool is_contained(std::initializer_list<T> Set, const E &Element) {
+template <typename T>
+constexpr bool is_contained(std::initializer_list<T> Set, T Value) {
// TODO: Use std::find when we switch to C++20.
- for (const T &V : Set)
- if (V == Element)
+ for (T V : Set)
+ if (V == Value)
return true;
return false;
}
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index 50820871c399..992c51790c44 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -960,28 +960,11 @@ enum Doggos {
Longboi,
};
-struct WooferCmp {
- // Not copyable.
- WooferCmp(const WooferCmp &) = delete;
- WooferCmp &operator=(const WooferCmp &) = delete;
-
- friend bool operator==(const Doggos &Doggo, const WooferCmp &) {
- return Doggo == Doggos::Woofer;
- }
-};
-
TEST(STLExtrasTest, IsContainedInitializerList) {
EXPECT_TRUE(is_contained({Woofer, SubWoofer}, Woofer));
EXPECT_TRUE(is_contained({Woofer, SubWoofer}, SubWoofer));
EXPECT_FALSE(is_contained({Woofer, SubWoofer}, Pupper));
-
- // Check that the initializer list type and the element type do not have to
- // match exactly.
- EXPECT_TRUE(is_contained({Floofer, Woofer, SubWoofer}, WooferCmp{}));
- EXPECT_FALSE(is_contained({Floofer, SubWoofer}, WooferCmp{}));
-
- EXPECT_TRUE(is_contained({"a", "bb", "ccc", "dddd"}, llvm::StringRef("ccc")));
- EXPECT_FALSE(is_contained({"a", "bb", "ccc", "dddd"}, llvm::StringRef("x")));
+ EXPECT_FALSE(is_contained({}, Longboi));
static_assert(is_contained({Woofer, SubWoofer}, SubWoofer), "SubWoofer!");
static_assert(!is_contained({Woofer, SubWoofer}, Pupper), "Missing Pupper!");
More information about the llvm-commits
mailing list