std::span<T,Extent>::end
From cppreference.com
constexpr iterator end() const noexcept; |
||
Returns an iterator to the element following the last element of the span
.
This element acts as a placeholder; attempting to access it results in undefined behavior.
Parameters
(none)
Return value
Iterator to the element following the last element.
Complexity
Constant.
Example
Run this code
#include <span> #include <iostream> void print(std::span<const int> sp) { for(auto it = sp.begin(); it != sp.end(); ++it) { std::cout << *it << ' '; } std::cout << '\n'; } void transmogrify(std::span<int> sp) { if (!sp.empty()) { std::cout << *sp.begin() << '\n'; *sp.begin() = 2; } } int main() { int array[] { 1, 3, 4, 5 }; print(array); transmogrify(array); print(array); }
Output:
1 3 4 5 1 2 3 4 5
See also
(C++20) |
returns an iterator to the beginning (public member function) |
(C++11)(C++14) |
returns an iterator to the end of a container or array (function template) |