[PATCH] D131289: [ADT] Add is_splat overload accepting initializer_list
Jakub Kuderski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 8 07:24:17 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGba9dc5f57738: [ADT] Add is_splat overload accepting initializer_list (authored by kuhar).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131289/new/
https://reviews.llvm.org/D131289
Files:
llvm/include/llvm/ADT/STLExtras.h
llvm/unittests/ADT/STLExtrasTest.cpp
Index: llvm/unittests/ADT/STLExtrasTest.cpp
===================================================================
--- llvm/unittests/ADT/STLExtrasTest.cpp
+++ llvm/unittests/ADT/STLExtrasTest.cpp
@@ -606,7 +606,7 @@
EXPECT_EQ(EIR.end(), I);
}
-TEST(STLExtrasTest, splat) {
+TEST(STLExtrasTest, IsSplat) {
std::vector<int> V;
EXPECT_FALSE(is_splat(V));
@@ -621,6 +621,13 @@
EXPECT_FALSE(is_splat(V));
}
+TEST(STLExtrasTest, IsSplatInitializerList) {
+ EXPECT_TRUE(is_splat({1}));
+ EXPECT_TRUE(is_splat({1, 1}));
+ EXPECT_FALSE(is_splat({1, 2}));
+ EXPECT_TRUE(is_splat({1, 1, 1}));
+}
+
TEST(STLExtrasTest, to_address) {
int *V1 = new int;
EXPECT_EQ(V1, to_address(V1));
Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -1796,6 +1796,11 @@
std::equal(adl_begin(Range) + 1, adl_end(Range), adl_begin(Range)));
}
+/// Returns true iff all Values in the initializer lists are same.
+template <typename T> bool is_splat(std::initializer_list<T> Values) {
+ return is_splat<std::initializer_list<T>>(std::move(Values));
+}
+
/// Provide a container algorithm similar to C++ Library Fundamentals v2's
/// `erase_if` which is equivalent to:
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131289.450800.patch
Type: text/x-patch
Size: 1323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220808/d8126c26/attachment.bin>
More information about the llvm-commits
mailing list