最終更新日時(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();
}

出力例 (GCC)

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

出力例 (GCC)

1
   0#  f() at /app/example.cpp:11

バージョン

言語

  • C++23

処理系