llvm.org GIT mirror llvm / 5f6c7cf
SmallVector: return a valid iterator for the rare case of inserting an empty range into a SmallVector. Patch by Johannes Schaub! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158643 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
2 changed file(s) with 9 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
541541 iterator insert(iterator I, size_type NumToInsert, const T &Elt) {
542542 if (I == this->end()) { // Important special case for empty vector.
543543 append(NumToInsert, Elt);
544 return this->end()-1;
544 return NumToInsert == 0 ? this->end() : this->end()-1;
545545 }
546546
547547 // Convert iterator to elt# to avoid invalidating iterator when we reserve()
589589 iterator insert(iterator I, ItTy From, ItTy To) {
590590 if (I == this->end()) { // Important special case for empty vector.
591591 append(From, To);
592 return this->end()-1;
592 return From == To ? this->end() : this->end()-1;
593593 }
594594
595595 size_t NumToInsert = std::distance(From, To);
352352 makeSequence(theVector, 10, 15);
353353 theVector.insert(theVector.begin() + 1, 2, Constructable(16));
354354 assertValuesInOrder(theVector, 8u, 10, 16, 16, 11, 12, 13, 14, 15);
355
356 EXPECT_EQ(theVector.end(),
357 theVector.insert(theVector.end(), 0, Constructable(42)));
355358 }
356359
357360 // Insert range.
361364 makeSequence(theVector, 1, 3);
362365 theVector.insert(theVector.begin() + 1, 3, Constructable(77));
363366 assertValuesInOrder(theVector, 6u, 1, 77, 77, 77, 2, 3);
367
368 EXPECT_EQ(theVector.end(), theVector.insert(theVector.end(),
369 theVector.begin(),
370 theVector.begin()));
364371 }
365372
366373 // Comparison tests.