summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/STLExtrasTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2016-12-25 08:22:50 +0000
committerChandler Carruth <chandlerc@gmail.com>2016-12-25 08:22:50 +0000
commitfba73aec7204803730f75df390c76cd56cdf2eb3 (patch)
tree67fe8d46893aedf8120d212de971e57a70b886ce /llvm/unittests/ADT/STLExtrasTest.cpp
parent87d263e870752d1bd724183bd88be47f6d2f6fed (diff)
downloadbcm5719-llvm-fba73aec7204803730f75df390c76cd56cdf2eb3.tar.gz
bcm5719-llvm-fba73aec7204803730f75df390c76cd56cdf2eb3.zip
[ADT] Add a generic concatenating iterator and range.
This allows both defining convenience iterator/range accessors on types which walk across N different independent ranges within the object, and more direct and simple usages with range based for loops such as shown in the unittest. The same facilities are used for both. They end up quite small and simple as it happens. I've also switched an iterator on `Module` to use this. I would like to add another convenience iterator that includes even more sequences as part of it and seeing this one already present motivated me to actually abstract it away and introduce a general utility. Differential Revision: https://reviews.llvm.org/D28093 llvm-svn: 290512
Diffstat (limited to 'llvm/unittests/ADT/STLExtrasTest.cpp')
-rw-r--r--llvm/unittests/ADT/STLExtrasTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index 76881296db6..d3bef6a2e05 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -10,6 +10,7 @@
#include "llvm/ADT/STLExtras.h"
#include "gtest/gtest.h"
+#include <list>
#include <vector>
using namespace llvm;
@@ -253,4 +254,26 @@ TEST(STLExtrasTest, CountAdaptor) {
EXPECT_EQ(1, count(v, 3));
EXPECT_EQ(1, count(v, 4));
}
+
+TEST(STLExtrasTest, ConcatRange) {
+ std::vector<int> Expected = {1, 2, 3, 4, 5, 6, 7, 8};
+ std::vector<int> Test;
+
+ std::vector<int> V1234 = {1, 2, 3, 4};
+ std::list<int> L56 = {5, 6};
+ SmallVector<int, 2> SV78 = {7, 8};
+
+ // Use concat across different sized ranges of different types with different
+ // iterators.
+ for (int &i : concat<int>(V1234, L56, SV78))
+ Test.push_back(i);
+ EXPECT_EQ(Expected, Test);
+
+ // Use concat between a temporary, an L-value, and an R-value to make sure
+ // complex lifetimes work well.
+ Test.clear();
+ for (int &i : concat<int>(std::vector<int>(V1234), L56, std::move(SV78)))
+ Test.push_back(i);
+ EXPECT_EQ(Expected, Test);
+}
}
OpenPOWER on IntegriCloud