Spec-Zone.ru › C++

Annotations (since C++26)

Attach information to declarations in a way that reflection can observe.

Syntax

The list of annotations is introduced in an attribute specifier. Each annotation starts with =.

= constant-expression

Explanation

An annotation may be applied to any declaration of a type, type alias, variable, function, function parameter of non-void type, namespace, enumerator, base-specifier, or non-static data member.

Let E be std::meta::reflect_constant(expr) (where expr is the constant-expression), E must be a constant expression. The result of E can be observed by calling std::meta::constant_of on the reflection of the annotation.

Annotations are always distinct from one another, even if they have equivalent values and are applied to the same declaration.

[[=42, =42]] int x;
static_assert(std::meta::annotations_of(^^x).size() == 2);

[[=42]] int f();
[[=24]] int f();
static_assert(std::meta::annotations_of(^^f).size() == 2);

Substituting into an annotation is not an immediate context.

Example

See also

annotations_of
(C++26)
obtains the annotations applying to the reflected entity
(function)
annotations_of_with_type
(C++26)
obtains the annotations that apply to the reflected entity and have the specified type
(function)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/language/annotations

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API