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
Although we believe a single opaque `std::meta::info` type to be the best and most scalable foundation for reflection, we acknowledge the desire expressed by SG7 for future support for "typeful reflection". The following demonstrates one possible means of assembling a typeful reflection library, in which different classes of reflections are represented by distinct types, on top of the facilities proposed here.
1005
+
1006
+
::: bq
1007
+
```cpp
1008
+
// Represents a 'std::meta::info' constrained by a predicate.
Note that the `metatype` class can be generalized to wrap values of any literal type, or to wrap multiple values of possibly different types. This has been used, for instance, to select compile-time overloads based on: whether two integers share the same parity, the presence or absence of a value in an `optional`, the type of the value held by a `variant` or an `any`, or the syntactic form of a compile-time string.
1072
+
1073
+
Achieving the same in C++23, with the same generality, would require spelling the argument(s) twice: first to obtain a "classification tag" to use as a template argument, and again to call the function, i.e.,
1074
+
1075
+
::: bq
1076
+
```cpp
1077
+
Printer::PrintKind<classify(^int)>(^int).
1078
+
// or worse...
1079
+
fn<classify(Arg1, Arg2, Arg3)>(Arg1, Arg2, Arg3).
1080
+
```
1081
+
:::
1082
+
1002
1083
# Proposed Features
1003
1084
1004
1085
## The Reflection Operator (`^`)
@@ -1409,6 +1490,9 @@ namespace std::meta {
1409
1490
template<typenameT>
1410
1491
consteval auto reflect_value(T value) -> info;
1411
1492
1493
+
// @[reflect_invoke](#reflect_invoke)@
1494
+
consteval auto reflect_invoke(info target, span<infoconst> args) -> info;
This metafunction produces a reflection representing the constant value of the operand.
1661
1745
1746
+
### `reflect_invoke`
1747
+
1748
+
:::bq
1749
+
```c++
1750
+
namespace std::meta {
1751
+
consteval auto reflect_invoke(info target, span<info const> args) -> info;
1752
+
}
1753
+
```
1754
+
:::
1755
+
1756
+
This metafunction produces a reflection of the value returned by a call expression.
1757
+
1758
+
Letting `F` be the entity reflected by `target`, and `A_0, ..., A_n` be the sequence of entities reflected by the values held by `args`: if the expression `F(A_0, ..., A_N)` is a well-formed constant expression evaluating to a type that is not `void`, and if every value in `args` is a reflection of a constant value, then `reflect_invoke(target, args)` evaluates to a reflection of the constant value `F(A_0, ..., A_N)`.
1759
+
1760
+
For all other invocations, `reflect_invoke(target, args)` is ill-formed.
0 commit comments