名前空間
変種
操作

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

From cppreference.com
< cpp‎ | container‎ | multimap
 
 
 
 
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以降)

逆順にしたmultimapの最初の要素への逆イテレータを返します。これは、通常の順序のmultimapの最後の要素に対応します。multimapが空の場合、返されるイテレータはrend()と等しくなります。

range-rbegin-rend.svg

目次

[編集] 戻り値

最初の要素へのリバースイテレータ。

[編集] 計算量

定数。

[編集] 注記

返される逆イテレータの基底イテレータは、endイテレータです。したがって、返されるイテレータは、endイテレータが無効になった時点で無効になります。

libc++はC++98モードにcrbegin()をバックポートしています。

[編集]

#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 メンバ関数) [編集]
コンテナまたは配列の先頭を指す逆順イテレータを返す
(function template) [編集]
English 日本語 中文(简体) 中文(繁體)