命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | container‎ | multimap
 
 
 
 
reverse_iterator rbegin();
(1) (noexcept since C++11)
const_reverse_iterator rbegin() const;
(2) (noexcept since C++11)
const_reverse_iterator crbegin() const noexcept;
(3) (since C++11)

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

range-rbegin-rend.svg

目录

[编辑] 返回值

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

[编辑] 复杂度

常量。

[编辑] 注解

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

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 << "Print out in reverse order using const reverse iterators:\n";
    std::for_each(map.crbegin(), map.crend(),
        [](std::pair<const std::string, int> const& e)
        {
            std::cout << "{ \"" << e.first << "\", " << e.second << " };\n";
        });
 
    map.rbegin()->second = 42; // OK: non-const value is modifiable
//  map.crbegin()->second = 42; // Error: cannot modify the const value
}

可能的输出

Print out in reverse order using const reverse iterators:
{ "▓", 8 };
{ "▓", 7 };
{ "▒", 6 };
{ "▒", 5 };
{ "░", 4 };
{ "░", 3 };
{ "█", 2 };
{ "█", 1 };

[编辑] 参见

(C++11)
返回指向末尾的逆序迭代器
(public member function) [编辑]
返回指向容器或数组开头的逆序迭代器
(function template) [编辑]