From: Nicholas Ormrod Date: Mon, 12 May 2014 18:02:00 +0000 (-0700) Subject: small_vector exception safety, part 2 X-Git-Tag: v0.22.0~543 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=278a1f7dbb4c8f938114cf550c0a07bcdda11161;p=folly.git small_vector exception safety, part 2 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 --- diff --git a/folly/small_vector.h b/folly/small_vector.h index c33eb745..f5eddcb3 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -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));