std::
multiset::begin
公众成员函数 <set>
C++98 |
iterator begin();
const_iterator begin() const; |
C++11 |
iterator begin() noexcept;
const_iterator begin() const noexcept; |
返回迭代器的起始位置
返回指向multiset容器中第一个元素的迭代器。
因为multiset容器始终保持其元素的顺序,begin指向首先遵循容器排序标准的元素。
如果容器为空,则不能对返回的迭代器值进行解引用.
☲ 参数
-
none
☉ 返回值
指向容器中第一个元素的迭代器。
如果multiset对象是const限定的,则该函数返回const_iterator对象。否则,它将返回一个iterator。
成员类型iterator和const_iterator是指向元素的双向迭代器类型。
☣ 示例
// multiset::begin/end
#include <iostream>
#include <set>
int main ()
{
int myints[] = {42,71,71,71,12};
std::multiset<int> mymultiset (myints,myints+5);
std::multiset<int>::iterator it;
std::cout << "mymultiset contains:";
for (std::multiset<int>::iterator it=mymultiset.begin(); it!=mymultiset.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
} |
输出:
mymultiset contains: 12 42 71 71 71
✥ 复杂度
常量
☣ 迭代器的有效性
不变
⇄ 数据竞争
容器被访问(const和非const版本都不会修改容器)。
并发地访问multiset的元素是安全的。
☂ 异常安全性
No-throw保证:这个成员函数从不抛出异常。
返回迭代器的复制构造或赋值也保证不会引发抛出。
🍄 另请参阅
multiset::rbegin |
返回指向容器中最后一个元素的反向迭代器(公众成员函数) |
multiset::rend |
返回指向multiset开始元素之前的理论元素的反向迭代器(公众成员函数) |
multiset::end |
返回一个指向容器末尾元素的下一个元素的迭代器(公众成员函数) |