[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 13:56:56 PDT 2017


fjricci updated this revision to Diff 101813.
fjricci retitled this revision from "[ADT] Ensure that correct overrides for SmallVector assign are selected" to "[ADT] Make iterable SmallVector template overrides more specific".
fjricci edited the summary of this revision.
fjricci added a comment.

Add unit test and migrate to iterator SFINAE checks


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
@@ -434,6 +434,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, 2);
+  this->assertValuesInOrder(this->theVector, 2u, 2);
+}
+
 // Move-assign test
 TYPED_TEST(SmallVectorTest, MoveAssignTest) {
   SCOPED_TRACE("MoveAssignTest");
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.101813.patch
Type: text/x-patch
Size: 2184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170607/a7278cf2/attachment.bin>


More information about the llvm-commits mailing list