std::basic_...ace::cbegin(3)

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

πŸ’– NAME πŸ’–

okay so bestie, this is the std::basic_...ace::cbegin(3) page from the C++ Standard Libary manual, and it's here to explain the whole begin/cbegin situation for std::basic_stacktrace. no cap, it's giving β€œpoint me at the first entry” energy.

  • std::basic_stacktrace::begin,std::basic_stacktrace::cbegin β€” std::basic_stacktrace::begin,std::basic_stacktrace::cbegin. yes, the NAME line literally says it twice. iconic, honestly.

✨ Synopsis ✨

here's the exact vibe, bestie:

const_iterator begin()  const noexcept; (1) (since C++23)
const_iterator cbegin() const noexcept; (2) (since C++23)

so both of these return an iterator to the first entry of the basic_stacktrace. if the basic_stacktrace is empty, the returned iterator is equal to end(). that's the whole plot twist 🫢

also there is a lil diagram moment: range-begin-end.svg πŸ’…


🌸 Parameters 🌸

(none) β€” literally no parameters, not a single one. clean. simple. slay.


πŸŽ€ Return value πŸŽ€

Iterator to the first entry. periodt πŸ’–


πŸ¦‹ Complexity πŸ¦‹

Constant. so it's not doing a whole side quest, bestie ⭐


πŸ”₯ Example πŸ”₯

the page says // Run this code, and then gives you this absolute queen of a snippet:

#include <algorithm>
#include <iostream>
#include <stacktrace>

int main()
{
    auto trace       = std::stacktrace::current();
    auto empty_trace = std::stacktrace{};

    // Print 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";
}

πŸ“ Possible output πŸ“

like, maybe it prints this:

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.

🌈 See also 🌈

  • end β€” returns an iterator to the end
  • cend β€” (public member function)

made with love from http://cppreference.com on 2024.06.10 πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from