Skip to content

C++26リフレクションに対応#1607

Open
faithandbrave wants to merge 3 commits intomasterfrom
cpp26_reflection
Open

C++26リフレクションに対応#1607
faithandbrave wants to merge 3 commits intomasterfrom
cpp26_reflection

Conversation

@faithandbrave
Copy link
Copy Markdown
Member

一通り軽くチェックしたくらいなので、作業漏れチェックなどしてからマージします。

@faithandbrave
Copy link
Copy Markdown
Member Author

まだ大量に抜けがありそう

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

プレビュー (HTML) (更新時刻: 2026-04-10 11:10:02 JST)

  • Commit: 6d21c35
  • プレビューの生成には時間がかかります (3~5分)。進捗状況はこちらをご確認ください。

変更記事一覧

258件の記事が変更されました。多いため一部を表示しています。完全なリストについてはこちらをご参照ください。

(ファイル一覧)

※ソース (.md) に直接変更のあった記事を列挙しています。グローバル修飾や変換規則の変更による変化は考慮していません。

@faithandbrave
Copy link
Copy Markdown
Member Author

これの取り消しに対応しないといけない

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)) { // 型から列挙子のリストを取得
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::define_static_array

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));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::meta::identifier_ofstd::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)はオブジェクトをそれぞれ静的ストレージに配置する。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define_static_XXXは名前空間stdに属します(not std::meta

int main() {
Point p{10, 20, "origin"};

template for (constexpr auto m :
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::define_static_array

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)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::define_static_array

void process(int id, double value, const char* name) {}

int main() {
template for (constexpr auto p : std::meta::parameters_of(^^process)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::define_static_array

Comment on lines +231 to +236
struct Name { std::string_view value; };

struct [[=Name{"点"}]] Point {
[[=Name{"x座標"}]] int x;
[[=Name{"y座標"}]] int y;
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct [[=Label{"my struct"}, =42]] S {};
struct [[=Label{std::define_static_string("my struct")}, =42]] S {};

std::define_static_string が必要です。

Comment on lines +29 to +32
struct [[=Name{"点"}, =42]] Point {
[[=Name{"x座標"}]] int x;
[[=Name{"y座標"}]] int y;
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 が必要です。

Comment on lines +14 to +19
## 概要
`override`指定されているかを判定する。


## 戻り値
`r`が`override`指定されたメンバ関数を表す場合に`true`を返す。
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

override 指定に関係なく「オーバーライドされているか」を判定するのではないですか?

# current
* meta[meta header]
* std::meta[meta namespace]
* std::meta::access_context[meta class]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* std::meta::access_context[meta class]
* access_context[meta class]

# scope
* meta[meta header]
* std::meta[meta namespace]
* std::meta::access_context[meta class]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* std::meta::access_context[meta class]
* access_context[meta class]

# unchecked
* meta[meta header]
* std::meta[meta namespace]
* std::meta::access_context[meta class]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* std::meta::access_context[meta class]
* access_context[meta class]

# unprivileged
* meta[meta header]
* std::meta[meta namespace]
* std::meta::access_context[meta class]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* std::meta::access_context[meta class]
* access_context[meta class]

# via
* meta[meta header]
* std::meta[meta namespace]
* std::meta::access_context[meta class]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* std::meta::access_context[meta class]
* access_context[meta class]

Comment on lines +97 to +98
constexpr auto members = std::meta::members_of(
^^S, std::meta::access_context::unchecked());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}

Comment on lines +137 to +138
constexpr auto members = std::meta::nonstatic_data_members_of(
^^S, std::meta::access_context::unchecked());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::vector<std::meta::info> をconstexpr変数で持つことはできません。

@faithandbrave
Copy link
Copy Markdown
Member Author

@yohhoy @Raclamusi
たくさん指摘いただいてありがとうございます。
まだ直すところ、書くところが大量にあってぜんぜん追いついてない状況です。
セルフチェックまでおわったらレビュー期間をとりますので、一旦置いておいていただければと思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants