Namespaces
Variants

std::array<T,N>:: rend, std::array<T,N>:: crend

From 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)

反転された * this の最後の要素の次を指す逆方向イテレータを返します。これは非反転の * this の最初の要素の前の要素に対応します。

この返されたイテレータはセンチネルとしてのみ機能します。これが dereferenceable であることは保証されません。

range-rbegin-rend.svg

目次

翻訳の説明: - 「Contents」を「目次」に翻訳 - HTMLタグ、属性、
タグ内のテキストは翻訳せず保持
- C++固有の用語(Return value、Complexity、Example、See also)は翻訳せず保持
- 元のフォーマットと構造を完全に維持

戻り値

最後の要素の次の要素への逆イテレータ。

計算量

定数。

#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)
コンテナまたは配列の逆方向終端イテレータを返す
(関数テンプレート)