std::span<T,Extent>::rend, std::span<T,Extent>::crend
来自cppreference.com
constexpr reverse_iterator rend()constnoexcept; | (1) | (C++20 起) |
constexpr const_reverse_iterator crend()constnoexcept; | (2) | (C++23 起) |
返回指向逆向的 *this 的尾后元素的逆向迭代器。它对应非逆向的 *this 的首元素的前一元素。
返回的迭代器仅表现为哨位。不保证它可解引用。
目录 |
[编辑]返回值
指向尾后元素的逆向迭代器。
[编辑]复杂度
常数。
[编辑]示例
运行此代码
#include <algorithm>#include <iostream>#include <span>#include <string_view> void ascending(conststd::span<conststd::string_view> data, conststd::string_view term){std::for_each(data.begin(), data.end(), [](conststd::string_view x){std::cout<< x <<" ";});std::cout<< term;} void descending(conststd::span<conststd::string_view> data, conststd::string_view term){std::for_each(data.rbegin(), data.rend(), [](conststd::string_view x){std::cout<< x <<" ";});std::cout<< term;} int main(){constexprstd::string_view bars[]{"▁","▂","▃","▄","▅","▆","▇","█"}; ascending(bars, " "); descending(bars, "\n");}
输出:
▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
[编辑]参阅
(C++23) | 返回指向起始的逆向迭代器 (公开成员函数) |
(C++14) | 返回容器或数组的逆向尾迭代器 (函数模板) |