std::span<T,Extent>::rend, std::span<T,Extent>::crend
From cppreference.com
| constexpr reverse_iterator rend() const noexcept; |
(1) | (C++20以降) |
| constexpr const_reverse_iterator crend() const noexcept; |
(2) | (C++23から) |
逆順のspanの最後の要素の次の要素を指す逆イテレータを返します。これは、逆順でないspanの最初の要素の前の要素に対応します。この要素はプレースホルダとして機能し、アクセスしようとすると未定義の動作が発生します。
目次 |
[編集] 戻り値
最後の要素の次の要素へのリバースイテレータ。
[編集] 複雑性
定数。
[編集] 例
このコードを実行
#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 メンバ関数) |
| (C++14) |
コンテナまたは配列の逆順の終端イテレータを返す (function template) |