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 版本都不會修改容器)。
呼叫該函式不訪問任何包含的元素,但返回的迭代器可用於訪問或修改元素。併發訪問或修改不同元素是安全的。
異常安全
無異常保證:此成員函式從不丟擲異常。
還可以保證返回的迭代器的複製構造或賦值永遠不會引發異常。