Skip to content

Latest commit

 

History

History
61 lines (44 loc) · 1.21 KB

begin.md

File metadata and controls

61 lines (44 loc) · 1.21 KB

begin

  • vector[meta header]
  • std[meta namespace]
  • vector[meta class]
  • function[meta id-type]
iterator begin();                      // (1) C++03
iterator begin() noexcept;             // (1) C++11
constexpr iterator begin() noexcept;   // (1) C++20

const_iterator begin() const;                    // (2) C++03
const_iterator begin() const noexcept;           // (2) C++11
constexpr const_iterator begin() const noexcept; // (2) C++20

概要

先頭要素を指すイテレータを取得する。

戻り値

constな文脈ではiterator型で先頭要素へのイテレータを返し、

constな文脈ではconst_iterator型で先頭要素へのイテレータを返す。

例外

投げない

計算量

定数時間

#include <iostream>
#include <vector>

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

  decltype(v)::iterator i = v.begin();
  decltype(v)::const_iterator ci = cv.begin();

  std::cout << *i << std::endl;
  std::cout << *ci << std::endl;
}
  • begin()[color ff0000]

出力

1
1

参照