- 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