std::span::...an::crbegin(3)

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

πŸ’– NAME πŸ’–

Okay bestie, welcome to the std::span::...an::crbegin(3) page from the C++ Standard Libary manual. This one is all about std::span::rbegin and std::span::crbegin β€” and yes, the NAME is literally std::span::rbegin,std::span::crbegin and then std::span::rbegin,std::span::crbegin again. πŸ’…βœ¨

🌸 Synopsis 🌸

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

Returns a reverse iterator to the first element of the reversed span. It corresponds to the last element of the non-reversed span. If the span is empty, the returned iterator is equal to rend(). 🫢

range-rbegin-rend.svg

πŸŽ€ Parameters πŸŽ€

(none) β€” literally no parameters, bestie. Not a single one. πŸ™ˆ

πŸ’… Return value πŸ’…

Reverse iterator to the first element. Periodt. ✨

⭐ Complexity ⭐

Constant. Easy peasy.

πŸ¦‹ Notes πŸ¦‹

The underlying iterator of the returned reverse iterator is the end iterator. Hence the returned iterator is invalidated if and when the end iterator is invalidated. This is the important part, bestie: invalidation is real. 😭

πŸ“ Example πŸ“

Run this code, bestie:

// Run this code

#include <algorithm>
#include <iostream>
#include <iterator>
#include <span>

int main()
{
    constexpr std::span<const char>
code{"@droNE_T0P_w$s@s#_SECRET_a,p^42!"};

    auto hack = [](const unsigned O) { return O - 0141 < 120; };

    std::copy_if(code.rbegin(), code.rend(),
        std::ostream_iterator<const char>(std::cout), hack);

    std::cout << '\n';
}

πŸ”₯ Output: πŸ”₯

password

🌈 See also 🌈

  • rend β€” returns a reverse iterator to the end
  • crend β€” (public member function) (C++23)
  • rbegin β€” returns a reverse iterator to the beginning of a container or array
  • crbegin β€” (function template) (C++14)

xoxo, bestie πŸ’– β€” source/version: http://cppreference.com Β· date: 2024.06.10 πŸŽ€

πŸ“¦ where this page comes from