std::array<T,N>::rend, std::array<T,N>::crend
ja.cppreference.net より
reverse_iterator rend() noexcept;
|
(1) | (C++11 から) (C++17 から constexpr) |
const_reverse_iterator rend() const noexcept;
|
(2) | (C++11 から) (C++17 から constexpr) |
const_reverse_iterator crend() const noexcept;
|
(3) | (C++11 から) (C++17 から constexpr) |
逆順にした array の最後の要素の次の要素を指す逆イテレータを返します。これは、逆順にしていない array の最初の要素の前の要素に対応します。この要素はプレースホルダとして機能し、アクセスを試みると未定義動作になります。
戻り値
最後の要素の次の要素への逆イテレータ。
計算量
定数。
例
このコードを実行
#include <algorithm> #include <iostream> #include <array> int main() { std::array<int, 11> a{1, 11, 11, 35, 0, 12, 79, 76, 76, 69, 40}; // const_reverse_iteratorを使用してコンテナの要素を逆順に出力 std::for_each(a.crbegin(), a.crend(), [](int e){ std::cout << e << ' '; }); std::cout << '\n'; // 非const reverse_iteratorを使用してコンテナの各要素を変更 std::for_each(a.rbegin(), a.rend(), [](int& e){ e += 32; }); // const_reverse_iteratorを使用して文字として要素を逆順に出力 std::for_each(a.crbegin(), a.crend(), [](char e){ std::cout << e; }); std::cout << '\n'; }
出力:
40 69 76 76 79 12 0 35 11 11 1 Hello, C++!
関連項目
|
先頭を指す逆方向イテレータを返す
(公開メンバ関数) |
|
|
(C++14)
|
コンテナまたは配列の逆方向終端イテレータを返す
(関数テンプレート) |