std::span<T,Extent>::end, std::span<T,Extent>::cend
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Containers library
(C++17)
(C++11)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++23)
(C++23)
(C++20)
(C++23)
Tables
std::span
(C++26)
(C++23)
span::endspan::cend
(C++23)
(C++23)
(C++23)
constexpr iterator end() const noexcept;
(1)
(since C++20)
constexpr const_iterator cend() const noexcept;
(2)
(since C++23)
Returns an iterator past the last element of *this.
This returned iterator only acts as a sentinel. It is not guaranteed to be dereferenceable.
Contents
[edit] Return value
Iterator past the last element.
[edit] Complexity
Constant.
[edit] 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