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
処理系
- Clang: ??
- GCC: 16 (
-freflectionオプション指定) ✅ - Visual C++: ??