mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +00:00
Add 2x constructors for TinyPtrVector, one that takes in one elemenet and the other that takes in an ArrayRef<EltTy>
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
This commit is contained in:
@@ -96,6 +96,13 @@ public:
|
|||||||
return *this;
|
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.
|
// implicit conversion operator to ArrayRef.
|
||||||
operator ArrayRef<EltTy>() const {
|
operator ArrayRef<EltTy>() const {
|
||||||
if (Val.isNull())
|
if (Val.isNull())
|
||||||
|
|||||||
@@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user