GeezerVison is showing cpprefjp.github.io — std::rend - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function template
<iterator>
std:: rend (C++14)
namespace std {
template < class C >
auto
rend ( C & c )
-> decltype ( c . rend ()); // (1) C++14
template < class C >
constexpr auto
rend ( C & c )
-> decltype ( c . rend ()); // (1) C++17
template < class C >
constexpr auto
rend ( C & c )
noexcept ( noexcept ( c . rend ()))
-> decltype ( c . rend ()); // (1) C++26
template < class C >
auto
rend ( const C & c )
-> decltype ( c . rend ()); // (2) C++14
template < class C >
constexpr auto
rend ( const C & c )
-> decltype ( c . rend ()); // (2) C++17
template < class C >
constexpr auto
rend ( const C & c )
noexcept ( noexcept ( c . rend ()))
-> decltype ( c . rend ()); // (2) C++26
template < class T , size_t N >
reverse_iterator < T *>
rend ( T ( & array )[ N ]); // (3) C++14
template < class T , size_t N >
constexpr reverse_iterator < T *>
rend ( T ( & array )[ N ]) noexcept ; // (3) C++17
template < class E >
reverse_iterator < const E *>
rend ( initializer_list < E > il ); // (4) C++14
template < class E >
constexpr reverse_iterator < const E *>
rend ( initializer_list < E > il ); // (4) C++17
}
概要
範囲の先頭の前を指す逆イテレータを取得する。
(1) : コンテナのrend()メンバ関数で、範囲の先頭の前を指す、逆イテレータを返す。
(2) : コンテナのrend()メンバ関数で、範囲の先頭の前を指す、読み取り専用逆イテレータを返す。
(3) : 組み込み配列の先頭の前を指す、逆イテレータを返す。
(4) : initializer_listオブジェクトの先頭の前を指す、読み取り専用逆イテレータを返す。C++26で削除。
戻り値
備考
<iterator>ヘッダを読み込む以外では、以下のヘッダが読み込まれている場合に、この関数を使用できる:
例
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
void print ( int x )
{
std::cout << x << " " ;
}
int main ()
{
// コンテナ
{
std::vector < int > v = { 1 , 2 , 3 };
decltype ( v ) :: reverse_iterator first = std::rbegin ( v );
decltype ( v ) :: reverse_iterator last = std::rend ( v );
std::for_each ( first , last , print );
}
std::cout << std::endl ;
// 組み込み配列
{
int ar [] = { 4 , 5 , 6 };
std::reverse_iterator < int *> first = std::rbegin ( ar );
std::reverse_iterator < int *> last = std::rend ( ar );
std::for_each ( first , last , print );
}
std::cout << std::endl ;
// 初期化子リスト
{
std::initializer_list < int > init = { 7 , 8 , 9 };
std::reverse_iterator < const int *> first = std::rbegin ( init );
std::reverse_iterator < const int *> last = std::rend ( init );
std::for_each ( first , last , print );
}
}
出力
3 2 1
6 5 4
9 8 7
バージョン
言語
処理系
参照