命名空间
变体
操作

std::inplace_vector<T,N>::rbegin, std::inplace_vector<T,N>::crbegin

来自 cppreference.cn
< cpp‎ | 容器‎ | 原位向量
 
 
 
 
constexpr reverse_iterator rbegin() noexcept;
(1) (C++26 起)
constexpr const_reverse_iterator rbegin() const noexcept;
(2) (C++26 起)
constexpr const_reverse_iterator crbegin() const noexcept;
(3) (C++26 起)

返回指向反向 inplace_vector 的首元素的逆向迭代器。它对应于非反向 inplace_vector 的末元素。如果 inplace_vector 为空,则返回的迭代器等于 rend()

range-rbegin-rend.svg

内容

[编辑] 返回值

指向首元素的逆向迭代器。

[编辑] 复杂度

常数。

[编辑] 注解

返回的逆向迭代器的底层迭代器end 迭代器。因此,如果 end 迭代器失效,则返回的迭代器也会失效。

[编辑] 示例

#include <algorithm>
#include <inplace_vector>
#include <iostream>
#include <string>
#include <string_view>
 
void print(const std::string_view s) { std::cout << s << ' '; }
 
int main()
{
    const std::inplace_vector<std::string_view, 8> data
    {
        "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"
    };
    std::inplace_vector<std::string, 8> arr(8);
 
    std::copy(data.cbegin(), data.cend(), arr.begin());
 
    print("Print 'arr' in direct order using [cbegin, cend):\t");
    std::for_each(arr.cbegin(), arr.cend(), print);
 
    print("\n\nPrint 'arr' in reverse order using [crbegin, crend):\t");
    std::for_each(arr.crbegin(), arr.crend(), print);
}

输出

Print 'arr' in direct order using [cbegin, cend):        ▁ ▂ ▃ ▄ ▅ ▆ ▇ █
 
Print 'arr' in reverse order using [crbegin, crend):     █ ▇ ▆ ▅ ▄ ▃ ▂ ▁

[编辑] 参见

返回指向末尾的逆向迭代器
(公开成员函数) [编辑]
返回指向容器或数组开头的逆向迭代器
(函数模板) [编辑]