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

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

πŸ¦‹ std::basic_string_view::rend / std::basic_string_view::crend πŸ¦‹

okay so bestie, welcome to the C++ Standard Libary manual-page energy for std::basic_string_view::rend and std::basic_string_view::crend β€” the reversed-end duo. Yes, that manual name is exact, typo and all; we don’t edit the lore πŸ’….

🌸 NAME 🌸

std::basic_string_view::rend,std::basic_string_view::crend β€” std::basic_string_view::rend,std::basic_string_view::crend

That’s the whole name block. We’re talking about the rend / crend pair on std::basic_string_view, and they are literally the main characters here. ✨

✨ Synopsis ✨

constexpr const_reverse_iterator rend() const noexcept;
constexpr const_reverse_iterator crend() const noexcept;

Both are (since C++17). 🫢

Returns a reverse iterator to the character following the last character of the reversed view. It corresponds to the character preceding the first character of the non-reversed view. This character acts as a placeholder, and attempting to access it results in undefined behavior. 😭

🚨 placeholder character alert: do not dereference it. Accessing it = undefined behavior. No cap.

There’s a diagram referenced right here too: range-rbegin-rend.svg πŸŽ€.

πŸŽ€ Parameters πŸŽ€

(none) β€” she takes nothing, bestie. Literally no parameters. 🫢

πŸ’– Return value πŸ’–

const_reverse_iterator to the character following the last character. That’s the flex. ✨

πŸ”₯ Complexity πŸ”₯

Constant. ⚑

🌈 Example 🌈

// 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(), str_view.rend(), out_it);
    *out_it = '\n';

    std::copy(str_view.crbegin(), str_view.crend(), out_it);
    *out_it = '\n';
}

Output:

fedcba
fedcba

πŸ‘‘ See also πŸ‘‘

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

mwah πŸ’‹ that’s the page, bestie. source: http://cppreference.com, version/date: 2024.06.10, page title: std::basic_...view::crend(3). byeee 🫢✨

πŸ“¦ where this page comes from