public member type
<forward_list>
iterator begin() noexcept;const_iterator begin() const noexcept;
Return iterator to beginning
Returns an iterator pointing to the first element in the forward_list container.
Notice that, unlike member forward_list::front, which returns a reference to the first element, this function returns a forward iterator pointing to it.
If the container is empty, the returned iterator value shall not be dereferenced.
返回值
An iterator to the beginning of the sequence container.
如果 forward_list 对象是 const 限定的,则函数返回一个const_iterator。否则,它返回一个iterator.
成员类型iterator和const_iteratorare forward iterator types (pointing to an element and to a const element, respectively).
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// forward_list::begin example
#include <iostream>
#include <forward_list>
int main ()
{
std::forward_list<int> mylist = { 34, 77, 16, 2 };
std::cout << "mylist contains:";
for ( auto it = mylist.begin(); it != mylist.end(); ++it )
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
|
输出
mylist contains: 34 77 16 2
|
数据竞争
访问容器(const 和非 const 版本都不会修改容器)。
调用该函数不访问任何包含的元素,但返回的迭代器可用于访问或修改元素。并发访问或修改不同元素是安全的。
异常安全
无异常保证:此成员函数从不抛出异常。
还可以保证返回的迭代器的复制构造或赋值永远不会引发异常。