C++ Library - <stacktrace>



The <stacktrace> header in C++20, introduces a way to work with the stack traces. It provides a snapshot of the function call history at a particular point in the program execution, which is helpful for debugging and error handling.

Before C++20, obtaining stack traces requires a platform-specific libraries or third-party tools making it a messed task. However, with the introduction of <stacktrace> it regulates the process, enabling the cross-platform compatibility and reducing the dependence on the external libraries.

Including <stacktrace> Header

To include the <stacktrace> header in your C++ program, you can use the following syntax.

#include <stacktrace>

Functions of <stacktrace> Header

Below is list of all functions from <stacktrace> header.

Sr.NoFunctions & Description
1operator=

It assigns to the basic_stacktrace.

2current

It obtains the current stacktrace or its given part.

3get_allocator

It returns the associated allocator.

4begin

It returns an iterator to the beginning.

5cbegin

It returns an constant iterator to the beginning.

6end

It returns an iterator to the end.

7cend

It returns an constant iterator to the end.

8rbegin

It returns a reverse iterator to the beginning.

9crbegin

It returns a constant reverse iterator to the beginning.

10rend

It returns a reverse iterator to the end.

11crend

It returns a constant reverse iterator to the end.

12empty

It checks whether the stacktrace is empty.

13size

It returns the number of stacktrace entries.

14max_size

It returns the maximum possible number of stacktrace entries.

15operator[]

It access specified stacktrace entry.

16at

It access specified stacktrace entry with bounds checking.

17swap

It swaps the contents.

Non-member functions

Sr.NoFunctions & Description
1operator==

It compares the sizes and the contents of two basic_stacktrace values.

2to_string

It returns a string with a description of the stacktrace.

3operator<<

It performs stream output of stracktrace.