std::rend, std::crend
From cppreference.com
| ヘッダー <array> で定義 |
||
| ヘッダー <deque> で定義 |
||
| ヘッダ <flat_map> で定義 |
||
| ヘッダ <flat_set> で定義 |
||
| ヘッダ <forward_list> で定義 |
||
| ヘッダ <inplace_vector> で定義 |
||
| ヘッダ <iterator> で定義 |
||
| ヘッダ <list> で定義 |
||
| ヘッダ <map> で定義 |
||
| ヘッダ <regex> で定義 |
||
| ヘッダー <set> で定義 |
||
| ヘッダ <span> で定義 |
||
| ヘッダ <string> で定義 |
||
| ヘッダ <string_view> で定義 |
||
| ヘッダ <unordered_map> で定義 |
||
| ヘッダー <unordered_set> で定義 |
||
| ヘッダー <vector> で定義 |
||
template< class C > auto rend( C& c ) -> decltype(c.rend()); |
(1) | (C++14以降) (C++17 以降 constexpr) |
template< class C > auto rend( const C& c ) -> decltype(c.rend()); |
(2) | (C++14以降) (C++17 以降 constexpr) |
template< class T, std::size_t N > std::reverse_iterator<T*> rend( T (&array)[N] ); |
(3) | (C++14以降) (C++17 以降 constexpr) |
template< class T > std::reverse_iterator<const T*> rend( std::initializer_list<T> il ); |
(4) | (C++14以降) (C++17 以降 constexpr) |
template< class C > auto crend( const C& c ) -> decltype(std::rend(c)); |
(5) | (C++14以降) (C++17 以降 constexpr) |
指定された範囲の逆エンドへのイテレータを返します。
1,2) c.rend() を返します。これは通常、c が表すシーケンスの逆エンドの1つ後ろのイテレータです。
目次 |
[編集] パラメータ
| c | - | rend メンバ関数を持つコンテナまたはビュー |
| array | - | 任意の型の配列 |
| il | - | std::initializer_list |
[編集] 戻り値
1,2) c.rend()
3) std::reverse_iterator<T*>(array)
4) std::reverse_iterator<const T*>(il.begin())
5) c.rend()
[編集] 例外
実装定義の例外をスローする場合があります。
[編集] オーバーロード
反復可能なクラスや列挙型で、適切な rend() メンバ関数が公開されていない場合のために、カスタムの rend オーバーロードを提供できます。
|
引数依存名前探索によって見つかる |
(C++20以降) |
[編集] 注記
std::initializer_list のオーバーロードは、メンバ関数 rend を持たないため必要です。
[編集] 例
このコードを実行
#include <algorithm> #include <iostream> #include <iterator> #include <vector> int main() { int a[]{4, 6, -3, 9, 10}; std::cout << "C-style array `a` backwards: "; std::copy(std::rbegin(a), std::rend(a), std::ostream_iterator<int>(std::cout, " ")); auto il = {3, 1, 4}; std::cout << "\nstd::initializer_list `il` backwards: "; std::copy(std::rbegin(il), std::rend(il), std::ostream_iterator<int>(std::cout, " ")); std::vector<int> v{4, 6, -3, 9, 10}; std::cout << "\nstd::vector `v` backwards: "; std::copy(std::rbegin(v), std::rend(v), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n'; }
出力
C-style array `a` backwards: 10 9 -3 6 4 std::initializer_list `il` backwards: 4 1 3 std::vector `v` backwards: 10 9 -3 6 4
[編集] 関連項目
| (C++11)(C++14) |
コンテナまたは配列の末尾を指すイテレータを返す (関数テンプレート) |
| (C++14) |
コンテナまたは配列の先頭を指す逆順イテレータを返す (function template) |
| (C++11)(C++14) |
コンテナまたは配列の先頭を指すイテレータを返す (関数テンプレート) |
| (C++20) |
rangeへの逆終端イテレータを返す (カスタマイゼーションポイントオブジェクト) |
| (C++20) |
読み取り専用rangeへの逆終端イテレータを返す (カスタマイゼーションポイントオブジェクト) |