summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/STLExtrasTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2016-12-26 23:10:40 +0000
committerChandler Carruth <chandlerc@gmail.com>2016-12-26 23:10:40 +0000
commitd9eaa54ef44693facfaa63edab37af1d0a9cb9fd (patch)
tree9b7074719e6191dcf575e09a4d1bfdc237f3df9a /llvm/unittests/ADT/STLExtrasTest.cpp
parent4f9b3f4a5bdda7e13e39d75779d50cf4e7a2e18e (diff)
downloadbcm5719-llvm-d9eaa54ef44693facfaa63edab37af1d0a9cb9fd.tar.gz
bcm5719-llvm-d9eaa54ef44693facfaa63edab37af1d0a9cb9fd.zip
[ADT] Add a boring std::partition wrapper similar to our std::remove_if
wrapper. llvm-svn: 290553
Diffstat (limited to 'llvm/unittests/ADT/STLExtrasTest.cpp')
-rw-r--r--llvm/unittests/ADT/STLExtrasTest.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index d3bef6a2e05..28e0ebb53f6 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -276,4 +276,25 @@ TEST(STLExtrasTest, ConcatRange) {
Test.push_back(i);
EXPECT_EQ(Expected, Test);
}
+
+TEST(STLExtrasTest, PartitionAdaptor) {
+ std::vector<int> V = {1, 2, 3, 4, 5, 6, 7, 8};
+
+ auto I = partition(V, [](int i) { return i % 2 == 0; });
+ ASSERT_EQ(V.begin() + 4, I);
+
+ // Sort the two halves as partition may have messed with the order.
+ std::sort(V.begin(), I);
+ std::sort(I, V.end());
+
+ EXPECT_EQ(2, V[0]);
+ EXPECT_EQ(4, V[1]);
+ EXPECT_EQ(6, V[2]);
+ EXPECT_EQ(8, V[3]);
+ EXPECT_EQ(1, V[4]);
+ EXPECT_EQ(3, V[5]);
+ EXPECT_EQ(5, V[6]);
+ EXPECT_EQ(7, V[7]);
+}
+
}
OpenPOWER on IntegriCloud