名前空間
変種
操作

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

From cppreference.com
< cpp‎ | container‎ | 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 メンバ関数) [編集]
(C++14)
コンテナまたは配列の逆順の終端イテレータを返す
(function template) [編集]
English 日本語 中文(简体) 中文(繁體)