std::meta::annotations_of
| Defined in header <meta>
|
||
consteval std::vector<std::meta::info> annotations_of( std::meta::info item );
|
(since C++26) | |
Returns a vector containing reflections of annotations that apply to the entity represented by item.
If item represents a function parameter P of a function F, then let S be the set of declarations, ignoring any explicit instantiations, that are reachable from a point in the evaluation context and that declare either F or a templated function of which F is a specialization, the result contains reflections of all the annotations that apply to P in every declaration in S.
If item represents a direct base class relationship, the result contains reflections of all the annotations that apply to the corresponding base-specifier.
For any two reflections R1 and R2 in the returned vector, if the annotation represented by R1 precedes the annotation represented by R2, then R1 is before R2 in the vector. If R1 and R2 represent annotations from the same translation unit T, any elements between R1 and R2 in the returned vector represent annotations from T. The order is otherwise unspecified.
Parameters
| item | - | a reflection value |
Return value
a vector containing reflections of annotations that apply to what item represents.
Exceptions
Throws std::meta::exception unless item represents one of the following:
- type
- type alias
- variable
- function
- function parameter
- namespace
- enumerator
- direct base class relationship
- non-static data member
Example
#include <meta>
#include <print>
template<class T>
struct [[=42]] D {};
constexpr std::meta::info a1 = std::meta::annotations_of(^^D<int>)[0];
constexpr std::meta::info a2 = std::meta::annotations_of(^^D<char>)[0];
static_assert(a1 != a2);
static_assert(std::meta::constant_of(a1) == std::meta::constant_of(a2));
[[=1]] int x, y;
static_assert(std::meta::annotations_of(^^x)[0] == std::meta::annotations_of(^^y)[0]);
int main()
{
[[=3.14]] typedef int var;
typedef int var [[=42]];
static constexpr auto annotations =
std::define_static_array(std::meta::annotations_of(^^var));
template for (constexpr auto ann : annotations) {
std::println("{}", [:std::meta::constant_of(ann):]);
}
}
Output:
3.14
42
See also
(C++26) |
obtains the annotations that apply to the reflected entity and have the specified type (function) |
(C++26) |
checks if reflection represents an annotation (function) |
(C++26) |
obtains a reflection of the constant value of the reflected entity (function) |
(C++26) |
obtains a reflection of the type of the reflected entity (function) |