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

履歴 編集

function
<meta>

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

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

概要

クラスの基底クラスとメンバ変数を統合して取得する。

戻り値

type完全型のクラスを表す場合、アクセスコンテキストctxでアクセス可能な直接基底クラス関係とメンバ変数のリフレクションを格納したstd::vectorオブジェクトを返す。基底クラスがメンバ変数より先に配置される。

例外

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

#include <meta>
#include <print>

struct Base { int b; };
struct Derived : Base { int d; };

int main() {
  static constexpr auto subs = std::define_static_array(
      std::meta::subobjects_of(
          ^^Derived, std::meta::access_context::unchecked()));

  // 基底クラスが先、メンバ変数が後
  template for (constexpr auto s : subs) {
    std::println("{}", std::meta::display_string_of(s));
  }
}

出力例

Base
d

バージョン

言語

  • C++26

処理系

関連項目

参照