namespace std::meta {
consteval string_view symbol_of(operators op);
consteval u8string_view u8symbol_of(operators op);
}
概要
演算子の種類から記号文字列を取得する。
戻り値
演算子opに対応する記号文字列を返す。
例外
opの値がoperatorsの列挙子のいずれかに対応しない場合、std::meta::exception例外を送出する。
備考
std::meta名前空間の関数のうち、戻り値の型がstring_viewまたはu8string_viewであるものは、NULL終端された静的記憶域上の文字列を返す、というルールがある。本関数もそれに該当する。
例
#include <meta>
#include <print>
struct S {
bool operator==(const S&) const = default;
};
int main() {
template for (constexpr auto m :
std::define_static_array(std::meta::members_of(^^S, std::meta::access_context::unchecked()))) {
if constexpr (std::meta::is_operator_function(m)) {
std::println("演算子: {}", std::meta::symbol_of(std::meta::operator_of(m)));
}
}
}
出力
演算子: ==
演算子: =
演算子: =
バージョン
言語
- C++26
処理系
- Clang: ??
- GCC: 16 (
-freflectionオプション指定) ✅ - Visual C++: ??
参照
- P2996R13 Reflection for C++26
- LWG Issue 4556. Unclear properties of reflection strings
- C++26で、
string_view/u8string_viewを返すstd::metaの関数がNULL終端された静的記憶域上の文字列を返すことが明確化された
- C++26で、