Skip to content

Latest commit

 

History

History
73 lines (54 loc) · 1.89 KB

File metadata and controls

73 lines (54 loc) · 1.89 KB

subobjects_of

  • meta[meta header]
  • std::meta[meta namespace]
  • function[meta id-type]
  • cpp26[meta cpp]
namespace std::meta {
  consteval std::vector<info> subobjects_of(info type, access_context ctx);
}
  • info[link info.md]
  • access_context[link access_context.md]

概要

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

戻り値

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));
  }
}
  • std::meta::access_context[link access_context.md]
  • unchecked[link access_context/unchecked.md]
  • std::meta::display_string_of[link display_string_of.md]

出力例

Base
d

バージョン

言語

  • C++26

処理系

関連項目

参照