list_rbegin

list_rbegin (std::list::rbegin — 역방향 시작 이터레이터)

std::list를 역순으로 순회하기 위한 역방향 이터레이터를 반환하는 멤버 함수예요. 뒤집힌 list의 첫 번째 원소(즉 원래 순서의 마지막 원소)를 가리켜요.

출처: cppreference

본문

시그니처는 다음과 같아요.

reverse_iterator rbegin();                     // (1) (noexcept since C++11)
const_reverse_iterator rbegin() const;         // (2) (noexcept since C++11)
const_reverse_iterator crbegin() const noexcept;   // (3) (since C++11)

뒤집힌 list의 첫 번째 원소를 가리키는 역방향 이터레이터를 반환해요. 원래 순서의 list에선 마지막 원소에 해당해요. list가 비어 있으면 반환된 이터레이터는 rend()와 같아요.

반환값

첫 번째 원소를 가리키는 역방향 이터레이터.

복잡도

상수(constant)예요.

예제

#include <list>
#include <iostream>
int main()
{
    std::list<int> l{1, 2, 3, 4};
    for (auto it = l.rbegin(); it != l.rend(); ++it)
        std::cout << *it << ' ';  // 4 3 2 1
}

함께 보기

  • rend/crend: 끝을 가리키는 역방향 이터레이터를 반환해요

더 알아보기 (Learn more)

cppreference