Namespaces
Variants

std::basic_stacktrace<Allocator>:: begin, std::basic_stacktrace<Allocator>:: cbegin

From cppreference.net
const_iterator begin ( ) const noexcept ;
(1) (C++23以降)
const_iterator cbegin ( ) const noexcept ;
(2) (C++23以降)

basic_stacktrace の最初のエントリへのイテレータを返します。

basic_stacktrace が空の場合、返されるイテレータは end() と等しくなります。

range-begin-end.svg

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - C++関連の専門用語(Parameters, Return value, Complexity, Example, See also)は原文のまま保持しました - HTMLタグ、属性、クラス名、ID、リンク先は一切変更していません - 数値や書式設定は完全に保持されています

パラメータ

(なし)

戻り値

最初のエントリへのイテレータ。

計算量

定数。

#include <algorithm>
#include <iostream>
#include <stacktrace>
int main()
{
    auto trace       = std::stacktrace::current();
    auto empty_trace = std::stacktrace{};
    // スタックトレースを出力
    std::for_each(trace.begin(), trace.end(),
                  [](const auto& f) { std::cout << f << '\n'; });
    if (empty_trace.begin() == empty_trace.end())
        std::cout << "stacktrace 'empty_trace' is indeed empty.\n";
}

出力例:

0x0000000000402BA8 in ./prog.exe
__libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
0x0000000000402A29 in ./prog.exe
stacktrace 'empty_trace' is indeed empty.

関連項目

終端を指すイテレータを返す
(public member function)