◐ Shell
clean mode source ↗

std::span<T,Extent>::rend, std::span<T,Extent>::crend - cppreference.com

来自cppreference.com

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

输出:

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

参阅