命名空间
变体
操作

std::set<Key,Compare,Allocator>::end, std::set<Key,Compare,Allocator>::cend

来自 cppreference.cn
< cpp‎ | container‎ | set
 
 
 
 
iterator end();
(1) (noexcept since C++11)
const_iterator end() const;
(2) (noexcept since C++11)
const_iterator cend() const noexcept;
(3) (since C++11)

返回指向 set 中最后一个元素之后元素的迭代器。

此元素充当占位符;尝试访问它会导致未定义行为。

range-begin-end.svg

内容

[编辑] 返回值

指向最后一个元素之后元素的迭代器。

[编辑] 复杂度

常数。

注解

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

libc++ 将 cend() 向后移植到 C++98 模式。

[编辑] 示例

#include <algorithm>
#include <iostream>
#include <set>
 
int main()
{
    std::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)
返回指向容器或数组末尾的迭代器
(函数模板) [编辑]