]> granicus.if.org Git - llvm/commitdiff
Add 2x constructors for TinyPtrVector, one that takes in one elemenet and the other...
authorMichael Gottesman <mgottesman@apple.com>
Wed, 31 Dec 2014 23:33:24 +0000 (23:33 +0000)
committerMichael Gottesman <mgottesman@apple.com>
Wed, 31 Dec 2014 23:33:24 +0000 (23:33 +0000)
Currently one can only construct an empty TinyPtrVector. These are just missing
elements of the API.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225055 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/TinyPtrVector.h
unittests/ADT/TinyPtrVectorTest.cpp

index e158f9d278b207074a186bca8b58cffa4523d5c2..15137f5ebf8c8a89530827c596233eaeb0c29862 100644 (file)
@@ -96,6 +96,13 @@ public:
     return *this;
   }
 
+  /// Constructor from a single element.
+  explicit TinyPtrVector(EltTy Elt) : Val(Elt) {}
+
+  /// Constructor from an ArrayRef.
+  explicit TinyPtrVector(ArrayRef<EltTy> Elts)
+      : Val(new VecTy(Elts.begin(), Elts.end())) {}
+
   // implicit conversion operator to ArrayRef.
   operator ArrayRef<EltTy>() const {
     if (Val.isNull())
index ec868d4258a2c7dd2a558130b1859fca4d087a91..a402e8be9df6d06dcd3d278673f9fe1ef845cf1d 100644 (file)
@@ -412,3 +412,29 @@ TYPED_TEST(TinyPtrVectorTest, InsertRange) {
 }
 
 }
+
+TEST(TinyPtrVectorTest, SingleEltCtorTest) {
+  int v = 55;
+  TinyPtrVector<int *> V(&v);
+
+  EXPECT_TRUE(V.size() == 1);
+  EXPECT_FALSE(V.empty());
+  EXPECT_TRUE(V.front() == &v);
+}
+
+TEST(TinyPtrVectorTest, ArrayRefCtorTest) {
+  int data_array[128];
+  std::vector<int *> data;
+
+  for (unsigned i = 0, e = 128; i != e; ++i) {
+    data_array[i] = 324 - int(i);
+    data.push_back(&data_array[i]);
+  }
+
+  TinyPtrVector<int *> V(data);
+  EXPECT_TRUE(V.size() == 128);
+  EXPECT_FALSE(V.empty());
+  for (unsigned i = 0, e = 128; i != e; ++i) {
+    EXPECT_TRUE(V[i] == data[i]);
+  }
+}