aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/IteratorTest.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-04-24 21:10:35 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-04-24 21:10:35 +0000
commitd5835ee36815c82cc059b95a6a9cdb864dd193a7 (patch)
tree4d1c36acf675a6093d08110da65d797cb5d867eb /llvm/unittests/Support/IteratorTest.cpp
parent76f753e9a97ebd0d2823152c73d6f4341352e5f1 (diff)
downloadllvm-d5835ee36815c82cc059b95a6a9cdb864dd193a7.zip
llvm-d5835ee36815c82cc059b95a6a9cdb864dd193a7.tar.gz
llvm-d5835ee36815c82cc059b95a6a9cdb864dd193a7.tar.bz2
[ADT] Generalize pointee_iterator to smart pointers by using decltype.
Based on review feedback from Dave on the original patch. llvm-svn: 207146
Diffstat (limited to 'llvm/unittests/Support/IteratorTest.cpp')
-rw-r--r--llvm/unittests/Support/IteratorTest.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/unittests/Support/IteratorTest.cpp b/llvm/unittests/Support/IteratorTest.cpp
index 3a16406..8384832 100644
--- a/llvm/unittests/Support/IteratorTest.cpp
+++ b/llvm/unittests/Support/IteratorTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/iterator.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "gtest/gtest.h"
@@ -56,4 +57,45 @@ TEST(PointeeIteratorTest, Basic) {
EXPECT_EQ(End, I);
}
+TEST(PointeeIteratorTest, SmartPointer) {
+ SmallVector<std::unique_ptr<int>, 4> V;
+ V.push_back(make_unique<int>(1));
+ V.push_back(make_unique<int>(2));
+ V.push_back(make_unique<int>(3));
+ V.push_back(make_unique<int>(4));
+
+ typedef pointee_iterator<
+ SmallVectorImpl<std::unique_ptr<int>>::const_iterator> test_iterator;
+
+ test_iterator Begin, End;
+ Begin = V.begin();
+ End = test_iterator(V.end());
+
+ test_iterator I = Begin;
+ for (int i = 0; i < 4; ++i) {
+ EXPECT_EQ(*V[i], *I);
+
+ EXPECT_EQ(I, Begin + i);
+ EXPECT_EQ(I, std::next(Begin, i));
+ test_iterator J = Begin;
+ J += i;
+ EXPECT_EQ(I, J);
+ EXPECT_EQ(*V[i], Begin[i]);
+
+ EXPECT_NE(I, End);
+ EXPECT_GT(End, I);
+ EXPECT_LT(I, End);
+ EXPECT_GE(I, Begin);
+ EXPECT_LE(Begin, I);
+
+ EXPECT_EQ(i, I - Begin);
+ EXPECT_EQ(i, std::distance(Begin, I));
+ EXPECT_EQ(Begin, I - i);
+
+ test_iterator K = I++;
+ EXPECT_EQ(K, std::prev(I));
+ }
+ EXPECT_EQ(End, I);
+}
+
} // anonymous namespace