C ++ Forward_list Library - funzione pop_front ()

Descrizione

La funzione C ++ std::forward_list::pop_front() rimuove il primo elemento da forward_list e riduce di uno la dimensione di forward_list.

Dichiarazione

Di seguito è riportata la dichiarazione per la funzione std :: forward_list :: pop_front () nell'intestazione std :: forward_list.

C ++ 11

void pop_front();

Parametri

Nessuna

Valore di ritorno

Nessuna

Eccezioni

Questa funzione membro non genera mai eccezioni. La chiamata di questa funzione su forward_list vuota causa un comportamento indefinito.

Complessità temporale

Costante cioè O (1)

Esempio

L'esempio seguente mostra l'utilizzo della funzione std :: forward_list :: pop_front ().

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {

   forward_list<int> fl = {1, 2, 3, 4, 5};

   cout << "List contains following elements before" 
      " pop_front operation" << endl;

   for (auto it = fl.begin(); it != fl.end(); ++it)
      cout << *it << endl;

   fl.pop_front();
   fl.pop_front();

   cout << "List contains following elements after" 
      " pop_front operation" << endl;

   for (auto it = fl.begin(); it != fl.end(); ++it)
      cout << *it << endl;

   return 0;
}

Compiliamo ed eseguiamo il programma sopra, questo produrrà il seguente risultato:

List contains following elements before pop_front operation
1
2
3
4
5
List contains following elements after pop_front operation
3
4
5