std::basic_string::rbegin,(3)

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

πŸŽ€ NAME πŸŽ€

okay bestie, this is the std::basic_string::rbegin,(3) page from the C++ Standard Libary manual. The NAME line is std::basic_string::rbegin, - std::basic_string::rbegin, β€” yes, it says it twice and the comma is included, she’s extra πŸ’….

✨ Synopsis ✨

Here’s the synopsis, keep the overload labels and annotations, they’re part of the lore 🫢:

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

So what it does: it returns a reverse iterator to the first character of the reversed string. That corresponds to the last character of the non-reversed string. reverse brainrot but make it useful ✨

There’s a diagram named range-rbegin-rend.svg hanging out with this page, btw.

🌸 Parameters 🌸

(none) β€” zero parameters, nada, no cap 🫢.

πŸ¦‹ Return value πŸ¦‹

Reverse iterator to the first character. That’s the whole return value, bestie.

πŸŽ€ Complexity πŸŽ€

Constant. That’s what it says, and we respect it.

πŸ’œ Notes πŸ’œ

libc++ backports crbegin() to C++98 mode. iykyk πŸ’œ.

πŸ”₯ Example πŸ”₯

The page says // Run this code, so here’s the example exactly:

// Run this code

#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>

int main()
{
    std::string s("Exemplar!");
    *s.rbegin() = 'y';
    std::cout << s << '\n'; // "Exemplary"

    std::string c;
    std::copy(s.crbegin(), s.crend(), std::back_inserter(c));
    std::cout << c << '\n'; // "yralpmexE"
}

🌈 Output: 🌈

Exemplary
yralpmexE

πŸ‘‘ See also πŸ‘‘

  • rend β€” returns a reverse iterator to the end
  • crend β€” (public member function) (C++11)
  • rbegin β€” returns a reverse iterator to the beginning
  • crbegin β€” (public member function of std::basic_string_view<CharT,Traits>)

source: http://cppreference.com, date: 2024.06.10, page: std::basic_string::rbegin,(3) β€” bye bestie, go reverse-iterate something cute πŸ’–

πŸ“¦ where this page comes from