std::basic_...trace::cend(3)

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

πŸ’… NAME πŸ’…

okay bestie, welcome to the std::basic_...trace::cend(3) page from the C++ Standard Libary manual (yes it says β€œLibary” in the header, iconic πŸ’€). This is the tea on std::basic_stacktrace::end and std::basic_stacktrace::cend:

std::basic_stacktrace::end,std::basic_stacktrace::cend β€” std::basic_stacktrace::end,std::basic_stacktrace::cend

periodt, that’s the name, no cap πŸ’–


✨ Synopsis ✨

here’s the exact vibe, bestie:

const_iterator end()  const noexcept; (1) (since C++23)
const_iterator cend() const noexcept; (2) (since C++23)

so both of these return an iterator pointing past the last entry of the basic_stacktrace. they’re your β€œone past the end” besties 🫢

and like… this iterator is literally just a placeholder. if you try to dereference it, that’s undefined behavior 😭 do not do it, bestie, that’s not the cute kind of surprise.

there’s also a lil diagram situation mentioned as range-begin-end.svg πŸŽ€ iykyk.


πŸŽ€ Parameters πŸŽ€

(none) β€” literally none, zero, nada 🫢


πŸ’– Return value πŸ’–

The end iterator. that’s it, that’s the whole answer πŸ’…


πŸ¦‹ Complexity πŸ¦‹

Constant. like, it’s not doing extra work, it’s just constant, periodt ✨


πŸ”₯ Example πŸ”₯

the manpage says // Run this code, so bestie, here’s the code, exactly as written:

#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:

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.

slay, it prints the stacktrace and then confirms empty_trace is indeed empty 🌸


πŸ‘‘ See also πŸ‘‘

  • begin β€” returns an iterator to the beginning
  • cbegin β€” (public member function)

go check those out too, bestie, they’re giving matching set energy πŸ’œ


okay that’s the whole page! source: http://cppreference.com, dated 2024.06.10, and the page is std::basic_...trace::cend(3). bye bestie, go dereference responsibly (which is to say: don’t dereference the end iterator) πŸ˜­πŸ’–βœ¨

πŸ“¦ where this page comes from