std::basic_..._view::cend(3)
π std::basic_..._view::cend(3) π
Okay so welcome to the std::basic_..._view::cend(3) page from the C++ Standard Libary manual, bestie. This one is about std::basic_string_view::end and std::basic_string_view::cend, and it is lowkey iconic because it's all about that one-past-the-last-character energy. β¨
π NAME π
std::basic_string_view::end,std::basic_string_view::cend β std::basic_string_view::end,std::basic_string_view::cend.
Yep, the NAME line is literally doing an echo thing. Not me pointing it out, but periodt. π
β¨ Synopsis β¨
constexpr const_iterator end() const noexcept; (since C++17)
constexpr const_iterator cend() const noexcept; (since C++17)
Both of these return an iterator to the character following the last character of the view. That character is a placeholder, bestie, and attempting to access it results in undefined behavior. π«Ά
There's also a range-begin-end.svg diagram referenced here in the original page, so respect the diagram vibes. π¦
π Parameters π
(none) β zero parameters, no arguments, not a single little input. It's giving "no thoughts, just iterator" energy. πΈ
π¦ Return value π¦
A const_iterator to the character following the last character. Literally that one-past-the-end spot. π₯
πΈ Complexity πΈ
Constant. That's it, bestie β constant. β
π Example π
// Run this code
#include <iostream>
#include <iterator>
#include <string_view>
int main()
{
constexpr std::string_view str_view("abcd");
constexpr auto end = str_view.end();
constexpr auto cend = str_view.cend();
static_assert
(
*std::prev(end) == 'd' && 'd' == *std::prev(cend) and end ==
cend
);
}
π See also π
beginβ returns an iterator to the beginning π±cbeginβ (public member function) β¨endβ returns an iterator to the end π₯cendβ (public member function ofstd::basic_string<CharT,Traits,Allocator>)(C++11)π
Bestie, do not dereference that placeholder character. That's undefined behavior, no cap. Do not touch it. π
Source/version/date check: http://cppreference.com, 2024.06.10, footer title std::basic_..._view::cend(3). That's the whole tea β bye and slay your iterators! π
β¨
π¦ 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