std::multimap<Key,T,Compare,Allocator>::rbegin, std::multimap<Key,T,Compare,Allocator>::crbegin

来自cppreference.com
< cpp‎ | container‎ | multimap
 
 
 
 
reverse_iterator rbegin();
(1) (C++11 起为 noexcept)
(C++26 起为 constexpr)
const_reverse_iterator rbegin()const;
(2) (C++11 起为 noexcept)
(C++26 起为 constexpr)
const_reverse_iterator crbegin()constnoexcept;
(3) (C++11 起)
(C++26 起为 constexpr)

返回指向逆向的 *this 的首元素的逆向迭代器。它对应非逆向 *this 的末元素。

如果 *this 为空,那么返回的迭代器等于 rend()

range-rbegin-rend.svg

目录

[编辑]返回值

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

[编辑]复杂度

常数。

[编辑]注解

返回的逆向迭代器的底层迭代器尾迭代器。因此在尾迭代器失效时,返回的迭代器也会失效。

libc++ 将 crbegin() 向后移植到 C++98 模式。

[编辑]示例

#include <algorithm>#include <iostream>#include <string>#include <map>   int main(){std::multimap<std::string, int> map {{"█", 1}, {"▒", 5}, {"░", 3}, {"▓", 7}, {"▓", 8}, {"░", 4}, {"▒", 6}, {"█", 2}};   std::cout<<"使用 const 逆向迭代器进行逆序打印:\n";std::for_each(map.crbegin(), map.crend(), [](std::pair<conststd::string, int>const& e){std::cout<<"{ \""<< e.first<<"\", "<< e.second<<" };\n";});   map.rbegin()->second =42;// OK,可以修改非 const 值// imap.crbegin()->second = 42; // 错误:不能修改 const 值}

可能的输出:

使用 const 逆向迭代器进行逆序打印: { "▓", 8 }; { "▓", 7 }; { "▒", 6 }; { "▒", 5 }; { "░", 4 }; { "░", 3 }; { "█", 2 }; { "█", 1 };

[编辑]参阅

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