Namespaces
Variants

std::flat_set<Key,Compare,KeyContainer>:: begin, std::flat_set<Key,Compare,KeyContainer>:: 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

目录

返回值

指向第一个元素的迭代器。

复杂度

常量。

注释

由于 iterator const_iterator 都是常量迭代器(实际上可能是相同类型),因此无法通过这些成员函数返回的迭代器来修改容器中的元素。

示例

#include <algorithm>
#include <flat_set>
#include <iostream>
int main()
{
    std::flat_set<int> set{3, 1, 4, 1, 5, 9, 2, 6, 5};
    std::for_each(set.cbegin(), set.cend(), [](int x)
    {
        std::cout << x << ' ';
    });
    std::cout << '\n';
}

输出:

1 2 3 4 5 6 9

参见

返回指向末尾的迭代器
(公开成员函数)
(C++11) (C++14)
返回指向容器或数组起始位置的迭代器
(函数模板)