C++ Standard Library C++ STL Library

C++ <forward_list> - pop_front() Function



The C++ forward_list::pop_front function is used to delete the first element of the forward_list. Every deletion of element results into reducing the container size by one unless the forward_list is empty.

Syntax

void pop_front();

Parameters

No parameter is required.

Return Value

None.

Time Complexity

Constant i.e, Θ(1)

Example:

In the example below, the forward_list::pop_front function is used to delete first elements of the forward_list called flist.

#include <iostream>
#include <forward_list>
using namespace std;
 
int main (){
  forward_list<int> flist{100, 200, 300, 400, 500, 600};
  forward_list<int>::iterator it;

  //deletes first element of the flist
  flist.pop_front();
  //deletes next first element of the flist
  flist.pop_front();

  cout<<"flist contains:";
  for(it = flist.begin(); it != flist.end(); ++it)
    cout<<" "<<*it;

  return 0;
}

The output of the above code will be:

flist contains: 300 400 500 600

❮ C++ <forward_list> Library