namespace std::meta {
consteval string_view identifier_of(info r);
consteval u8string_view u8identifier_of(info r);
}
概要
リフレクションの識別子を文字列で取得する。
戻り値
rの識別子を返す。has_identifier(r)がtrueであり、識別子が返す文字エンコーディングで表現可能であることが事前条件となる。
例外
has_identifier(r)がfalseの場合、または返される識別子が文字エンコーディングで表現できない場合、std::meta::exception例外を送出する。
備考
std::meta名前空間の関数のうち、戻り値の型がstring_viewまたはu8string_viewであるものは、NULL終端された静的記憶域上の文字列を返す、というルールがある。本関数もそれに該当する。
例
#include <meta>
#include <print>
struct Point {
int x;
int y;
};
int main() {
template for (constexpr auto m :
std::define_static_array(std::meta::nonstatic_data_members_of(^^Point,
std::meta::access_context::unchecked()))) {
std::println("{}", std::meta::identifier_of(m));
}
}
出力
x
y
バージョン
言語
- C++26
処理系
- Clang: ??
- GCC: 16 (
-freflectionオプション指定) ✅ - Visual C++: ??
参照
- P2996R13 Reflection for C++26
- P3096R12 Function Parameter Reflection in Reflection for C++26
- LWG Issue 4556. Unclear properties of reflection strings
- C++26で、
string_view/u8string_viewを返すstd::metaの関数がNULL終端された静的記憶域上の文字列を返すことが明確化された
- C++26で、