close
名前空間
変種

std::rend, std::crend

提供: cppreference.com
 
 
イテレータライブラリ
イテレータコンセプト
イテレータプリミティブ
アルゴリズムのコンセプトとユーティリティ
間接呼び出し可能コンセプト
共通アルゴリズム要件
ユーティリティ
イテレータアダプタ
ストリームイテレータ
イテレータのカスタマイゼーションポイント
イテレータ操作
(C++11)
(C++11)
範囲アクセス
(C++11)(C++14)
(C++11)(C++14)
(C++17)(C++20)
(C++14)(C++14)
(C++14)(C++14)
(C++17)
(C++17)
 
<tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody>
ヘッダ <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 修飾されたイテレータを返します。

Image

引数

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]