[libcxx-commits] [libcxx] [libc++] Ensure strong exception guarantee for forward_list::resize (PR #131025)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed May 28 09:57:37 PDT 2025
================
@@ -1241,10 +1241,29 @@ void forward_list<_Tp, _Alloc>::resize(size_type __n) {
erase_after(__p, __e);
else {
__n -= __sz;
+ __begin_node_pointer __r = __p.__get_begin();
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);
+ __node_pointer __first = this->__create_node(/* next = */ nullptr);
----------------
ldionne wrote:
I wonder if we could use `emplace_after` instead with no `_Args...`? Or maybe we can add an internal version that gets called by both `resize(n)` and `resize(n, value)`?
https://github.com/llvm/llvm-project/pull/131025
More information about the libcxx-commits
mailing list