命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | 容器‎ | span
constexpr reverse_iterator rbegin() const noexcept;
(1) (C++20 起)
constexpr const_reverse_iterator crbegin() const noexcept;
(2) (C++23 起)

返回反转的 span 的第一个元素的逆向迭代器。它对应于非反转 span 的最后一个元素。如果 span 为空,则返回的迭代器等于 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)
返回指向末尾的逆向迭代器
(公共成员函数) [编辑]
返回指向容器或数组开头的反向迭代器
(函数模板) [编辑]