llvm.org GIT mirror llvm / eb71fa4
[tinyptrvector] Add in a MutableArrayRef implicit conversion operator to complement the ArrayRef implicit conversion operator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226428 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Gottesman 5 years ago
2 changed file(s) with 30 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
115115 return *Val.template get();
116116 }
117117
118 // implicit conversion operator to MutableArrayRef.
119 operator MutableArrayRef() {
120 if (Val.isNull())
121 return None;
122 if (Val.template is())
123 return *Val.getAddrOfPtr1();
124 return *Val.template get();
125 }
126
118127 bool empty() const {
119128 // This vector can be empty if it contains no element, or if it
120129 // contains a pointer to an empty vector.
437437 EXPECT_TRUE(V[i] == data[i]);
438438 }
439439 }
440
441 TEST(TinyPtrVectorTest, MutableArrayRefTest) {
442 int data_array[128];
443 std::vector data;
444
445 for (unsigned i = 0, e = 128; i != e; ++i) {
446 data_array[i] = 324 - int(i);
447 data.push_back(&data_array[i]);
448 }
449
450 TinyPtrVector V(data);
451 EXPECT_TRUE(V.size() == 128);
452 EXPECT_FALSE(V.empty());
453
454 MutableArrayRef mut_array = V;
455 for (unsigned i = 0, e = 128; i != e; ++i) {
456 EXPECT_TRUE(mut_array[i] == data[i]);
457 mut_array[i] = 324 + mut_array[i];
458 EXPECT_TRUE(mut_array[i] == (324 + data[i]));
459 }
460 }