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

履歴 編集

function
<meta>

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

namespace std::meta {
  consteval std::vector<info> members_of(info r, access_context ctx);
}

概要

クラスまたは名前空間のすべてのメンバのリフレクションを取得する。

戻り値

r完全型のクラスまたは名前空間を表す場合、アクセスコンテキストctxでアクセス可能なすべてのメンバのリフレクションを格納したvectorを返す。

例外

r完全型のクラスまたは名前空間を表さない場合、std::meta::exception例外を送出する。

#include <meta>
#include <print>

struct S {
  int x;
  double y;
  void f() {}
};

int main() {
  constexpr auto count = std::meta::members_of(
      ^^S, std::meta::access_context::unchecked()).size();
  std::println("メンバ数: {}", count);
}

出力例

メンバ数: 9

バージョン

言語

  • C++26

処理系

関連項目

参照