跳到主要内容

std::span rbegin() 方法

constexpr iterator rbegin() const noexcept;

返回一个反向迭代器

指向反向视图的第一个元素。
它对应于非反向视图的最后一个元素。

如果 span 为空,返回的迭代器将等于 rend()

注意

此方法实际上并未反转视图,它返回一个指向视图最后一个元素的迭代器,其 +---++ 运算符的实现略有改变。

例如,it++会递减内部指针,而it--会递增内部指针(以便以相反的顺序遍历容器实际工作)。

参数

(无)

返回值

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

复杂度

常数 - O(1)

示例

Main.cpp
#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 hacker = [](const unsigned O) { return O-0141<120; };

std::copy_if(code.rbegin(), code.rend(),
std::ostream_iterator<const char>(std::cout), hacker);
}
输出
password
本文档源自此 CppReference 页面。它可能为了改进或编辑者的偏好而进行了修改。点击“编辑此页面”查看本文档所做的所有更改。
悬停查看原始许可证。

std::span rbegin() 方法

constexpr iterator rbegin() const noexcept;

返回一个反向迭代器

指向反向视图的第一个元素。
它对应于非反向视图的最后一个元素。

如果 span 为空,返回的迭代器将等于 rend()

注意

此方法实际上并未反转视图,它返回一个指向视图最后一个元素的迭代器,其 +---++ 运算符的实现略有改变。

例如,it++会递减内部指针,而it--会递增内部指针(以便以相反的顺序遍历容器实际工作)。

参数

(无)

返回值

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

复杂度

常数 - O(1)

示例

Main.cpp
#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 hacker = [](const unsigned O) { return O-0141<120; };

std::copy_if(code.rbegin(), code.rend(),
std::ostream_iterator<const char>(std::cout), hacker);
}
输出
password
本文档源自此 CppReference 页面。它可能为了改进或编辑者的偏好而进行了修改。点击“编辑此页面”查看本文档所做的所有更改。
悬停查看原始许可证。