Namespaces
Variants

std::span<T,Extent>:: rend, std::span<T,Extent>:: crend

From cppreference.net

constexpr reverse_iterator rend ( ) const noexcept ;
(1) (C++20부터)
constexpr const_reverse_iterator crend ( ) const noexcept ;
(2) (C++23부터)

역순으로 된 * this 의 마지막 요소 다음을 가리키는 역방향 반복자를 반환합니다. 이는 비역순 * this 의 첫 번째 요소 바로 앞 요소에 해당합니다.

이 반환된 반복자는 단지 센티널 역할만 합니다. 이것이 역참조 가능 하다는 보장은 없습니다.

range-rbegin-rend.svg

목차

반환값

마지막 요소 다음에 오는 요소로의 역방향 반복자.

복잡도

상수.

예제

#include <algorithm>
#include <iostream>
#include <span>
#include <string_view>
void ascending(const std::span<const std::string_view> data,
               const std::string_view term)
{
    std::for_each(data.begin(), data.end(),
        [](const std::string_view x) { std::cout << x << ' '; });
    std::cout << term;
}
void descending(const std::span<const std::string_view> data,
                const std::string_view term)
{
    std::for_each(data.rbegin(), data.rend(),
        [](const std::string_view x) { std::cout << x << ' '; });
    std::cout << term;
}
int main()
{
    constexpr std::string_view bars[]{"▁","▂","▃","▄","▅","▆","▇","█"};
    ascending(bars, " ");
    descending(bars, "\n");
}

출력:

▁ ▂ ▃ ▄ ▅ ▆ ▇ █  █ ▇ ▆ ▅ ▄ ▃ ▂ ▁

참고 항목

시작 부분으로의 역방향 반복자를 반환합니다
(public member function)
(C++14)
컨테이너나 배열을 위한 역방향 끝 반복자를 반환합니다
(function template)