std::multiset<Key,Compare,Allocator>::rbegin, std::multiset<Key,Compare,Allocator>::crbegin
来自 cppreference.cn
reverse_iterator rbegin(); |
(1) | (C++11 起 noexcept) |
const_reverse_iterator rbegin() const; |
(2) | (C++11 起 noexcept) |
const_reverse_iterator crbegin() const noexcept; |
(3) | (C++11 起) |
返回指向反向 multiset
的首元素的逆向迭代器。它对应于非反向 multiset
的末尾元素。如果 multiset
为空,则返回的迭代器等于 rend()。
目录 |
[编辑] 返回值
指向首元素的逆向迭代器。
[编辑] 复杂度
常数时间复杂度。
[编辑] 注解
由于 iterator 和 const_iterator 都是常量迭代器 (实际上可能为同一类型),因此无法通过这些成员函数返回的迭代器来修改容器的元素。
返回的逆向迭代器的底层迭代器是 end 迭代器。因此,如果 end 迭代器失效,则返回的迭代器也会失效。
libc++ 将 crbegin() 向后移植到 C++98 模式。
[编辑] 示例
运行此代码
#include <iostream> #include <set> int main() { std::multiset<unsigned> rep{1, 2, 3, 4, 1, 2, 3, 4}; for (auto it = rep.crbegin(); it != rep.crend(); ++it) { for (auto n = *it; n > 0; --n) std::cout << "⏼" << ' '; std::cout << '\n'; } }
输出
⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼ ⏼
[编辑] 参见
(C++11) |
返回指向末尾的逆向迭代器 (公共成员函数) |
(C++14) |
返回指向容器或数组开头的逆向迭代器 (函数模板) |