Skip to content

Commit d3797ae

Browse files
committed
New issue from Jiang An: "Complexity of std::visit with immediate functions"
1 parent 3be69af commit d3797ae

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

xml/issue4197.xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4197" status="New">
5+
<title>Complexity of `std::visit` with immediate functions</title>
6+
<section><sref ref="[variant.visit]"/></section>
7+
<submitter>Jiang An</submitter>
8+
<date>26 Jan 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
`std::visit` generally needs to be implemented with "vtables" that contain function pointers.
14+
When `std::visit` needs to call an immediate function (e.g. when passing a lambda whose
15+
`operator()` is `consteval`), the vtable will contain a pointer to an immediate-escalated
16+
function, which forbids the vtable from being a `constexpr` variable.
17+
<p/>
18+
In order to properly handle immediate functions in `std::visit`, it seems necessary to form
19+
the vtable, or do some non-constant-time lookup each time when calling `std::visit`. In other words,
20+
<sref ref="[variant.visit]"/>/8 seems to be unimplementable when an immediate function is involved.
21+
</p>
22+
</discussion>
23+
24+
<resolution>
25+
<p>
26+
This wording is relative to <paper num="N5001"/>.
27+
</p>
28+
29+
<ol>
30+
31+
<li><p>Modify <sref ref="[variant.visit]"/> as indicated:</p>
32+
33+
<blockquote>
34+
<pre>
35+
template&lt;class Visitor, class... Variants&gt;
36+
constexpr <i>see below</i> visit(Visitor&amp;&amp; vis, Variants&amp;&amp;... vars);
37+
template&lt;class R, class Visitor, class... Variants&gt;
38+
constexpr R visit(Visitor&amp;&amp; vis, Variants&amp;&amp;... vars);
39+
</pre>
40+
<blockquote>
41+
<p>
42+
-1- [&hellip;] Let <tt><i>n</i></tt> be `sizeof...(Variants)`. [&hellip;]
43+
<p/>
44+
[&hellip;]
45+
<p/>
46+
-8- <i>Complexity</i>: <ins>If <tt><i>n</i> &gt; 1</tt> or any of the aforementioned <tt><i>INVOKE</i></tt>
47+
operations calls an immediate function, the invocation of the callable object has no complexity requirements.
48+
Otherwise</ins><del>For <tt><i>n</i> &le; 1</tt></del>, the invocation of the callable object is
49+
implemented in constant time, i.e., for <tt><i>n</i> = 1</tt>, it does not depend on the number
50+
of alternative types of <tt>V<sub>0</sub></tt>. <del>For <tt><i>n</i> &gt; 1</tt>, the invocation of
51+
the callable object has no complexity requirements.</del>
52+
</p>
53+
</blockquote>
54+
</blockquote>
55+
</li>
56+
</ol>
57+
</resolution>
58+
59+
</issue>

0 commit comments

Comments
 (0)