Namespaces
Variants

std::rend, std::crend

cppreference.net에서
 
 
반복자 라이브러리
반복자 개념
반복자 기본 요소
알고리즘 개념 및 유틸리티
간접 호출 가능 개념
공통 알고리즘 요구 사항
(C++20)
(C++20)
(C++20)
유틸리티
(C++20)
반복자 어댑터
범위 접근
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
헤더 <array>
헤더 <deque>
헤더 <flat_map>
 (C++23부터)
헤더 <flat_set>
 (C++23부터)
 (C++26부터)
헤더 <iterator>
헤더 <list>
헤더 <map>
헤더 <optional>
 (C++26부터)
헤더 <regex>
헤더 <set>
헤더 <span>
 (C++20부터)
헤더 <stacktrace>
 (C++23부터)
헤더 <string>
 (C++17부터)
헤더 <valarray>
헤더 <vector>
template< class C >
auto rend( C& c ) noexcept(noexcept(c.rend()))
    -> decltype(c.rend());
(1) (C++14부터)
(C++17부터 constexpr)
template< class C >
auto rend( const C& c ) noexcept(noexcept(c.rend()))
    -> decltype(c.rend());
(2) (C++14부터)
(C++17부터 constexpr)
template< class T, std::size_t N >
std::reverse_iterator<T*> rend( T (&array)[N] ) noexcept;
(3) (C++14부터)
(C++17부터 constexpr)
template< class T >
std::reverse_iterator<const T*> rend( std::initializer_list<T> il ) noexcept;
(4) (C++14부터)
(C++17부터 constexpr)
template< class C >
auto crend( const C& c ) noexcept(noexcept(std::rend(c)))
    -> decltype(std::rend(c));
(5) (C++14부터)
(C++17부터 constexpr)

주어진 범위의 역방향 끝을 가리키는 반복자를 반환합니다.

1,2) c.rend()을(를) 반환합니다. 이는 일반적으로 c이(가) 나타내는 시퀀스의 역방향 끝 바로 다음을 가리키는 반복자입니다.
1) C이(가) 표준 Container인 경우, C::reverse_iterator 객체를 반환합니다.
2) C이(가) 표준 Container인 경우, C::const_reverse_iterator 객체를 반환합니다.
3) std::reverse_iterator<T*> 객체를 array의 역방향 끝으로 반환합니다.
4) std::reverse_iterator<const T*> 객체를 il의 역방향 끝으로 반환합니다.
5) std::end(c)을(를) 반환합니다. 이때 c은(는) 항상 const 한정으로 처리됩니다.
C이(가) 표준 Container인 경우, C::const_reverse_iterator 객체를 반환합니다.

매개변수

c - rend 멤버 함수를 가진 컨테이너 또는 뷰
array - 임의 타입의 배열
il - std:: initializer_list

반환값

1,2) c. rend ( )
3) std:: reverse_iterator < T * > ( array )
4) std:: reverse_iterator < const T * > ( il. begin ( ) )
5) c. rend ( )

예외

구현 정의 예외를 던질 수 있습니다.

오버로드

클래스와 열거형이 적절한 rend 멤버 함수를 노출하지 않지만 반복이 가능한 경우, rend() 에 대한 사용자 정의 오버로드를 제공할 수 있습니다.

인수 종속 탐색 으로 찾은 rend 의 오버로드는 std :: ranges:: rend 과 std::ranges::crend 의 동작을 사용자 정의하는 데 사용할 수 있습니다.

(C++20부터)

참고 사항

std::initializer_list 에 대한 오버로드는 rend 멤버 함수를 가지고 있지 않기 때문에 필요합니다.

예제

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
int main()
{
    int a[]{4, 6, -3, 9, 10};
    std::cout << "C-style array `a` backwards: ";
    std::copy(std::rbegin(a), std::rend(a), std::ostream_iterator<int>(std::cout, " "));
    auto il = {3, 1, 4};
    std::cout << "\nstd::initializer_list `il` backwards: ";
    std::copy(std::rbegin(il), std::rend(il), std::ostream_iterator<int>(std::cout, " "));
    std::vector<int> v{4, 6, -3, 9, 10};
    std::cout << "\nstd::vector `v` backwards: ";
    std::copy(std::rbegin(v), std::rend(v), std::ostream_iterator<int>(std::cout, " "));
    std::cout << '\n';
}

출력:

C-style array `a` backwards: 10 9 -3 6 4
std::initializer_list `il` backwards: 4 1 3
std::vector `v` backwards: 10 9 -3 6 4

결함 보고서

다음 동작 변경 결함 보고서는 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 3537 C++14 std::rend 및 std::crend 는 예외 명세를 전파할 필요가 없었습니다 요구됨

참고 항목

(C++11) (C++14)
컨테이너나 배열의 끝을 가리키는 반복자를 반환합니다
(함수 템플릿)
컨테이너나 배열의 시작을 가리키는 역방향 반복자를 반환합니다
(함수 템플릿)
(C++11) (C++14)
컨테이너나 배열의 시작을 가리키는 반복자를 반환합니다
(함수 템플릿)
범위의 역방향 끝 반복자를 반환합니다
(커스터마이제이션 포인트 객체)
읽기 전용 범위의 역방향 끝 반복자를 반환합니다
(커스터마이제이션 포인트 객체)