std::basic_...race::crend(3)

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

okay so this is from the C++ Standard Libary manual (their spelling, not mine, bestie 😭) for std::basic_...race::crend(3). Buckle up, we're doing reverse iterators.

✨ NAME ✨

std::basic_stacktrace::rend, std::basic_stacktrace::crend β€” yep, it's giving std::basic_stacktrace::rend, std::basic_stacktrace::crend, the reverse-end duo. πŸ’…

🌸 Synopsis 🌸

Two overloads, both const noexcept, both since C++23:

const_reverse_iterator rend()  const noexcept; (1) (since C++23)
const_reverse_iterator crend() const noexcept; (2) (since C++23)

So what's the vibe? These return a reverse iterator pointing past the last entry of the reversed basic_stacktrace. It corresponds to the iterator preceding the first entry of the original basic_stacktrace. This iterator acts as a placeholder β€” attempting to dereference it results in undefined behavior. 🫠

There's also this little diagram moment: range-rbegin-rend.svg πŸ“Ž

⚠️ bestie, do not dereference this placeholder iterator. That's undefined behavior. It's not a fun surprise, it's a no-cap warning. πŸ’€

πŸŽ€ Parameters πŸŽ€

(none) β€” literally zero parameters, not a single one. 🫢

πŸ¦‹ Return value πŸ¦‹

The end iterator of the reversed basic_stacktrace.

⭐ Complexity ⭐

Constant.

🌈 Example 🌈

// Run this code

#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 πŸ‘‘

  • rbegin β€” returns a reverse iterator to the beginning
  • crbegin β€” (public member function)

catch you later, bestie πŸ’– β€” source/version: http://cppreference.com; date: 2024.06.10; page: std::basic_...race::crend(3).

πŸ“¦ where this page comes from