You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Ever since writing <spanclass="title"><spanclass="citation" data-cites="P1240R0">[<ahref="https://wg21.link/p1240r0" role="doc-biblioref">P1240R0</a>]</span></span>, but more so since <spanclass="title"><spanclass="citation" data-cites="P2996R0">[<ahref="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 <spanclass="title"><spanclass="citation" data-cites="P1240R0"><ahref="https://wg21.link/p1240r0" role="doc-biblioref">[P1240R0] (Scalable Reflection in
647
+
C++)</a></span></span>, but more so since <spanclass="title"><spanclass="citation" data-cites="P2996R0"><ahref="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
649
651
post to the <ahref="https://lists.isocpp.org/sg7/2023/10/0450.php">SG7
650
652
reflector</a>. Corentin Jabot also noticed the need while P1240 was
651
-
evolving and wrote <spanclass="title"><spanclass="citation" data-cites="P1887R0">[<ahref="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 <spanclass="title"><spanclass="citation" data-cites="P1887R0"><ahref="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>
653
656
<p>In early versions of P2996 (and P1240 before that), a workaround was
654
657
to encode properties in the template arguments of alias template
class is complete. Before completeness allows the class to observe the
1214
1217
annotation during instantiation. After completeness allows the
1215
1218
annotation callback to observe properties of the type. In some sense,
1216
-
Herb Sutter’s <spanclass="title"><spanclass="citation" data-cites="P0707R4">[<ahref="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 <spanclass="title"><spanclass="citation" data-cites="P0707R4"><ahref="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>
1219
1222
<p>One concrete, simpler example. We can, with this proposal as-is,
1220
1223
create a <codeclass="sourceCode cpp">Debug</code> annotation that a
1221
1224
user can add to their type and a specialization of <codeclass="sourceCode cpp">std<spanclass="op">::</span>formatter</code> for
<codeclass="sourceCode cpp">Point</code>, inject an explicit
1254
1257
specialization of <codeclass="sourceCode cpp">std<spanclass="op">::</span>formatter</code>.
1255
1258
This would rely both on the ability for the annotation to be called back
1256
-
and language support for such injection (see <spanclass="title"><spanclass="citation" data-cites="P3294R2">[<ahref="https://wg21.link/p3294r2" role="doc-biblioref">P3294R2</a>]</span></span>).</p>
1259
+
and language support for such injection (see <spanclass="title"><spanclass="citation" data-cites="P3294R2"><ahref="https://wg21.link/p3294r2" role="doc-biblioref">[P3294R2] (Code
1260
+
Injection with Token Sequences)</a></span></span>).</p>
1257
1261
<p>There are still open questions as to how to handle such callbacks.
1258
1262
Does an annotation that gets called back merit different syntax from an
1259
1263
annotation that doesn’t? Can it mutate the entity that it is attached
<p>The wording is relative to <spanclass="citation" data-cites="P2996R9">[<ahref="https://wg21.link/p2996r9" role="doc-biblioref">P2996R9</a>]</span>.</p>
1275
+
<p>The wording is relative to <spanclass="citation" data-cites="P2996R9"><ahref="https://wg21.link/p2996r9" role="doc-biblioref">[P2996R9]</a></span>.</p>
<spanid="cb26-20"><ahref="#cb26-20" aria-hidden="true" tabindex="-1"></a><spanclass="va">+ consteval info annotate(info item, info value, source_location loc = source_location::current());</span></span>
<spanid="cb26-12"><ahref="#cb26-12" aria-hidden="true" tabindex="-1"></a><spanclass="va">+ consteval info annotate(info item, info value, source_location loc = source_location::current());</span></span>
0 commit comments