std::rend, std::crend
提供: cppreference.com
ヘッダ <iterator> で定義 | ||
(1) | ||
template<class C > auto rend( C& c )-> decltype(c.rend()); | (C++14以上) (C++17未満) | |
template<class C > constexprauto 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 > constexprauto 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 > constexprauto crend(const C& c )-> decltype(std::rend(c)); | (C++17以上) | |
指定されたコンテナ c
または配列 array
の逆の終端を指すイテレータを返します。
1) コンテナ
c
の逆の終端を指す const 修飾されたまたはされていないイテレータを返します。3) コンテナ
c
の逆の終端を指す const 修飾されたイテレータを返します。目次 |
[編集]引数
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
のカスタムオーバーロードを提供しても構いません。 以下のオーバーロードは標準ライブラリによってすでに提供されています。
(C++14) | std::rend の特殊化 (関数) |
[編集]例
Run this code
#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) | コンテナまたは配列の終端を指すイテレータを返します (関数) |
(C++14) | コンテナまたは配列の先頭を指す逆イテレータを返します (関数) |
(C++11)(C++14) | コンテナまたは配列の先頭を指すイテレータを返します (関数) |