std::span<T,Extent>:: begin, std::span<T,Extent>:: cbegin
From cppreference.net
|
constexpr
iterator begin
(
)
const
noexcept
;
|
(1) | (seit C++20) |
|
constexpr
const_iterator cbegin
(
)
const
noexcept
;
|
(2) | (seit C++23) |
Gibt einen Iterator auf das erste Element von * this zurück.
Wenn * this leer ist, wird der zurückgegebene Iterator gleich end() sein.
Inhaltsverzeichnis |
Rückgabewert
Iterator zum ersten Element.
Komplexität
Konstante.
Beispiel
Diesen Code ausführen
#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); }
Ausgabe:
array = 1 3 4 5 old *begin = 1 new *begin = 2 array = 2 3 4 5
Siehe auch
|
(C++23)
|
gibt einen Iterator zum Ende zurück
(öffentliche Elementfunktion) |
|
(C++11)
(C++14)
|
gibt einen Iterator zum Anfang eines Containers oder Arrays zurück
(Funktionstemplate) |