最終更新日時(UTC):
が更新

履歴 編集

function
<map>

std::map::crend(C++11)

const_reverse_iterator crend() const noexcept;

概要

map コンテナの先頭要素の前(これは反転シーケンスの末尾にあたる)を指す逆イテレータを取得する。 crend()begin() と同じ要素を指すわけではなく、その前の要素を指すことに注意。

戻り値

反転シーケンスの終端を指す逆イテレータ。 const_reverse_iterator はメンバ型である。map クラステンプレートにおいて、これらは逆双方向イテレータであり、reverse_iterator<const_iterator> と定義される。

#include <iostream>
#include <map>

int main()
{
  std::map<int, char> m;
  m.insert(std::make_pair(5, 'e'));
  m.insert(std::make_pair(2, 'b'));
  m.insert(std::make_pair(4, 'd'));
  m.insert(std::make_pair(1, 'a'));
  m.insert(std::make_pair(1, 'a'));

  std::map<int,char>::const_reverse_iterator i = m.crbegin();
  for( ; i != m.crend() ; ++i )
    std::cout << i->first << " " << i->second << std::endl;

  return 0;
}

出力

5 e
4 d
2 b
1 a

処理系

関連項目

名前 説明
map::begin 先頭を指すイテレータを取得する
map::end 末尾の次を指すイテレータを取得する
map::cbegin 先頭を指すconstイテレータを取得する
map::cend 末尾の次を指すconstイテレータを取得する
map::rbegin 末尾を指す逆イテレータを取得する
map::rend 先頭の前を指す逆イテレータを取得する
map::crbegin 末尾を指す逆constイテレータを取得する