std::basic_...ce::crbegin(3)

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

πŸ¦‹ std::basic_stacktrace::rbegin / std::basic_stacktrace::crbegin πŸ¦‹

Okay bestie, this page is from the C++ Standard Libary manual (that's the manual name as it appears, spelling included πŸ’…), and the page title is std::basic_...ce::crbegin(3). We're talking about rbegin and crbegin on std::basic_stacktrace, and yes, both are since C++23. Periodt.

πŸŽ€ NAME πŸŽ€

std::basic_stacktrace::rbegin,std::basic_stacktrace::crbegin β€” and then, literally, the exact same name again: std::basic_stacktrace::rbegin,std::basic_stacktrace::crbegin. No extra lore, that's the whole NAME section.

✨ Synopsis ✨

Here's the signature situation, bestie:

const_reverse_iterator rbegin()  const noexcept; (1) (since C++23)
const_reverse_iterator crbegin() const noexcept; (2) (since C++23)

So both of these return a reverse iterator to the first entry of the reversed basic_stacktrace. It corresponds to the last entry of the original basic_stacktrace. And if the basic_stacktrace is empty, the returned iterator is equal to rend().

The original page also drops a diagram named range-rbegin-rend.svg β€” yes, that's the literal filename β€” to show the rbegin/rend range vibe. 🫢

🌸 Parameters 🌸

(none) β€” not a single argument, not one optional extra. It's giving no-arg icon behavior. πŸ’…

πŸ’– Return value πŸ’–

Reverse iterator to the first entry. That's the whole return value, and it ate. ✨

πŸŽ€ Complexity πŸŽ€

Constant. No cap, constant. 🧚

πŸ”₯ Example πŸ”₯

The page says // Run this code, so here's the code, copied exactly:

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

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

    // Print stacktrace.
    std::for_each(trace.rbegin(), trace.rend(),
                  [](const auto& f) { std::cout << f << '\n'; });

    if (empty_trace.rbegin() == empty_trace.rend())
        std::cout << "stacktrace 'empty_trace' is indeed empty.\n";
}

Possible output:

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

🌈 See also 🌈

  • rend β€” returns a reverse iterator to the end
  • crend β€” (public member function)

And that's the whole page, bestie! Source/version/date: http://cppreference.com, 2024.06.10, page std::basic_...ce::crbegin(3). Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from