Skip to content

Commit 9ad3bb5

Browse files
committed
New issue from Hewill: "Container adaptor's empty/size should be noexcept"
1 parent 0eb0702 commit 9ad3bb5

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

xml/issue4371.xml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4371" status="New">
5+
<title>Container adaptor's `empty`/`size` should be `noexcept`</title>
6+
<section>
7+
<sref ref="[queue.defn]"/>
8+
<sref ref="[priqueue.overview]"/>
9+
<sref ref="[stack.defn]"/>
10+
</section>
11+
<submitter>Hewill Kang</submitter>
12+
<date>09 Sep 2025</date>
13+
<priority>99</priority>
14+
15+
<discussion>
16+
<p>
17+
C++23 container adaptors <tt>flat_<i>meow</i></tt> all have `noexcept` `size`/`empty` members.
18+
<p/>
19+
However, the `size`/`empty` members of other container adaptors are not mark `noexcept`,
20+
even though they behave the same as <tt>flat_<i>meow</i></tt> that returning the `size`/`empty`
21+
of the underlying container.
22+
<p/>
23+
It makes sense to make them `noexcept` as well for consistency. Although the standard doesn't
24+
explicitly say those two members of the container must not throw, the fact that all standard
25+
containers and common third-party containers mark them as unconditionally `noexcept` implies
26+
that it's perfectly reasonable to assume that they never will.
27+
</p>
28+
</discussion>
29+
30+
<resolution>
31+
<p>
32+
This wording is relative to <paper num="N5014"/>.
33+
</p>
34+
35+
<ol>
36+
37+
<li><p>Modify <sref ref="[queue.defn]"/> as indicated:</p>
38+
39+
<blockquote>
40+
<pre>
41+
namespace std {
42+
template&lt;class T, class Container = deque&lt;T&gt;&gt;
43+
class queue {
44+
public:
45+
[&hellip;]
46+
constexpr bool empty() const <ins>noexcept</ins> { return c.empty(); }
47+
constexpr size_type size() const <ins>noexcept</ins> { return c.size(); }
48+
[&hellip;]
49+
};
50+
[&hellip;]
51+
}
52+
</pre>
53+
</blockquote>
54+
55+
</li>
56+
57+
<li><p>Modify <sref ref="[priqueue.overview]"/> as indicated:</p>
58+
59+
<blockquote>
60+
<pre>
61+
namespace std {
62+
template&lt;class T, class Container = vector&lt;T&gt;,
63+
class Compare = less&lt;typename Container::value_type&gt;&gt;
64+
class priority_queue {
65+
public:
66+
[&hellip;]
67+
constexpr bool empty() const <ins>noexcept</ins> { return c.empty(); }
68+
constexpr size_type size() const <ins>noexcept</ins> { return c.size(); }
69+
[&hellip;]
70+
};
71+
[&hellip;]
72+
}
73+
</pre>
74+
</blockquote>
75+
76+
</li>
77+
78+
<li><p>Modify <sref ref="[stack.defn]"/> as indicated:</p>
79+
80+
<blockquote>
81+
<pre>
82+
namespace std {
83+
template&lt;class T, class Container = deque&lt;T&gt;&gt;
84+
class stack {
85+
public:
86+
[&hellip;]
87+
constexpr bool empty() const <ins>noexcept</ins> { return c.empty(); }
88+
constexpr size_type size() const <ins>noexcept</ins> { return c.size(); }
89+
[&hellip;]
90+
};
91+
[&hellip;]
92+
}
93+
</pre>
94+
</blockquote>
95+
96+
</li>
97+
98+
</ol></resolution>
99+
100+
</issue>

0 commit comments

Comments
 (0)