Namespaces
Variants

std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>:: begin, std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>:: cbegin

From cppreference.net

iterator begin ( ) noexcept ;
(1) (C++23부터)
(C++26부터 constexpr)
const_iterator begin ( ) const noexcept ;
(2) (C++23부터)
(C++26부터 constexpr)
const_iterator cbegin ( ) const noexcept ;
(3) (C++23부터)
(C++26부터 constexpr)

* this 의 첫 번째 요소에 대한 반복자를 반환합니다.

만약 * this 가 비어 있다면, 반환된 반복자는 end() 와 같을 것입니다.

range-begin-end.svg

목차

반환값

첫 번째 요소에 대한 반복자.

복잡도

상수.

예제

#include <iostream>
#include <flat_map>
int main()
{
    std::flat_map<int, double> map{{4, 4.13}, {9, 9.24}, {1, 1.09}};
    for (auto it = map.cbegin(); it != map.cend(); ++it)
        std::cout << '[' << it->first << "] = " << it->second << '\n';
    // std::map의 양방향 반복자와 달리, std::flat_map 반복자는
    // 임의 접근(random-access)이 가능하므로 operator[]와 함께 사용할 수 있습니다:
    auto it = map.cbegin();
    assert(it[0] == map[1]);
    assert(it[1] == map[4]);
    assert(it[2] == map[9]);
}

출력:

[1] = 1.09
[4] = 4.13
[9] = 9.24

참고 항목

끝을 가리키는 반복자를 반환합니다
(public member function)
(C++11) (C++14)
컨테이너나 배열의 시작을 가리키는 반복자를 반환합니다
(function template)