std::array<T,N>::rbegin, std::array<T,N>::crbegin
Von de.cppreference.net
reverse_iterator rbegin() noexcept;
|
(1) | (seit C++11) (constexpr seit C++17) |
const_reverse_iterator rbegin() const noexcept;
|
(2) | (seit C++11) (constexpr seit C++17) |
const_reverse_iterator crbegin() const noexcept;
|
(3) | (seit C++11) (constexpr seit C++17) |
Gibt einen reverse_iterator auf das erste Element des umgekehrten array zurück. Es entspricht dem letzten Element des nicht umgekehrten array. Wenn das array leer ist, ist der zurückgegebene Iterator gleich rend().
Rückgabewert
Umgekehrter Iterator zum ersten Element.
Komplexität
Konstante.
Hinweise
Der zugrundeliegende Iterator des zurückgegebenen Reverse-Iterators ist der End-Iterator . Daher wird der zurückgegebene Iterator ungültig, wenn und falls der End-Iterator ungültig wird.
Beispiel
Diesen Code ausführen
#include <algorithm>
#include <iostream>
#include <string>
#include <string_view>
#include <array>
void print(const std::string_view s) { std::cout << s << ' '; }
int main()
{
const std::array<std::string_view, 8> data
{
"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"
};
std::array<std::string, 8> arr;
std::copy(data.cbegin(), data.cend(), arr.begin());
print("Print 'arr' in direct order using [cbegin, cend):\t");
std::for_each(arr.cbegin(), arr.cend(), print);
print("\n\nPrint 'arr' in reverse order using [crbegin, crend):\t");
std::for_each(arr.crbegin(), arr.crend(), print);
}
Ausgabe:
Print 'arr' in direct order using [cbegin, cend): ▁ ▂ ▃ ▄ ▅ ▆ ▇ █
Print 'arr' in reverse order using [crbegin, crend): █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
Siehe auch
|
gibt einen Reverse Iterator zum Ende zurück
(public member function) |
|
|
(C++14)
|
gibt einen Reverse Iterator zum Anfang eines Containers oder Arrays zurück
(function template) |