std::span<T,Extent>::rend, std::span<T,Extent>::crend
来自 cppreference.cn
constexpr reverse_iterator rend() const noexcept; |
(1) | (始于 C++20) |
constexpr const_reverse_iterator crend() const noexcept; |
(2) | (始于 C++23) |
返回指向逆序 span
的最后一个元素之后元素的逆序迭代器。它对应于非逆序 span
的第一个元素之前的元素。此元素充当占位符,尝试访问它会导致未定义行为。
内容 |
[编辑] 返回值
指向最后一个元素之后元素的逆序迭代器。
[编辑] 复杂度
常数。
[编辑] 示例
运行此代码
#include <algorithm> #include <iostream> #include <span> #include <string_view> void ascending(const std::span<const std::string_view> data, const std::string_view term) { std::for_each(data.begin(), data.end(), [](const std::string_view x) { std::cout << x << ' '; }); std::cout << term; } void descending(const std::span<const std::string_view> data, const std::string_view term) { std::for_each(data.rbegin(), data.rend(), [](const std::string_view x) { std::cout << x << ' '; }); std::cout << term; } int main() { constexpr std::string_view bars[]{"▁","▂","▃","▄","▅","▆","▇","█"}; ascending(bars, " "); descending(bars, "\n"); }
输出
▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
[编辑] 参见
(C++23) |
返回指向开头的逆序迭代器 (公共成员函数) |
(C++14) |
返回容器或数组的逆序尾后迭代器 (函数模板) |