[libcxx-commits] [libcxx] [libc++] Ensure strong exception guarantee for forward_list::resize (PR #131025)

Peng Liu via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 16 08:26:01 PDT 2025


================
@@ -1240,12 +1271,7 @@ void forward_list<_Tp, _Alloc>::resize(size_type __n) {
   if (__i != __e)
     erase_after(__p, __e);
   else {
-    __n -= __sz;
-    if (__n > 0) {
-      for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n, __ptr = __ptr->__next_as_begin()) {
-        __ptr->__next_ = this->__create_node(/* next = */ nullptr);
-      }
-    }
+    __default_insert_after(__p, __n - __sz);
----------------
winner245 wrote:

Thank you for the suggestion! I‘ve inlined `__default_insert_after` into `resize`. 

https://github.com/llvm/llvm-project/pull/131025


More information about the libcxx-commits mailing list