Namespaces
Variants

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

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()와 같습니다.

반환값

첫 번째 요소로의 역방향 반복자.

복잡도

상수.

참고 사항

반환된 역방향 반복자의 기반 반복자 는 end iterator 입니다. 따라서 end iterator가 무효화될 경우 반환된 반복자도 무효화됩니다.

예제

#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)