名稱空間
變體
操作

std::span<T,Extent>::rend, std::span<T,Extent>::crend

來自 cppreference.com
< cpp‎ | 容器‎ | span
constexpr reverse_iterator rend() const noexcept;
(1) (C++20 起)
constexpr const_reverse_iterator crend() const noexcept;
(2) (C++23 起)

返回一個反向迭代器,指向反向 span 的末尾元素之後。它對應於非反向 span 的第一個元素之前的位置。此元素用作佔位符,嘗試訪問它會導致未定義行為。

range-rbegin-rend.svg

目錄

[編輯] 返回值

指向最後一個元素之後位置的逆向迭代器。

[編輯] 複雜度

常數時間。

[編輯] 示例

#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");
}

輸出

▁ ▂ ▃ ▄ ▅ ▆ ▇ █  █ ▇ ▆ ▅ ▄ ▃ ▂ ▁

[編輯] 參閱

返回指向起始的逆向迭代器
(public member function) [編輯]
(C++14)
返回容器或陣列的反向結束迭代器
(function template) [編輯]