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

履歴 編集

function
<meta>

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

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

概要

クラスの静的データメンバのリフレクションを取得する。

戻り値

type完全型のクラスを表す場合、アクセスコンテキストctxでアクセス可能な静的データメンバのリフレクションを格納したvectorを返す。

例外

r完全型のクラスを表さない場合、std::meta::exception例外を送出する。

#include <meta>
#include <print>

struct S {
  static int count;
  static constexpr double pi = 3.14;
  int instance_var;
};

int main() {
  static constexpr auto statics = std::define_static_array(
      std::meta::static_data_members_of(
          ^^S, std::meta::access_context::unchecked()));
  static_assert(statics.size() == 2);

  template for (constexpr auto m : statics) {
    std::println("{}", std::meta::identifier_of(m));
  }
}

出力

count
pi

バージョン

言語

  • C++26

処理系

参照