Skip to content

Latest commit

 

History

History
74 lines (54 loc) · 1.88 KB

File metadata and controls

74 lines (54 loc) · 1.88 KB

cend

  • vector[meta header]
  • std[meta namespace]
  • vector[meta class]
  • function[meta id-type]
  • cpp11[meta cpp]
const_iterator cend() const noexcept;           // (1) C++11
constexpr const_iterator cend() const noexcept; // (1) C++20

概要

末尾要素の次を指す読み取り専用イテレータを取得する。

end()は非constvectorオブジェクトに対してiteratorを返し、constvectorオブジェクトに対してはconst_iteratorを返すが、cend()const_iteratorを返すバージョンのみが提供されている。

アルゴリズムにイテレータの組を渡す際、アルゴリズム内でデータの書き換えが起こらないというユーザーの意図を示す場合などに有用である。

戻り値

末尾要素の次を指す読み取り専用イテレータ

例外

投げない

計算量

定数時間

備考

  • この関数によって返されるイテレータは、*thisが保持するいずれの要素も参照しない。その指す先は、不正な範囲となるだろう

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
  std::vector<int> v = {1, 2, 3};

  // このアルゴリズム内ではvの書き換えを決して行わない
  std::for_each(v.cbegin(), v.cend(), [](const int& x) {
    std::cout << x << std::endl;
  });
}
  • cend()[color ff0000]
  • v.cbegin()[link cbegin.md]

出力

1
2
3

バージョン

言語

  • C++11

処理系

  • Clang: ??
  • GCC: 4.7.0 [mark verified]
  • ICC: ??
  • Visual C++: 2010 [mark verified], 2012 [mark verified], 2013 [mark verified]

参照