std::basic_...iew::rbegin,(3)
π NAME
okay so bestie, this is std::basic_string_view::rbegin β yes the page title is literally std::basic_...iew::rbegin,(3) because the C++ Standard Library manpage is out here doing the absolute most with abbreviations π β and it's about getting a reverse iterator pointed at the first character of the reversed view β¨
(also yes, this lives in the C++ Standard Library, in case the parenthetical vibe check wasn't clear π«Ά)
β¨ Synopsis
Two overloads, both of them besties since C++17:
constexpr const_reverse_iterator rbegin() const noexcept; (since C++17)
constexpr const_reverse_iterator crbegin() const noexcept; (since C++17)
So what are these actually doing? They return a reverse iterator to the first character of the reversed view π₯ And that corresponds to the last character of the non-reversed view. Not me explaining it in two directions but like β that's genuinely what it is π
There's also a lil diagram on the page, range-rbegin-rend.svg, if you're a visual learner π
πΈ Parameters
(none)
Literally zero arguments. She takes nothing. Iconic, low-effort, no notes π
π¦ Return value
A const_reverse_iterator to the first character. That's it, that's the whole deal π
β Complexity
Constant. Constannnttt. O(1) behavior, main character energy, in and out, no drama π
πΊ Example
Run this code, fr fr:
// Run this code
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string_view>
int main()
{
std::ostream_iterator<char> out_it(std::cout);
std::string_view str_view("abcdef");
std::copy(str_view.rbegin(), std::next(str_view.rbegin(), 3), out_it);
*out_it = '\n';
std::copy(str_view.crbegin(), std::next(str_view.crbegin(), 3), out_it);
*out_it = '\n';
}
π Output
fed
fed
fed twice β rbegin() ate and left no crumbs, then crbegin() came through and did the exact same thing π (the string is "abcdef", so reversed you're reading it backwards from the f, hence fed β iykyk π)
π§ See also
rendβ returns a reverse iterator to the endcrendβ (public member function)rbeginβ returns a reverse iterator to the beginningcrbeginβ (public member function ofstd::basic_string<CharT,Traits,Allocator>) (C++11)
like yes, they're the sibling functions, and yes one of them is from std::basic_string not the view, that's just how the page lists it, don't come for me π
ngl the docs are honest about nothing here being dangerous β no UB, no deprecation, no gotchas, everything'sconstexprandnoexceptand safe. Slay. π
and that's the page!! brought to you by cppreference.com π version/date stamp 2024.06.10, and the original footer named it std::basic_...iew::rbegin,(3) β so go forth, reverse-iterate responsibly, and remember: last character of the normal view = first character of the reversed view, periodt πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms