C++26 Annotations: Metadata for Static Reflection
A quick recap
Annotations 能够给代码结构附上一些额外信息,供 Reflection 随后查找。
直接上个例子:
struct label {
int value;
};
inline constexpr label answer{42};
[[=answer]]
int x;
consteval label annotation_value() {
auto annotations = std::meta::annotations_of(^^x);
return std::meta::extract<label>(annotations[0]);
}
int main() {
constexpr auto count = std::meta::annotations_of(^^x).size();… Continue Reading