std::span<T,Extent>:: end, std::span<T,Extent>:: cend
From cppreference.net
|
constexpr
iterator end
(
)
const
noexcept
;
|
(1) | (depuis C++20) |
|
constexpr
const_iterator cend
(
)
const
noexcept
;
|
(2) | (depuis C++23) |
Retourne un itérateur après le dernier élément de * this .
Cet itérateur retourné agit uniquement comme un sentinelle. Il n'est pas garanti qu'il soit déréférençable .
Table des matières |
Valeur de retour
Itérateur après le dernier élément.
Complexité
Constante.
Exemple
Exécuter ce 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); }
Sortie :
array = 1 3 4 5 old *begin = 1 new *begin = 2 array = 2 3 4 5
Voir aussi
|
(C++23)
|
retourne un itérateur vers le début
(fonction membre publique) |
|
(C++11)
(C++14)
|
retourne un itérateur vers la fin d'un conteneur ou d'un tableau
(fonction template) |