- stacktrace[meta header]
- std[meta namespace]
- basic_stacktrace[meta class]
- function[meta id-type]
- cpp23[meta cpp]
size_type size() const noexcept; // (1) C++23
スタックトレースの履歴数を取得する。
保持しているスタックトレースの履歴の、要素数を返す。
#include <iostream>
#include <stacktrace>
void g() {
auto trace = std::stacktrace::current();
std::cout << trace.size() << std::endl;
std::cout << trace << std::endl;
}
void f() {
g();
}
int main() {
f();
}
- trace.size()[color ff0000]
- current()[link current.md]
7
0# g() at /app/example.cpp:5
1# f() at /app/example.cpp:11
2# main at /app/example.cpp:15
3# at :0
4# at :0
5# _start at :0
6#
#include <iostream>
#include <stacktrace>
void g() {
auto trace = std::stacktrace::current(1, 1);
std::cout << trace.size() << std::endl;
std::cout << trace << std::endl;
}
void f() {
g();
}
int main() {
f();
}
- trace.size()[color ff0000]
- current[link current.md]
1
0# f() at /app/example.cpp:11
- C++23
- Clang: ??
- GCC: 12 [mark verified]
- Visual C++: ??