|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4164" status="New"> |
| 5 | +<title>Missing guarantees for `forward_list` modifiers</title> |
| 6 | +<section><sref ref="[forward.list.modifiers]"/></section> |
| 7 | +<submitter>Jonathan Wakely</submitter> |
| 8 | +<date>05 Oct 2024</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +The new `std::list` members added by <paper num="p1206r7"/>, |
| 14 | +<code>insert_range(const_iterator, R&&)</code>, |
| 15 | +<code>prepend_range(R&&)</code>, and |
| 16 | +<code>append_range(R&&)</code>, |
| 17 | +have the same exception safety guarantee as |
| 18 | +`std::list::insert(const_iterator, InputIterator, InputIterator)`, which is: |
| 19 | +<blockquote> |
| 20 | +<i>Remarks</i>: |
| 21 | +Does not affect the validity of iterators and references. |
| 22 | +If an exception is thrown, there are no effects. |
| 23 | +</blockquote> |
| 24 | +</p> |
| 25 | +<p> |
| 26 | +This guarantee was achieved for the new `list` functions simply by placing |
| 27 | +them in the same set of declarations as the existing `insert` overloads, |
| 28 | +at the start of <sref ref="[list.modifiers]"/>. |
| 29 | +</p> |
| 30 | + |
| 31 | +<p> |
| 32 | +However, the new `std::forward_list` members, |
| 33 | +<code>insert_range_after(const_iterator, R&&)</code> and |
| 34 | +<code>prepend_range(R&&)</code>, |
| 35 | +do not have the same guarantee as `forward_list::insert_after`. |
| 36 | +This looks like an omission caused by the fact that `insert_after`'s |
| 37 | +exception safety guarantee is given in a separate paragraph at the start |
| 38 | +of <sref ref="[forward.list.modifiers]"/>: |
| 39 | +<blockquote> |
| 40 | +None of the overloads of `insert_after` |
| 41 | +shall affect the validity of iterators and references, |
| 42 | +and `erase_after` shall invalidate only iterators and references |
| 43 | +to the erased elements. |
| 44 | +If an exception is thrown during `insert_after` there shall be no effect. |
| 45 | +</blockquote> |
| 46 | +</p> |
| 47 | + |
| 48 | +<p> |
| 49 | +I think we should give similar guarantees for `insert_range_after` |
| 50 | +and `prepend_range`. |
| 51 | +The change might also be appropriate for `emplace_after` as well. |
| 52 | +A "no effects" guarantee is already given for `push_front` and `emplace_front` |
| 53 | +in <sref ref="[container.reqmts]"/> p66, although that doesn't say anything |
| 54 | +about iterator invalidation so we might want to add that to |
| 55 | +<sref ref="[forward.list.modifiers]"/> too. |
| 56 | +</p> |
| 57 | + |
| 58 | +</discussion> |
| 59 | + |
| 60 | +<resolution> |
| 61 | +<p>This wording is relative to <paper num="n4988"/>.</p> |
| 62 | + |
| 63 | +<ol> |
| 64 | +<li> |
| 65 | +<p>Change <sref ref="[forward.list.modifiers]"/> as indicated:</p> |
| 66 | +<blockquote> |
| 67 | +None of the <del>overloads of `insert_after` shall</del> |
| 68 | +<ins>member functions in this subclause that insert elements</ins> |
| 69 | +affect the validity of iterators and references, |
| 70 | +and `erase_after` <del>shall invalidate</del> <ins>invalidates</ins> |
| 71 | +only iterators and references to the erased elements. |
| 72 | +If an exception is thrown |
| 73 | +<del>during `insert_after`</del> |
| 74 | +<ins>by any of these member functions that insert elements</ins> |
| 75 | +there <del>shall be</del> <ins>is</ins> no effect |
| 76 | +<ins>on the `forward_list`</ins>. |
| 77 | +</blockquote> |
| 78 | + |
| 79 | +</li> |
| 80 | +</ol> |
| 81 | + |
| 82 | +</resolution> |
| 83 | + |
| 84 | +</issue> |
0 commit comments