命名空间
变体
操作

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

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

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