std::span<T,Extent>:: rend, std::span<T,Extent>:: crend
From cppreference.net
|
constexpr
reverse_iterator rend
(
)
const
noexcept
;
|
(1) | (C++20以降) |
|
constexpr
const_reverse_iterator crend
(
)
const
noexcept
;
|
(2) | (C++23以降) |
反転された * this の最後の要素の次を指す逆方向イテレータを返します。これは、反転されていない * this の最初の要素の前の要素に対応します。
この返されたイテレータはセンチネルとしてのみ機能します。これが デリファレンス可能 であることは保証されません。
目次 |
戻り値
最後の要素の次の要素への逆イテレータ。
計算量
定数。
例
このコードを実行
#include <algorithm> #include <iostream> #include <span> #include <string_view> void ascending(const std::span<const std::string_view> data, const std::string_view term) { std::for_each(data.begin(), data.end(), [](const std::string_view x) { std::cout << x << ' '; }); std::cout << term; } void descending(const std::span<const std::string_view> data, const std::string_view term) { std::for_each(data.rbegin(), data.rend(), [](const std::string_view x) { std::cout << x << ' '; }); std::cout << term; } int main() { constexpr std::string_view bars[]{"▁","▂","▃","▄","▅","▆","▇","█"}; ascending(bars, " "); descending(bars, "\n"); }
出力:
▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
関連項目
|
(C++23)
|
先頭を指す逆方向イテレータを返す
(public member function) |
|
(C++14)
|
コンテナまたは配列の逆方向終端イテレータを返す
(function template) |