Namespaces
Variants

std::span<T,Extent>:: rbegin, std::span<T,Extent>:: crbegin

From cppreference.net

constexpr reverse_iterator rbegin ( ) const noexcept ;
(1) (自 C++20 起)
constexpr const_reverse_iterator crbegin ( ) const noexcept ;
(2) (自 C++23 起)

返回指向反转后 * this 首元素的反向迭代器。该元素对应于未反转 * this 的最后一个元素。

如果 * this 为空,则返回的迭代器等于 rend()

range-rbegin-rend.svg

目录

返回值

指向第一个元素的反向迭代器。

复杂度

常量。

注释

返回的反向迭代器的 底层迭代器 end 迭代器 。因此当 end 迭代器失效时,返回的迭代器也会同时失效。

示例

#include <algorithm>
#include <iostream>
#include <iterator>
#include <span>
int main()
{
    constexpr std::span<const char> code{"@droNE_T0P_w$s@s#_SECRET_a,p^42!"};
    auto hack = [](const unsigned O) { return O - 0141 < 120; };
    std::copy_if(code.rbegin(), code.rend(),
        std::ostream_iterator<const char>(std::cout), hack);
    std::cout << '\n';
}

输出:

password

参见

(C++23)
返回指向末尾的反向迭代器
(公开成员函数)
返回指向容器或数组起始位置的反向迭代器
(函数模板)