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

来自cppreference.com
< cpp‎ | container‎ | span
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

目录

[编辑] 返回值

指向首元素的逆向迭代器。

[编辑] 复杂度

常数。

[编辑] 注解

返回的逆向迭代器的底层迭代器尾迭代器。因此在尾迭代器失效时,返回的迭代器也会失效。

[编辑] 示例

#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)
返回指向末尾的逆向迭代器
(公开成员函数) [编辑]
返回指向一个容器或数组的逆向迭代器
(函数模板) [编辑]