Skip to content

Commit 7de1fde

Browse files
committed
access_context::scope : 動作検証したら出力がまちがっていたのでサンプル見直し
1 parent b094b24 commit 7de1fde

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

reference/meta/access_context/scope.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,39 @@ consteval info scope() const;
1717
## 戻り値
1818
このアクセスコンテキストが関連付けられているスコープのリフレクションを返す。
1919

20+
[`access_context::current()`](current.md)で取得したコンテキストの場合、`current()`を呼び出した時点で囲んでいる関数や名前空間などのスコープが返される。
21+
2022

2123
##
2224
```cpp example
2325
#include <meta>
2426
#include <print>
2527

2628
class C {
27-
int secret;
2829
public:
29-
int visible;
30-
3130
static void inspect() {
31+
// current()はinspect()関数内で呼ばれたので、スコープはinspect()関数
3232
constexpr auto ctx = std::meta::access_context::current();
33-
// C内部からcurrent()を呼んだので、スコープはC
34-
std::println("scope: {}", std::meta::display_string_of(ctx.scope()));
33+
std::println("inspect()のスコープ: {}",
34+
std::meta::display_string_of(ctx.scope()));
3535
}
3636
};
3737

38+
void free_function() {
39+
// current()はfree_function()内で呼ばれたので、スコープはfree_function()
40+
constexpr auto ctx = std::meta::access_context::current();
41+
std::println("free_function()のスコープ: {}",
42+
std::meta::display_string_of(ctx.scope()));
43+
}
44+
3845
int main() {
46+
// current()はmain()内で呼ばれたので、スコープはmain()
47+
constexpr auto ctx = std::meta::access_context::current();
48+
std::println("main()のスコープ: {}",
49+
std::meta::display_string_of(ctx.scope()));
50+
3951
C::inspect();
52+
free_function();
4053
}
4154
```
4255
* scope()[color ff0000]
@@ -45,7 +58,9 @@ int main() {
4558
4659
#### 出力例
4760
```
48-
scope: C
61+
main()のスコープ: int main()
62+
inspect()のスコープ: static void C::inspect()
63+
free_function()のスコープ: void free_function()
4964
```
5065
5166
## バージョン
@@ -54,7 +69,7 @@ scope: C
5469
5570
### 処理系
5671
- [Clang](/implementation.md#clang): ??
57-
- [GCC](/implementation.md#gcc): ??
72+
- [GCC](/implementation.md#gcc): 16 [mark verified]
5873
- [Visual C++](/implementation.md#visual_cpp): ??
5974
6075

0 commit comments

Comments
 (0)