最終更新日時(UTC):
が更新

履歴 編集

function
<meta>

std::meta::annotations_of_with_type(C++26)

namespace std::meta {
  consteval std::vector<info> annotations_of_with_type(info item, info type);
}

概要

宣言に付加された指定した型のアノテーションのみを取得する。

戻り値

itemに付加されたアノテーションのうち、型がtypeに一致するもののリフレクションを格納したstd::vectorオブジェクトを返す。

#include <meta>
#include <print>

struct Name { const char* value; };

struct [[=Name{std::define_static_string("点")}, =42]] Point {
  [[=Name{std::define_static_string("x座標")}]] int x;
  [[=Name{std::define_static_string("y座標")}]] int y;
};

int main() {
  static_assert(std::meta::annotations_of_with_type(^^Point, ^^Name).size() == 1);
  template for (constexpr auto a :
      std::define_static_array(
          std::meta::annotations_of_with_type(^^Point, ^^Name))) {
    // constant_of()で値のリフレクションを取り出してからスプライスする
    std::println("{}", [:std::meta::constant_of(a):].value);
  }
}

出力

バージョン

言語

  • C++26

処理系

関連項目

参照