名前空間
変種
操作

std::rend, std::crend

提供: cppreference.com
< cpp‎ | iterator
 
 
イテレータライブラリ
イテレータコンセプト
イテレータプリミティブ
アルゴリズムのコンセプトとユーティリティ
間接呼び出し可能コンセプト
共通アルゴリズム要件
ユーティリティ
イテレータアダプタ
ストリームイテレータ
イテレータのカスタマイゼーションポイント
イテレータ操作
(C++11)
(C++11)
範囲アクセス
(C++11)(C++14)
(C++11)(C++14)
(C++17)(C++20)
(C++14)(C++14)
rendcrend
(C++14)(C++14)
(C++17)
(C++17)
 
ヘッダ <iterator> で定義
(1)
template< class C >
auto rend( C& c ) -> decltype(c.rend());
(C++14以上)
(C++17未満)
template< class C >
constexpr auto rend( C& c ) -> decltype(c.rend());
(C++17以上)
(1)
template< class C >
auto rend( const C& c ) -> decltype(c.rend());
(C++14以上)
(C++17未満)
template< class C >
constexpr auto rend( const C& c ) -> decltype(c.rend());
(C++17以上)
(2)
template< class T, size_t N >
reverse_iterator<T*> rend( T (&array)[N] );
(C++14以上)
(C++17未満)
template< class T, size_t N >
constexpr reverse_iterator<T*> rend( T (&array)[N] );
(C++17以上)
(3)
template< class C >
auto crend( const C& c ) -> decltype(std::rend(c));
(C++14以上)
(C++17未満)
template< class C >
constexpr auto crend( const C& c ) -> decltype(std::rend(c));
(C++17以上)

指定されたコンテナ c または配列 array の逆の終端を指すイテレータを返します。

1) コンテナ c の逆の終端を指す const 修飾されたまたはされていないイテレータを返します。
2) 配列 array の逆の終端を指す std::reverse_iterator<T*> を返します。
3) コンテナ c の逆の終端を指す const 修飾されたイテレータを返します。

range-rbegin-rend.svg

目次

[編集] 引数

c - メンバ関数 rend を持つコンテナ
array - 任意の型の配列

[編集] 戻り値

c または array の逆の終端を指すイテレータ。

[編集] ノート

<iterator> がインクルードされた場合に加えて <array><deque><forward_list><list><map><regex><set><span> (C++20以上)<string><string_view> (C++17以上)<unordered_map><unordered_set><vector> のいずれかのヘッダがインクルードされた場合も、 std::rend および std::crend が利用可能になることが保証されています。

[編集] オーバーロード

適切な rend() メンバ関数を持たないけれどもイテレート可能なクラスに対して、 rend のカスタムオーバーロードを提供しても構いません。 以下のオーバーロードは標準ライブラリによってすでに提供されています。

std::rend の特殊化
(関数) [edit]

[編集]

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
 
int main()
{
    int a[] = {4, 6, -3, 9, 10};
    std::cout << "Array backwards: ";
    std::copy(std::rbegin(a), std::rend(a), std::ostream_iterator<int>(std::cout, " "));
 
    std::cout << "\nVector backwards: ";
    std::vector<int> v = {4, 6, -3, 9, 10};
    std::copy(std::rbegin(v), std::rend(v), std::ostream_iterator<int>(std::cout, " "));
}

出力:

Array backwards: 10 9 -3 6 4 
Vector backwards: 10 9 -3 6 4

[編集] 関連項目

(C++11)(C++14)
コンテナまたは配列の終端を指すイテレータを返します
(関数) [edit]
コンテナまたは配列の先頭を指す逆イテレータを返します
(関数) [edit]
(C++11)(C++14)
コンテナまたは配列の先頭を指すイテレータを返します
(関数) [edit]