std::stacktrace_entry(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::stacktrace_entry (a.k.a. the C++ Standard Library drama, cppreference edition)

okay bestie, so you know how the C++ Standard Libary manual lives at http://cppreference.com? yeah. this is that page. and today we're learning about the single most ✨iconic✨ little detective in the whole <stacktrace> header πŸ’–


🌸 NAME 🌸

std::stacktrace_entry β€” literally std::stacktrace_entry, that's it, that's the name, no cap πŸŽ€

It's Defined in header <stacktrace> and it showed up like:

class stacktrace_entry;         (since C++23)

(yeah she's a C++23 girlie, she wasn't at the function before that πŸ’…)


πŸ¦‹ Synopsis πŸ¦‹

okay so the stacktrace_entry class provides operations for querying information about an evaluation in a stacktrace. read that again. it's giving little index card for one moment in your call stack πŸŽ€

Each stacktrace_entry object is either empty, or it represents an evaluation in a stacktrace. no in-between, no "it's complicated", it's a binary vibe check ✨

Also, and this is the part where she ate: stacktrace_entry models std::regular and std::three_way_comparable<std::strong_ordering>. yes ma'am, three-way comparison, ordering, the whole package πŸ‘‘


🧚 Member types 🧚

  • native_handle_type (C++23) β€” implementation-defined native handle type. iykyk, it's whatever your implementation says it is, we don't make the rules 🫢

⭐ Member functions ⭐

  • constructor (C++23) β€” constructs a new stacktrace_entry. (public member function) ✨
  • destructor (C++23) β€” destroys the stacktrace_entry. (public member function) πŸ’€
  • operator= (C++23) β€” assigns the contents of one stacktrace_entry to another. (public member function) πŸ’–

πŸ‘‘ Observers πŸ‘‘

  • native_handle β€” gets the implementation-defined native handle of the stacktrace_entry. (C++23) (public member function) πŸ¦‹
  • operator bool β€” checks whether the stacktrace_entry is empty. (C++23) (public member function) β€” this is your "is she real or is she nothing" check, lowkey essential 🌸

πŸ” Query

  • description β€” gets the description of the evaluation represented by the stacktrace_entry. (C++23) (public member function) πŸŽ€
  • source_file β€” gets the name of the source file that lexically contains the expression or statement whose evaluation is represented by the stacktrace_entry. (C++23) (public member function) πŸ“βœ¨
  • source_line β€” gets the line number that lexically relates the evaluation represented by the stacktrace_entry. (C++23) (public member function) πŸ”’πŸ’œ

(and yes "lexically" is doing a lot of heavy lifting in both of those, don't come for her, it's the correct word, leave her alone 😭)


🌈 Non-member functions 🌈

  • operator==, operator<=> β€” compares two stacktrace_entry values. (function) (C++23) β€” comparing your little stack crumbs, love that for us ⭐
  • to_string β€” returns a string with a description of the stacktrace_entry. (C++23) (function) β€” string-ification, slay πŸ’…
  • operator<< β€” performs stream output of stacktrace_entry. (C++23) (function template) β€” now she can go straight into your std::cout like the main character she is πŸ‘‘πŸ”₯

πŸ“ Helper classes πŸ“

  • std::hash<std::stacktrace_entry> β€” hash support for std::stacktrace_entry. (C++23) (class template specialization) 🧚
  • std::formatter<std::stacktrace_entry> β€” formatting support for stacktrace_entry. (C++23) (class template specialization) ✨

like, hashable AND formattable?? she's booked and busy fr fr πŸ’–


πŸ“ Notes πŸ“

boost::stacktrace::frame (available in Boost.Stacktrace) can be used instead when std::stacktrace_entry is not available. so if your compiler is being a hater and you don't have the C++23 goodness yet, Boost has you, bestie 🫢

Also here's the feature-test macro, so you can vibe-check your toolchain:

  • __cpp_lib_stacktrace β€” value 202011L β€” Std C++23 β€” feature: Stacktrace library 🌟

(go look it up with __cpp_lib_stacktrace before you come crying to me that it doesn't compile, i'm literally begging πŸ™ˆ)


πŸ’€ Example πŸ’€

This section is incomplete.

Reason: no example 😭

yeah. we know. it's giving "the homework was due and nobody did it". tragic. but honestly? no example is still an example of something, periodt πŸŽ€


🫢 See also 🫢

  • basic_stacktrace (C++23) β€” approximate representation of an invocation sequence consists of stacktrace entries. (class template) πŸ¦‹ β€” the big picture, the whole group chat if you will
  • source_location (C++20) β€” a class representing information about the source code, such as file names, line numbers, and function names. (class) 🌸 β€” her older cousin who's been doing this since C++20 and never lets anyone forget it

πŸŽ€ Category πŸŽ€

  • Todo no example

(yeah, the category literally just says todo. love that journey for us πŸ’€βœ¨)


okay that's the whole page bestie, go forth and stacktrace responsibly πŸ’– remember: every flag, every member function, every "lexically", all of it stayed exactly where it was β€” i just made it cute. no cap, no invented behavior, just vibes and accurate documentation 🌈

β€” signed off from <stacktrace>, brought to you by http://cppreference.com, version 2024.06.10 β€” πŸŽ€πŸ’œπŸ¦‹

πŸ“¦ where this page comes from