Namespaces
Variants

std::array<T,N>::rbegin, std::array<T,N>::crbegin

ja.cppreference.net より

 
 
 
 
reverse_iterator rbegin() noexcept;
(1) (C++11 から)
(C++17 から constexpr)
const_reverse_iterator rbegin() const noexcept;
(2) (C++11 から)
(C++17 から constexpr)
const_reverse_iterator crbegin() const noexcept;
(3) (C++11 から)
(C++17 から constexpr)

逆順の array の最初の要素を指す逆イテレータを返します。これは、逆順でない array の最後の要素に対応します。array が空の場合は、返されたイテレータは rend() と等しくなります。

戻り値

最初の要素への逆イテレータ。

計算量

定数。

注記

返される逆イテレータの 基盤となるイテレータ は 終端イテレータ です。したがって、終端イテレータが無効化された場合、返されるイテレータも無効化されます。

例

#include <algorithm>
#include <iostream>
#include <string>
#include <string_view>
#include <array>

void print(const std::string_view s) { std::cout << s << ' '; }

int main()
{
    const std::array<std::string_view, 8> data
    {
        "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"
    };
    std::array<std::string, 8> arr;

    std::copy(data.cbegin(), data.cend(), arr.begin());

    print("Print 'arr' in direct order using [cbegin, cend):\t");
    std::for_each(arr.cbegin(), arr.cend(), print);

    print("\n\nPrint 'arr' in reverse order using [crbegin, crend):\t");
    std::for_each(arr.crbegin(), arr.crend(), print);
}

出力:

Print 'arr' in direct order using [cbegin, cend):        ▁ ▂ ▃ ▄ ▅ ▆ ▇ █

Print 'arr' in reverse order using [crbegin, crend):     █ ▇ ▆ ▅ ▄ ▃ ▂ ▁

関連項目

末尾を指す逆方向イテレータを返す
(public member function)
コンテナまたは配列の先頭を指す逆方向イテレータを返す
(function template)