std::deque<T,Allocator>:: rend, std::deque<T,Allocator>:: crend
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::deque
| Member types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Deduction guides (C++17) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
reverse_iterator rend
(
)
;
|
(1) |
(自 C++11 起为 noexcept)
(自 C++26 起为 constexpr) |
|
const_reverse_iterator rend
(
)
const
;
|
(2) |
(自 C++11 起为 noexcept)
(自 C++26 起为 constexpr) |
|
const_reverse_iterator crend
(
)
const
noexcept
;
|
(3) |
(自 C++11 起)
(自 C++26 起为 constexpr) |
返回一个反向迭代器,指向反转后 * this 的最后一个元素之后的位置。它对应于非反转 * this 的第一个元素之前的位置。
此返回的迭代器仅作为哨兵使用。不保证其具有 可解引用性 。
目录 |
返回值
指向最后一个元素之后元素的反向迭代器。
复杂度
常量。
注释
libc++ 向后移植
crend()
至 C++98 模式。
示例
运行此代码
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <deque> int main() { std::deque<int> nums{1, 2, 4, 8, 16}; std::deque<std::string> fruits{"orange", "apple", "raspberry"}; std::deque<char> empty; // 打印双端队列 std::for_each(nums.rbegin(), nums.rend(), [](const int n) { std::cout << n << ' '; }); std::cout << '\n'; // 对双端队列nums中的所有整数求和(如果有),仅打印结果 std::cout << "Sum of nums: " << std::accumulate(nums.rbegin(), nums.rend(), 0) << '\n'; // 打印双端队列fruits中的第一个水果,检查是否存在 if (!fruits.empty()) std::cout << "First fruit: " << *fruits.rbegin() << '\n'; if (empty.rbegin() == empty.rend()) std::cout << "deque 'empty' is indeed empty.\n"; }
输出:
16 8 4 2 1 Sum of nums: 31 First fruit: raspberry deque 'empty' is indeed empty.
另请参阅
|
(C++11)
|
返回指向起始位置的反向迭代器
(公开成员函数) |
|
(C++14)
|
返回容器或数组的逆向末端迭代器
(函数模板) |