public member function
<forward_list>

std::forward_list::pop_front

void pop_front();
刪除第一個元素
移除forward_list容器中的第一個元素,使其大小減一。

此函式會銷燬被移除的元素。

引數



返回值



示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// forward_list::pop_front
#include <iostream>
#include <forward_list>

int main ()
{
  std::forward_list<int> mylist = {10, 20, 30, 40};

  std::cout << "Popping out the elements in mylist:";
  while (!mylist.empty())
  {
    std::cout << ' ' << mylist.front();
    mylist.pop_front();
  }

  std::cout << '\n';

  return 0;
}
輸出
Popping out the elements in mylist: 10 20 30 40


複雜度

常量。

迭代器有效性

指向被函式移除的元素的迭代器、指標和引用將失效。
所有其他迭代器、指標和引用將保持有效。

資料競爭

容器被修改。
第一個元素被修改。併發訪問或修改其他元素是安全的。

異常安全

如果容器不是empty的,該函式永遠不會丟擲異常(無異常保證)。
否則,將導致未定義行為

另見