Skip to content

Commit 30f08f8

Browse files
author
github-actions
committed
Automatic update from GitHub Actions workflow
1 parent 41f124f commit 30f08f8

22 files changed

+376
-47
lines changed

issue4281.html

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Issue 4281: Inconsistency between value_or() and error_or() in std::expected</title>
6+
<meta property="og:title" content="Issue 4281: Inconsistency between value_or() and error_or() in std::expected">
7+
<meta property="og:description" content="C++ library issue. Status: New">
8+
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4281.html">
9+
<meta property="og:type" content="website">
10+
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
11+
<meta property="og:image:alt" content="C++ logo">
12+
<style>
13+
p {text-align:justify}
14+
li {text-align:justify}
15+
pre code.backtick::before { content: "`" }
16+
pre code.backtick::after { content: "`" }
17+
blockquote.note
18+
{
19+
background-color:#E0E0E0;
20+
padding-left: 15px;
21+
padding-right: 15px;
22+
padding-top: 1px;
23+
padding-bottom: 1px;
24+
}
25+
ins {background-color:#A0FFA0}
26+
del {background-color:#FFA0A0}
27+
table.issues-index { border: 1px solid; border-collapse: collapse; }
28+
table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
29+
table.issues-index td { padding: 4px; border: 1px solid; }
30+
table.issues-index td:nth-child(1) { text-align: right; }
31+
table.issues-index td:nth-child(2) { text-align: left; }
32+
table.issues-index td:nth-child(3) { text-align: left; }
33+
table.issues-index td:nth-child(4) { text-align: left; }
34+
table.issues-index td:nth-child(5) { text-align: center; }
35+
table.issues-index td:nth-child(6) { text-align: center; }
36+
table.issues-index td:nth-child(7) { text-align: left; }
37+
table.issues-index td:nth-child(5) span.no-pr { color: red; }
38+
@media (prefers-color-scheme: dark) {
39+
html {
40+
color: #ddd;
41+
background-color: black;
42+
}
43+
ins {
44+
background-color: #225522
45+
}
46+
del {
47+
background-color: #662222
48+
}
49+
a {
50+
color: #6af
51+
}
52+
a:visited {
53+
color: #6af
54+
}
55+
blockquote.note
56+
{
57+
background-color: rgba(255, 255, 255, .10)
58+
}
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
<hr>
64+
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p>
65+
<h3 id="4281"><a href="lwg-active.html#4281">4281</a>. Inconsistency between <code class='backtick'>value_or()</code> and <code class='backtick'>error_or()</code> in <code class='backtick'>std::expected</code></h3>
66+
<p><b>Section:</b> 22.5.3.7 <a href="https://wg21.link/optional.observe">[optional.observe]</a>, 22.8.6.6 <a href="https://wg21.link/expected.object.obs">[expected.object.obs]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
67+
<b>Submitter:</b> Hiroaki Ando <b>Opened:</b> 2025-06-27 <b>Last modified:</b> 2025-06-27</p>
68+
<p><b>Priority: </b>Not Prioritized
69+
</p>
70+
<p><b>View other</b> <a href="lwg-index-open.html#optional.observe">active issues</a> in [optional.observe].</p>
71+
<p><b>View all other</b> <a href="lwg-index.html#optional.observe">issues</a> in [optional.observe].</p>
72+
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
73+
<p><b>Discussion:</b></p>
74+
<p>
75+
In 22.8.6.6 <a href="https://wg21.link/expected.object.obs">[expected.object.obs]</a>/19, the return value of <code class='backtick'>value_or()</code>
76+
is specified as follows:
77+
<blockquote>
78+
<i>Returns</i>:
79+
<code>has_value() ? **this : static_cast&lt;T&gt;(std::forward&lt;U&gt;(v))</code>.
80+
</blockquote>
81+
82+
Meanwhile, the return value of <code class='backtick'>error_or()</code> is specified as follows (22.8.6.6 <a href="https://wg21.link/expected.object.obs">[expected.object.obs]</a>/23):
83+
<blockquote>
84+
<i>Returns</i>:
85+
<code>std::forward&lt;G&gt;(e)</code> if <code>has_value()</code> is <code>true</code>, <code>error()</code> otherwise.
86+
</blockquote>
87+
Since these functions appear to be dual in nature,
88+
it would be preferable to maintain consistent notation.
89+
</p>
90+
<p>
91+
Jonathan adds:
92+
The wording in <code class='backtick'>expected::error_or</code> is newer, having been added by
93+
<a href="https://wg21.link/P2505R5" title=" Monadic Functions for std::expected">P2505R5</a>, and intentionally avoided a conditional expression
94+
(the problems with conditional expressions explained in <a href="https://wg21.link/P3177R0" title=" const prvalues in the conditional operator">P3177R0</a>
95+
don't actually affect these member functions, due to the non-const prvalue
96+
return type, but determining that there are no pessimized copies in <code class='backtick'>value_or</code>
97+
wouldn't be necessary if we didn't specify it with a conditional expression).
98+
The <code class='backtick'>error_or</code> wording also avoids using an explicit conversion when the
99+
<i>Mandates</i>: element requires implicit conversion to work anyway.
100+
We might want to rephrase the <code class='backtick'>value_or</code> wording to match <code class='backtick'>error_or</code>,
101+
or possibly make <code class='backtick'>value_or</code> and <code class='backtick'>error_or</code> even more explicit:
102+
</p>
103+
<blockquote>
104+
<i>Effects</i>: Equivalent to:
105+
<pre><code>
106+
if (has_value())
107+
return **this;
108+
else
109+
return std::forward&lt;U&gt;(v);
110+
</code></pre>
111+
</blockquote>
112+
113+
114+
<p id="res-4281"><b>Proposed resolution:</b></p>
115+
<p>
116+
</p>
117+
118+
119+
120+
121+
122+
</body>
123+
</html>

0 commit comments

Comments
 (0)