最終更新日時(UTC):
が更新

履歴 編集

function
<stacktrace>

std::basic_stacktrace::size(C++23)

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

出力例

3
 0# g() at main.cpp:5
 1# f() at main.cpp:11
 2# main at main.cpp:15

指定範囲のスタックトレースの要素数

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

出力例

1
 0# f() at main.cpp:11

バージョン

言語

  • C++23

処理系