Skip to content

Commit 53ab5e9

Browse files
committed
stacktrace_entry : native_handleとoperator boolを追加
1 parent b22d84d commit 53ab5e9

File tree

3 files changed

+128
-2
lines changed

3 files changed

+128
-2
lines changed

reference/stacktrace/stacktrace_entry.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ namespace std {
2828
2929
| 名前 | 説明 | 対応バージョン |
3030
|------|------|----------------|
31-
| [`native_handle`](stacktrace_entry/native_handle.md.nolink) | ハンドルを取得する | C++23 |
32-
| [`operator bool`](stacktrace_entry/op_bool.md.nolink) | 空でないかを判定する | C++23 |
31+
| [`native_handle`](stacktrace_entry/native_handle.md) | ハンドルを取得する | C++23 |
32+
| [`operator bool`](stacktrace_entry/op_bool.md) | 空でないかを判定する | C++23 |
3333
3434
3535
### 照会
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# native_handle
2+
* stacktrace[meta header]
3+
* std[meta namespace]
4+
* stacktrace_entry[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
constexpr native_handle_type native_handle() const noexcept; // (1) C++23
10+
```
11+
12+
## 概要
13+
ハンドルを取得する。
14+
15+
16+
## 戻り値
17+
実装定義のハンドルを返す。
18+
19+
20+
## 備考
21+
- 変更されていない`stacktrace_entry`オブジェクトに対してこの関数を連続して呼び出すと、同じ値が返される
22+
- GCCでは、libstdc++の内部ライブラリ向けのポインタを整数値型[`std::uintptr_t`](/reference/cstdint/uintptr_t.md)の変換した型になっている
23+
- `__glibcxx_backtrace_pcinfo()`など、内部ライブラリ用であるため、ユーザーがハンドルを便利に使えるようにはなっていない
24+
- MSVCでも内部ライブラリ向けの`void*`型ポインタになっている
25+
- こちらも内部ライブラリ用であるため、ユーザーがハンドルを便利に使えるようにはなっていない
26+
27+
28+
##
29+
```cpp example
30+
#include <iostream>
31+
#include <stacktrace>
32+
33+
void g() {
34+
std::stacktrace st = std::stacktrace::current();
35+
std::stacktrace_entry entry = st[0];
36+
37+
std::cout << entry.native_handle() << std::endl;
38+
}
39+
40+
void f() {
41+
g();
42+
}
43+
44+
int main() {
45+
f();
46+
}
47+
```
48+
* entry.native_handle()[color ff0000]
49+
* std::stacktrace[link /reference/stacktrace/basic_stacktrace.md]
50+
* current[link /reference/stacktrace/basic_stacktrace/current.md]
51+
52+
### 出力例 (GCC)
53+
```
54+
4199037
55+
```
56+
57+
58+
## バージョン
59+
### 言語
60+
- C++23
61+
62+
### 処理系
63+
- [Clang](/implementation.md#clang): ??
64+
- [GCC](/implementation.md#gcc): 12
65+
- [Visual C++](/implementation.md#visual_cpp): ??
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# operator bool
2+
* stacktrace[meta header]
3+
* std[meta namespace]
4+
* stacktrace_entry[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
constexpr explicit operator bool() const noexcept; // (1) C++23
10+
```
11+
12+
## 概要
13+
`stacktrace_entry`が空でないかを判定する。
14+
15+
16+
## 戻り値
17+
`*this`が空である場合のみ`false`を返す。
18+
19+
20+
##
21+
```cpp example
22+
#include <iostream>
23+
#include <stacktrace>
24+
25+
void g() {
26+
std::stacktrace st = std::stacktrace::current();
27+
std::stacktrace_entry entry = st[0];
28+
29+
if (entry) {
30+
std::cout << "not empty" << std::endl;
31+
}
32+
else {
33+
std::cout << "empty" << std::endl;
34+
}
35+
}
36+
37+
void f() {
38+
g();
39+
}
40+
41+
int main() {
42+
f();
43+
}
44+
```
45+
* std::stacktrace[link /reference/stacktrace/basic_stacktrace.md]
46+
* current[link /reference/stacktrace/basic_stacktrace/current.md]
47+
48+
### 出力
49+
```
50+
not empty
51+
```
52+
53+
54+
## バージョン
55+
### 言語
56+
- C++23
57+
58+
### 処理系
59+
- [Clang](/implementation.md#clang): ??
60+
- [GCC](/implementation.md#gcc): 12
61+
- [Visual C++](/implementation.md#visual_cpp): ??

0 commit comments

Comments
 (0)