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のイテレータは
    // ランダムアクセス可能なので、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

関連項目

終端を指すイテレータを返す
(公開メンバ関数)
(C++11) (C++14)
コンテナまたは配列の先頭を指すイテレータを返す
(関数テンプレート)