std::meta::annotations_of_with_type

来自cppreference.com
< cpp | meta
 
 
 
反射库
 
反射类型与查询
反射查询
反射布局查询
类型属性
类型属性查询
 
在标头 <meta> 定义
consteval std::vector<std::meta::info>
    annotations_of_with_type( std::meta::info item, std::meta::info type );
(C++26 起)

返回根据 type 所表示的类型过滤后的 std::meta::annotations_of(item) 的结果。

参数

item - 一个反射值
type - 类型或类型别名的反射

返回值

一个 vector,包含 std::meta::annotations_of(item) 中满足条件的所有元素 estd::meta::remove_const(std::meta::type_of(e)) 等于 std::meta::remove_const(type),并保持原有顺序。

异常

如果 std::meta::annotations_of(item) 会抛出异常,或者满足以下任一条件,则抛出 std::meta::exception

  • std::meta::dealias(type) 不表示类型,或
  • std::meta::is_complete_type(type)false

示例

#include <meta>

struct Option { bool value; };

struct C {
    [[=Option{true}]] int a;
    [[=Option{false}]] int b;
};

static_assert([:annotations_of_with_type(^^C::a, ^^Option)[0]:].value);
static_assert(![:annotations_of_with_type(^^C::b, ^^Option)[0]:].value);

int main() {}

参阅

获取应用于所反射实体的标注
(函数) [编辑]
检查反射是否表示标注
(函数) [编辑]
获取所反射实体的常量值的反射
(函数) [编辑]
(C++26)
获取所反射实体的类型的反射
(函数) [编辑]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.