small_vector exception safety, part 2
authorNicholas Ormrod <njormrod@fb.com>
Mon, 12 May 2014 18:02:00 +0000 (11:02 -0700)
committerDave Watson <davejwatson@fb.com>
Tue, 20 May 2014 19:53:58 +0000 (12:53 -0700)
Summary:
small_vector is now object-exception safe for all container
functions, except for input-iterators.

That's a bold claim; probably incorrect. At the very least, it passes
the same test suite as std::vector and fbvector.

Aside: Clearly, no one uses erase(q1, q2) in the wild.

Facebook: Nothing special.

Test Plan:
fbconfig -r folly && fbmake runtests
fbconfig -r experimental/njormrod/stltest && fbmake runtests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1319787

folly/small_vector.h

index c33eb7454bae5ee8cddc3522e466e32a837b6779..f5eddcb3ec9db90e1e97f2f9a4ca426249bc31e7 100644 (file)
@@ -737,8 +737,9 @@ public:
   }
 
   iterator erase(const_iterator q1, const_iterator q2) {
+    if (q1 == q2) return unconst(q1);
     std::move(unconst(q2), end(), unconst(q1));
-    for (auto it = q1; it != end(); ++it) {
+    for (auto it = (end() - std::distance(q1, q2)); it != end(); ++it) {
       it->~value_type();
     }
     this->setSize(size() - (q2 - q1));