std::operat...stacktrace)(3)

๐Ÿ“ฆ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

๐ŸŒธ NAME ๐ŸŒธ

okay so bestie, welcome to std::operator<<(std::basic_stacktrace) โ€” page title std::operat...stacktrace)(3), from the C++ Standard Libary manual (yes, that's the exact spelling in the header, don't come for me ๐Ÿ™ˆ). The NAME line is literally std::operator<<(std::basic_stacktrace) - and then std::operator<<(std::basic_stacktrace) again, so likeโ€ฆ it's the same function, we get it, she's iconic ๐Ÿ’….

โœจ Synopsis โœจ

Defined in header <stacktrace> ๐Ÿฆ‹

template< class Allocator >
std::ostream& operator<<( std::ostream& os, const
std::basic_stacktrace<Allocator>& st );

(since C++23) โ€” yes bestie, C++23 and onward, no cap.

It inserts the description of st into the output stream os. Equivalent to return os << std::to_string(st);. That's the whole assignment, and she ate ๐Ÿ”ฅ.

๐ŸŽ€ Parameters ๐ŸŽ€

  • os โ€” an output stream
  • st โ€” a basic_stacktrace whose description is to be inserted

๐Ÿ’– Return value ๐Ÿ’–

It returns os. Periodt. ๐Ÿซถ

โš ๏ธ Exceptions โš ๏ธ

May throw implementation-defined exceptions. So like, don't assume it's a no-throw girlie, okay? ๐Ÿ˜ญ

๐ŸŒˆ Example ๐ŸŒˆ

Obsessed with this little demo โ€” it's giving main character stacktrace energy:

// Run this code

#include <stacktrace>
#include <iostream>

int main()
{
    std::cout << "The stacktrace obtained in the main function:\n";
    std::cout << std::stacktrace::current() << '\n';
    []{
        std::cout << "The stacktrace obtained in a nested lambda:\n";
        std::cout << std::stacktrace::current() << '\n';
    }();
}

๐Ÿ”ฎ Possible output ๐Ÿ”ฎ

The stacktrace obtained in the main function:
 0# 0x0000000000402E7B in ./prog.exe
 1# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
 2# 0x0000000000402CD9 in ./prog.exe

The stacktrace obtained in a nested lambda:
 0# 0x0000000000402DDA in ./prog.exe
 1# 0x0000000000402EB2 in ./prog.exe
 2# __libc_start_main in /lib/x86_64-linux-gnu/libc.so.6
 3# 0x0000000000402CD9 in ./prog.exe

๐Ÿ‘‘ See also ๐Ÿ‘‘

  • operator<< performs stream output of stacktrace_entry โ€” (C++23) (function template)

Source/version/date sign-off: this page comes from http://cppreference.com, dated 2024.06.10, and the footer title is std::operat...stacktrace)(3) โ€” k bye bestie, go print a stacktrace and slay ๐Ÿ’…โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from