std::span::...:span::cend(3)
πΈ NAME πΈ
std::span::end,std::span::cend β std::span::end,std::span::cend
Hii bestie π welcome to the std::span::...:span::cend(3) page from the C++ Standard Libary (yes, βLibaryβ is literally how itβs printed, iykyk π). Todayβs main characters are end and cend, and they are lowkey iconic.
β¨ Synopsis β¨
constexpr iterator end() const noexcept; (1) (since C++20)
constexpr const_iterator cend() const noexcept; (2) (since C++23)
Okay so bestie, this returns an iterator to the element following the last element of the span.
That element is literally a placeholder β attempting to access it results in undefined behavior. π¨ Not a drill, do not dereference the placeholder. The original page also has a diagram filename, range-begin-end.svg, doing its little visual moment.
π Parameters π
(none)β none at all, periodt.
π¦ Return value π¦
Iterator to the element following the last element. Thatβs the whole vibe. Slay. β¨
π Complexity π
Constant. β‘
π₯ Example π₯
// Run this code
#include <iostream>
#include <span>
void print(std::span<const int> array)
{
std::cout << "array = ";
for (auto it = array.begin(); it != array.end(); ++it)
std::cout << *it << ' ';
std::cout << '\n';
}
void set_first_element(std::span<int> sp, int new_value)
{
if (!sp.empty())
{
std::cout << "old *begin = " << *sp.begin() << '\n';
*sp.begin() = new_value;
std::cout << "new *begin = " << *sp.begin() << '\n';
}
}
int main()
{
int array[]{1, 3, 4, 5};
print(array);
set_first_element(array, 2);
print(array);
}
Output:
array = 1 3 4 5
old *begin = 1
new *begin = 2
array = 2 3 4 5
π See also π
beginβ returns an iterator to the beginningcbeginβ (public member function) (C++23)endcendβ returns an iterator to the end of a container or array (C++11) (function template) (C++14)
Bye bestie π«Ά thatβs the whole page β page std::span::...:span::cend(3), source http://cppreference.com, version/date 2024.06.10. Mwah π
π¦ 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