From 278a1f7dbb4c8f938114cf550c0a07bcdda11161 Mon Sep 17 00:00:00 2001 From: Nicholas Ormrod Date: Mon, 12 May 2014 11:02:00 -0700 Subject: [PATCH] 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 --- folly/small_vector.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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)); -- 2.34.1