名前空間
変種
操作

std::array<T,N>::rend, std::array<T,N>::crend

From cppreference.com
< cpp‎ | container‎ | array
 
 
 
 
reverse_iterator rend() noexcept;
(1) (C++11以降)
(C++17 以降 constexpr)
const_reverse_iterator rend() const noexcept;
(2) (C++11以降)
(C++17 以降 constexpr)
const_reverse_iterator crend() const noexcept;
(3) (C++11以降)
(C++17 以降 constexpr)

逆順にされたarrayの最後の要素の次の要素への逆イテレータを返します。これは、通常の順序のarrayの最初の要素の前の要素に対応します。この要素はプレースホルダーとして機能し、アクセスしようとすると未定義の動作が発生します。

range-rbegin-rend.svg

目次

[編集] 戻り値

最後の要素の次の要素へのリバースイテレータ。

[編集] 複雑性

定数。

[編集]

#include <algorithm>
#include <iostream>
#include <array>
 
int main()
{
    std::array<int, 11> a{1, 11, 11, 35, 0, 12, 79, 76, 76, 69, 40};
 
    // Print elements of container in reverse order using const_reverse_iterator's.
    std::for_each(a.crbegin(), a.crend(), [](int e){ std::cout << e << ' '; });
    std::cout << '\n';
 
    // Modify each element of container using non-const reverse_iterator's.
    std::for_each(a.rbegin(), a.rend(), [](int& e){ e += 32; });
 
    // Print elements as chars in reverse order using const_reverse_iterator's.
    std::for_each(a.crbegin(), a.crend(), [](char e){ std::cout << e; });
    std::cout << '\n';
}

出力

40 69 76 76 79 12 0 35 11 11 1
Hello, C++!

[編集] 関連項目

先頭への逆イテレータを返す
(public メンバ関数) [編集]
(C++14)
コンテナまたは配列の逆順の終端イテレータを返す
(function template) [編集]
English 日本語 中文(简体) 中文(繁體)