[PATCH] D33919: [ADT] Make iterable SmallVector template overrides more specific
Francis Ricci via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 7 14:31:01 PDT 2017
fjricci updated this revision to Diff 101815.
fjricci added a comment.
Add test cases for all 3 specialized methods
https://reviews.llvm.org/D33919
Files:
include/llvm/ADT/SmallVector.h
unittests/ADT/SmallVectorTest.cpp
Index: unittests/ADT/SmallVectorTest.cpp
===================================================================
--- unittests/ADT/SmallVectorTest.cpp
+++ unittests/ADT/SmallVectorTest.cpp
@@ -415,6 +415,15 @@
this->assertValuesInOrder(this->theVector, 3u, 1, 77, 77);
}
+// Append test
+TYPED_TEST(SmallVectorTest, AppendNonIterTest) {
+ SCOPED_TRACE("AppendRepeatedTest");
+
+ this->theVector.push_back(Constructable(1));
+ this->theVector.append(2, 7);
+ this->assertValuesInOrder(this->theVector, 3u, 1, 7, 7);
+}
+
// Assign test
TYPED_TEST(SmallVectorTest, AssignTest) {
SCOPED_TRACE("AssignTest");
@@ -434,6 +443,15 @@
this->assertValuesInOrder(this->theVector, 3u, 1, 2, 3);
}
+// Assign test
+TYPED_TEST(SmallVectorTest, AssignNonIterTest) {
+ SCOPED_TRACE("AssignTest");
+
+ this->theVector.push_back(Constructable(1));
+ this->theVector.assign(2, 7);
+ this->assertValuesInOrder(this->theVector, 2u, 7, 7);
+}
+
// Move-assign test
TYPED_TEST(SmallVectorTest, MoveAssignTest) {
SCOPED_TRACE("MoveAssignTest");
@@ -532,6 +550,16 @@
this->assertValuesInOrder(this->theVector, 6u, 1, 16, 16, 2, 3, 4);
}
+TYPED_TEST(SmallVectorTest, InsertRepeatedNonIterTest) {
+ SCOPED_TRACE("InsertRepeatedTest");
+
+ this->makeSequence(this->theVector, 1, 4);
+ Constructable::reset();
+ auto I =
+ this->theVector.insert(this->theVector.begin() + 1, 2, 7);
+ EXPECT_EQ(this->theVector.begin() + 1, I);
+ this->assertValuesInOrder(this->theVector, 6u, 1, 7, 7, 2, 3, 4);
+}
TYPED_TEST(SmallVectorTest, InsertRepeatedAtEndTest) {
SCOPED_TRACE("InsertRepeatedTest");
Index: include/llvm/ADT/SmallVector.h
===================================================================
--- include/llvm/ADT/SmallVector.h
+++ include/llvm/ADT/SmallVector.h
@@ -388,7 +388,8 @@
void swap(SmallVectorImpl &RHS);
/// Add the specified range to the end of the SmallVector.
- template<typename in_iter>
+ template <typename in_iter,
+ typename = typename std::iterator_traits<in_iter>::pointer>
void append(in_iter in_start, in_iter in_end) {
size_type NumInputs = std::distance(in_start, in_end);
// Grow allocated space if needed.
@@ -426,7 +427,9 @@
std::uninitialized_fill(this->begin(), this->end(), Elt);
}
- template <typename in_iter> void assign(in_iter in_start, in_iter in_end) {
+ template <typename in_iter,
+ typename = typename std::iterator_traits<in_iter>::pointer>
+ void assign(in_iter in_start, in_iter in_end) {
clear();
append(in_start, in_end);
}
@@ -579,7 +582,8 @@
return I;
}
- template<typename ItTy>
+ template <typename ItTy,
+ typename = typename std::iterator_traits<ItTy>::pointer>
iterator insert(iterator I, ItTy From, ItTy To) {
// Convert iterator to elt# to avoid invalidating iterator when we reserve()
size_t InsertElt = I - this->begin();
@@ -860,7 +864,8 @@
this->assign(Size, Value);
}
- template<typename ItTy>
+ template <typename ItTy,
+ typename = typename std::iterator_traits<ItTy>::pointer>
SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(N) {
this->append(S, E);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33919.101815.patch
Type: text/x-patch
Size: 3180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170607/705121c5/attachment.bin>
More information about the llvm-commits
mailing list