std::span<T,Extent>::rend
constexpr reverse_iterator rend() const noexcept; |
||
返回指向逆向 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"); }
输出:
▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
参阅
返回指向起始的逆向迭代器 (公开成员函数) |