Conversation
|
まだ大量に抜けがありそう |
|
これの取り消しに対応しないといけない |
| template <typename E> | ||
| requires std::is_enum_v<E> | ||
| constexpr std::string_view to_string(E value) { | ||
| template for (constexpr auto e : std::meta::enumerators_of(^^E)) { // 型から列挙子のリストを取得 |
There was a problem hiding this comment.
template for (constexpr auto e : ~)構文でstd::vector<std::meta::info>を走査するときはstd::define_static_arrayで配列型(std::meta::info[N])に変換しておく必要があります。
template for (constexpr auto e : std::define_static_array(std::meta::enumerators_of(^^E))) {
// ...|
|
||
| // メンバのアノテーションを取得 | ||
| template for (constexpr auto m : | ||
| std::meta::nonstatic_data_members_of(^^Point, |
There was a problem hiding this comment.
要std::define_static_array
template for (constexpr auto m :
std::define_static_array(
std::meta::nonstatic_data_members_of(
^^Point, std::meta::access_context::unchecked())) {| template <typename E> | ||
| requires std::is_enum_v<E> | ||
| constexpr std::string_view enum_to_string(E value) { | ||
| template for (constexpr auto e : std::meta::enumerators_of(^^E)) { |
| constexpr std::string_view enum_to_string(E value) { | ||
| template for (constexpr auto e : std::meta::enumerators_of(^^E)) { | ||
| if (value == [:e:]) { | ||
| return std::meta::define_static_string(std::meta::identifier_of(e)); |
There was a problem hiding this comment.
std::meta::identifier_ofはstd::string_viewを返すためstd::meta::define_static_stringは不要(冗長)です。(厳密にはstd名前空間所属ですね)
|
|
||
|
|
||
| ## `define_static_string` / `define_static_array` / `define_static_object` | ||
| これらは、コンパイル時に計算した値を静的ストレージに配置し、実行時に使用可能にするための関数群である。[`std::meta::define_static_string()`](/reference/meta/define_static_string.md)は文字列を、[`std::meta::define_static_array()`](/reference/meta/define_static_array.md)は配列を、[`std::meta::define_static_object()`](/reference/meta/define_static_object.md)はオブジェクトをそれぞれ静的ストレージに配置する。 |
There was a problem hiding this comment.
define_static_XXXは名前空間stdに属します(not std::meta)
| int main() { | ||
| Point p{10, 20, "origin"}; | ||
|
|
||
| template for (constexpr auto m : |
| template <typename E> | ||
| requires std::is_enum_v<E> | ||
| constexpr std::string_view to_string(E value) { | ||
| template for (constexpr auto e : std::meta::enumerators_of(^^E)) { |
| void process(int id, double value, const char* name) {} | ||
|
|
||
| int main() { | ||
| template for (constexpr auto p : std::meta::parameters_of(^^process)) { |
| struct Name { std::string_view value; }; | ||
|
|
||
| struct [[=Name{"点"}]] Point { | ||
| [[=Name{"x座標"}]] int x; | ||
| [[=Name{"y座標"}]] int y; | ||
| }; |
There was a problem hiding this comment.
| struct Name { std::string_view value; }; | |
| struct [[=Name{"点"}]] Point { | |
| [[=Name{"x座標"}]] int x; | |
| [[=Name{"y座標"}]] int y; | |
| }; | |
| struct Name { const char* value; }; | |
| struct [[=Name{std::define_static_string("点")}]] Point { | |
| [[=Name{std::define_static_string("x座標")}]] int x; | |
| [[=Name{std::define_static_string("y座標")}]] int y; | |
| }; |
std::string_view は structural type ではありません。
また、文字列リテラルはテンプレート引数同様使えないはずで、 std::define_static_string が必要だと思います。
|
|
||
| struct Label { const char* text; }; | ||
|
|
||
| struct [[=Label{"my struct"}, =42]] S {}; |
There was a problem hiding this comment.
| struct [[=Label{"my struct"}, =42]] S {}; | |
| struct [[=Label{std::define_static_string("my struct")}, =42]] S {}; |
std::define_static_string が必要です。
| struct [[=Name{"点"}, =42]] Point { | ||
| [[=Name{"x座標"}]] int x; | ||
| [[=Name{"y座標"}]] int y; | ||
| }; |
There was a problem hiding this comment.
| struct [[=Name{"点"}, =42]] Point { | |
| [[=Name{"x座標"}]] int x; | |
| [[=Name{"y座標"}]] int y; | |
| }; | |
| struct [[=Name{std::define_static_string("点")}, =42]] Point { | |
| [[=Name{std::define_static_string("x座標")}]] int x; | |
| [[=Name{std::define_static_string("y座標")}]] int y; | |
| }; |
std::define_static_string が必要です。
| ## 概要 | ||
| `override`指定されているかを判定する。 | ||
|
|
||
|
|
||
| ## 戻り値 | ||
| `r`が`override`指定されたメンバ関数を表す場合に`true`を返す。 |
There was a problem hiding this comment.
override 指定に関係なく「オーバーライドされているか」を判定するのではないですか?
| # current | ||
| * meta[meta header] | ||
| * std::meta[meta namespace] | ||
| * std::meta::access_context[meta class] |
There was a problem hiding this comment.
| * std::meta::access_context[meta class] | |
| * access_context[meta class] |
| # designating_class | ||
| * meta[meta header] | ||
| * std::meta[meta namespace] | ||
| * std::meta::access_context[meta class] |
There was a problem hiding this comment.
| * std::meta::access_context[meta class] | |
| * access_context[meta class] |
| # scope | ||
| * meta[meta header] | ||
| * std::meta[meta namespace] | ||
| * std::meta::access_context[meta class] |
There was a problem hiding this comment.
| * std::meta::access_context[meta class] | |
| * access_context[meta class] |
| # unchecked | ||
| * meta[meta header] | ||
| * std::meta[meta namespace] | ||
| * std::meta::access_context[meta class] |
There was a problem hiding this comment.
| * std::meta::access_context[meta class] | |
| * access_context[meta class] |
| # unprivileged | ||
| * meta[meta header] | ||
| * std::meta[meta namespace] | ||
| * std::meta::access_context[meta class] |
There was a problem hiding this comment.
| * std::meta::access_context[meta class] | |
| * access_context[meta class] |
| # via | ||
| * meta[meta header] | ||
| * std::meta[meta namespace] | ||
| * std::meta::access_context[meta class] |
There was a problem hiding this comment.
| * std::meta::access_context[meta class] | |
| * access_context[meta class] |
| constexpr auto members = std::meta::members_of( | ||
| ^^S, std::meta::access_context::unchecked()); |
There was a problem hiding this comment.
std::vector<std::meta::info> をconstexpr変数で持つことはできません。
std::define_static_array で静的ストレージに配置するか、
定数式内の一時オブジェクトとして使うか、
constexprの文脈でconstexprでない変数として使うべきです。
constexpr auto members = std::define_static_array(members_of(^^S, std::meta::access_context::unchecked()));constexpr auto ctx = std::meta::access_context::unchecked();
constexpr auto member0 = members_of(^^S, ctx)[0];
constexpr auto member1 = members_of(^^S, ctx)[1];#include <cassert>
consteval {
auto members = members_of(^^S, std::meta::access_context::unchecked());
assert(type_of(parameters_of(members[0])[0]) == ^^int);
assert(type_of(parameters_of(members[1])[0]) == ^^double);
}| constexpr auto members = std::meta::nonstatic_data_members_of( | ||
| ^^S, std::meta::access_context::unchecked()); |
There was a problem hiding this comment.
std::vector<std::meta::info> をconstexpr変数で持つことはできません。
|
@yohhoy @Raclamusi |
一通り軽くチェックしたくらいなので、作業漏れチェックなどしてからマージします。