Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


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 below example, the forward_list::pop_front function is used to delete first elements of the forward_list called f_list.

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

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

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

  return 0;
}

The output of the above code will be:

f_list contains: 300 400 500 600

❮ C++ <forward_list> Library