Skip to content

Commit 299deec

Browse files
committed
Updating API
1 parent e2dd990 commit 299deec

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

3394_annotations/annotations.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -615,15 +615,7 @@ namespace std::meta {
615615

616616
// [meta.reflection.annotation], annotation reflection
617617
+ consteval vector<info> annotations_of(info item);
618-
+ consteval vector<info> annotations_of(info item, info type);
619-
+
620-
+ template<class T>
621-
+ consteval optional<T> annotation_of(info item);
622-
+
623-
+ template<class T>
624-
+ consteval bool has_annotation(info item);
625-
+ template<class T>
626-
+ consteval bool has_annotation(info item, T const& value);
618+
+ consteval vector<info> annotations_of_with_type(info item, info type);
627619
+
628620
+ consteval info annotate(info item, info value, source_location loc = source_location::current());
629621
}

3394_annotations/d3394r2.html

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta name="generator" content="mpark/wg21" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7-
<meta name="dcterms.date" content="2025-01-29" />
7+
<meta name="dcterms.date" content="2025-02-12" />
88
<title>Annotations for Reflection</title>
99
<style>
1010
code{white-space: pre-wrap;}
@@ -569,7 +569,7 @@ <h1 class="title" style="text-align:center">Annotations for
569569
</tr>
570570
<tr>
571571
<td>Date:</td>
572-
<td>2025-01-29</td>
572+
<td>2025-02-12</td>
573573
</tr>
574574
<tr>
575575
<td style="vertical-align:top">Project:</td>
@@ -631,25 +631,28 @@ <h1 id="toctitle">Contents</h1>
631631
</div>
632632
<h1 data-number="1" style="border-bottom:1px solid #cccccc" id="revision-history"><span class="header-section-number">1</span>
633633
Revision History<a href="#revision-history" class="self-link"></a></h1>
634-
<p>Since <span class="citation" data-cites="P3394R1">[<a href="https://wg21.link/p3394r1" role="doc-biblioref">P3394R1</a>]</span>:</p>
634+
<p>Since <span class="citation" data-cites="P3394R1"><a href="https://wg21.link/p3394r1" role="doc-biblioref">[P3394R1]</a></span>:</p>
635635
<ul>
636636
<li>loosened the P2996 scope restrictions around injected declarations:
637637
allow the definition of an entity to produce injected declaration of
638638
itself</li>
639639
</ul>
640-
<p>Since <span class="citation" data-cites="P3394R0">[<a href="https://wg21.link/p3394r0" role="doc-biblioref">P3394R0</a>]</span>:</p>
640+
<p>Since <span class="citation" data-cites="P3394R0"><a href="https://wg21.link/p3394r0" role="doc-biblioref">[P3394R0]</a></span>:</p>
641641
<ul>
642642
<li>added wording</li>
643643
</ul>
644644
<h1 data-number="2" style="border-bottom:1px solid #cccccc" id="introduction"><span class="header-section-number">2</span>
645645
Introduction<a href="#introduction" class="self-link"></a></h1>
646-
<p>Ever since writing <span class="title"><span class="citation" data-cites="P1240R0">[<a href="https://wg21.link/p1240r0" role="doc-biblioref">P1240R0</a>]</span></span>, but more so since <span class="title"><span class="citation" data-cites="P2996R0">[<a href="https://wg21.link/p2996r0" role="doc-biblioref">P2996R0</a>]</span></span>, we have been requested
647-
to add a capability to annotate declarations in a way that reflection
648-
can observe. For example, Jeremy Ong presented compelling arguments in a
646+
<p>Ever since writing <span class="title"><span class="citation" data-cites="P1240R0"><a href="https://wg21.link/p1240r0" role="doc-biblioref">[P1240R0] (Scalable Reflection in
647+
C++)</a></span></span>, but more so since <span class="title"><span class="citation" data-cites="P2996R0"><a href="https://wg21.link/p2996r0" role="doc-biblioref">[P2996R0]
648+
(Reflection for C++26)</a></span></span>, we have been requested to add
649+
a capability to annotate declarations in a way that reflection can
650+
observe. For example, Jeremy Ong presented compelling arguments in a
649651
post to the <a href="https://lists.isocpp.org/sg7/2023/10/0450.php">SG7
650652
reflector</a>. Corentin Jabot also noticed the need while P1240 was
651-
evolving and wrote <span class="title"><span class="citation" data-cites="P1887R0">[<a href="https://wg21.link/p1887r0" role="doc-biblioref">P1887R0</a>]</span></span>, which proposes syntax
652-
not entirely unlike what we present here.</p>
653+
evolving and wrote <span class="title"><span class="citation" data-cites="P1887R0"><a href="https://wg21.link/p1887r0" role="doc-biblioref">[P1887R0] (Typesafe Reflection on
654+
attributes)</a></span></span>, which proposes syntax not entirely unlike
655+
what we present here.</p>
653656
<p>In early versions of P2996 (and P1240 before that), a workaround was
654657
to encode properties in the template arguments of alias template
655658
specializations:</p>
@@ -1213,9 +1216,9 @@ <h2 data-number="4.5" id="other-directions-we-are-exploring"><span class="header
12131216
class is complete. Before completeness allows the class to observe the
12141217
annotation during instantiation. After completeness allows the
12151218
annotation callback to observe properties of the type. In some sense,
1216-
Herb Sutter’s <span class="title"><span class="citation" data-cites="P0707R4">[<a href="https://wg21.link/p0707r4" role="doc-biblioref">P0707R4</a>]</span></span> was adding annotations
1217-
on classes, invoked on class completeness, that allow mutation of the
1218-
class.</p>
1219+
Herb Sutter’s <span class="title"><span class="citation" data-cites="P0707R4"><a href="https://wg21.link/p0707r4" role="doc-biblioref">[P0707R4] (Metaclasses: Generative
1220+
C++)</a></span></span> was adding annotations on classes, invoked on
1221+
class completeness, that allow mutation of the class.</p>
12191222
<p>One concrete, simpler example. We can, with this proposal as-is,
12201223
create a <code class="sourceCode cpp">Debug</code> annotation that a
12211224
user can add to their type and a specialization of <code class="sourceCode cpp">std<span class="op">::</span>formatter</code> for
@@ -1253,7 +1256,8 @@ <h2 data-number="4.5" id="other-directions-we-are-exploring"><span class="header
12531256
<code class="sourceCode cpp">Point</code>, inject an explicit
12541257
specialization of <code class="sourceCode cpp">std<span class="op">::</span>formatter</code>.
12551258
This would rely both on the ability for the annotation to be called back
1256-
and language support for such injection (see <span class="title"><span class="citation" data-cites="P3294R2">[<a href="https://wg21.link/p3294r2" role="doc-biblioref">P3294R2</a>]</span></span>).</p>
1259+
and language support for such injection (see <span class="title"><span class="citation" data-cites="P3294R2"><a href="https://wg21.link/p3294r2" role="doc-biblioref">[P3294R2] (Code
1260+
Injection with Token Sequences)</a></span></span>).</p>
12571261
<p>There are still open questions as to how to handle such callbacks.
12581262
Does an annotation that gets called back merit different syntax from an
12591263
annotation that doesn’t? Can it mutate the entity that it is attached
@@ -1268,7 +1272,7 @@ <h2 data-number="4.5" id="other-directions-we-are-exploring"><span class="header
12681272
be invoked when an entity is first declared with an annotation of type
12691273
<code class="sourceCode cpp">X</code>).</p>
12701274
<h1 data-number="5" style="border-bottom:1px solid #cccccc" id="wording"><span class="header-section-number">5</span> Wording<a href="#wording" class="self-link"></a></h1>
1271-
<p>The wording is relative to <span class="citation" data-cites="P2996R9">[<a href="https://wg21.link/p2996r9" role="doc-biblioref">P2996R9</a>]</span>.</p>
1275+
<p>The wording is relative to <span class="citation" data-cites="P2996R9"><a href="https://wg21.link/p2996r9" role="doc-biblioref">[P2996R9]</a></span>.</p>
12721276
<h2 data-number="5.1" id="language"><span class="header-section-number">5.1</span> Language<a href="#language" class="self-link"></a></h2>
12731277
<p>Change <span>6.8.2 <a href="https://wg21.link/basic.fundamental">[basic.fundamental]</a></span>
12741278
to add “annotation” to the list of reflection kinds:</p>
@@ -1456,18 +1460,10 @@ <h2 data-number="5.2" id="library"><span class="header-section-number">5.2</span
14561460
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a></span>
14571461
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a> // [meta.reflection.annotation], annotation reflection</span>
14581462
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a><span class="va">+ consteval vector&lt;info&gt; annotations_of(info item);</span></span>
1459-
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a><span class="va">+ consteval vector&lt;info&gt; annotations_of(info item, info type);</span></span>
1463+
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a><span class="va">+ consteval vector&lt;info&gt; annotations_of_with_type(info item, info type);</span></span>
14601464
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true" tabindex="-1"></a><span class="va">+</span></span>
1461-
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true" tabindex="-1"></a><span class="va">+ template&lt;class T&gt;</span></span>
1462-
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true" tabindex="-1"></a><span class="va">+ consteval optional&lt;T&gt; annotation_of(info item);</span></span>
1463-
<span id="cb26-14"><a href="#cb26-14" aria-hidden="true" tabindex="-1"></a><span class="va">+</span></span>
1464-
<span id="cb26-15"><a href="#cb26-15" aria-hidden="true" tabindex="-1"></a><span class="va">+ template&lt;class T&gt;</span></span>
1465-
<span id="cb26-16"><a href="#cb26-16" aria-hidden="true" tabindex="-1"></a><span class="va">+ consteval bool has_annotation(info item);</span></span>
1466-
<span id="cb26-17"><a href="#cb26-17" aria-hidden="true" tabindex="-1"></a><span class="va">+ template&lt;class T&gt;</span></span>
1467-
<span id="cb26-18"><a href="#cb26-18" aria-hidden="true" tabindex="-1"></a><span class="va">+ consteval bool has_annotation(info item, T const&amp; value);</span></span>
1468-
<span id="cb26-19"><a href="#cb26-19" aria-hidden="true" tabindex="-1"></a><span class="va">+</span></span>
1469-
<span id="cb26-20"><a href="#cb26-20" aria-hidden="true" tabindex="-1"></a><span class="va">+ consteval info annotate(info item, info value, source_location loc = source_location::current());</span></span>
1470-
<span id="cb26-21"><a href="#cb26-21" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
1465+
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true" tabindex="-1"></a><span class="va">+ consteval info annotate(info item, info value, source_location loc = source_location::current());</span></span>
1466+
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
14711467
</div>
14721468
</blockquote>
14731469
</div>
@@ -1811,12 +1807,12 @@ <h1 data-number="6" style="border-bottom:1px solid #cccccc" id="bibliography"><s
18111807
2024-10-15. Code Injection with Token Sequences. <a href="https://wg21.link/p3294r2"><div class="csl-block">https://wg21.link/p3294r2</div></a>
18121808
</div>
18131809
<div id="ref-P3394R0" class="csl-entry" role="doc-biblioentry">
1814-
[P3394R0] Daveed Vandevoorde, Wyatt Childers, Barry Revzin, Dan Katz.
1815-
2024-10-14. Annotations for Reflection. <a href="https://wg21.link/p3394r0"><div class="csl-block">https://wg21.link/p3394r0</div></a>
1810+
[P3394R0] Daveed Vandevoorde, Wyatt Childers, Dan Katz,. 2024-10-14.
1811+
Annotations for Reflection. <a href="https://wg21.link/p3394r0"><div class="csl-block">https://wg21.link/p3394r0</div></a>
18161812
</div>
18171813
<div id="ref-P3394R1" class="csl-entry" role="doc-biblioentry">
1818-
[P3394R1] Daveed Vandevoorde, Wyatt Childers, Barry Revzin, Dan Katz.
1819-
2025-01-12. Annotations for Reflection. <a href="https://wg21.link/p3394r1"><div class="csl-block">https://wg21.link/p3394r1</div></a>
1814+
[P3394R1] Daveed Vandevoorde, Wyatt Childers, Dan Katz, Barry Revzin.
1815+
2025-01-13. Annotations for Reflection. <a href="https://wg21.link/p3394r1"><div class="csl-block">https://wg21.link/p3394r1</div></a>
18201816
</div>
18211817
</div>
18221818
</div>

0 commit comments

Comments
 (0)