This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
std::deque, std::forward_list, or std::list?Section: 23.3.5.3 [deque.capacity], 23.3.7.5 [forward.list.modifiers], 23.3.11.3 [list.capacity] Status: New Submitter: Jiang An Opened: 2025-03-15 Last modified: 2025-10-17
Priority: 3
View all other issues in [deque.capacity].
View all issues with New status.
Discussion:
Currently, std::vector and std::inplace_vector's resize functions are specified to have no effects
on the container when an exception is throwing on appending. However, such specification seem to be missing
for std::deque, std::forward_list, and std::list.
resize exception guarantee for std::vector came from resolving LWG 2033(i) and were
later effectively copied to std::inplace_vector because that container's specification should resemble
as much as possible that of std::vector.
[2025-10-16; Reflector poll]
Set priority to 3 after reflector poll.
[2025-10-16; Jonathan provides wording]
LWG 4106(i) already fixed this for std::forward_list.
For std::list the "If an exception is thrown, there are no effects" wording
in 23.3.11.4 [list.modifiers] p2 doesn't apply to std::list::resize
because it's in a different subclause (23.3.11.3 [list.capacity]).
We can fix that though.
[2025-10-17; Comment from Nevin.]
deque::resize invalidates all iterators if it causes a map reallocation.
Proposed resolution:
This wording is relative to N5014.
Modify 23.3.5.3 [deque.capacity] as indicated:
constexpr void resize(size_type sz);-1- Preconditions:
Tis Cpp17MoveInsertable and Cpp17DefaultInsertable intodeque.-2- Effects: If
sz < size()istrue, erases the lastsize() - szelements from the sequence. Otherwise, appendssz - size()default-inserted elements to the sequence. If an exception is thrown, there is no effect on the container.constexpr void resize(size_type sz, const T& c);-3- Preconditions:
Tis Cpp17CopyInsertable intodeque.-4- Effects: If
sz < size()istrue, erases the lastsize() - szelements from the sequence. Otherwise, appendssz - size()copies ofcto the sequence. If an exception is thrown, there is no effect on the container.
Modify 23.3.11.3 [list.capacity] as indicated:
constexpr void resize(size_type sz);-1- Preconditions:
Tis Cpp17DefaultInsertable intolist.-2- Effects: If
size() < szistrue, appendssz - size()default-inserted elements to the sequence. Ifsz <= size()istrue, equivalent to:If an exception is thrown, there is no effect on the container.list<T>::iterator it = begin(); advance(it, sz); erase(it, end());constexpr void resize(size_type sz, const T& c);-3- Preconditions:
Tis Cpp17CopyInsertable intolist.-4- Effects:
As if byEquivalent to:if (sz < size() insert(end(), sz-size(), c); else if (sz < size()) { iterator i = begin(); advance(it, sz); erase(it, end()); } else ; // do nothing