list::push_front

Fügt ein Element am Anfang einer Liste hinzu.

void push_front(
   const Type& _Val
);
void push_front(
   Type&& _Val
); 

Parameter

Parameter

Description

_Val

Das Element hinzugefügt an den Anfang der Liste.

Hinweise

Wenn eine Ausnahme ausgelöst wird, wird die Liste unverändert lassen und die Ausnahme wird erneut ausgelöst.

Beispiel

// list_push_front.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
#include <string>

int main( ) 
{
   using namespace std;
   list <int> c1;
   
   c1.push_front( 1 );
   if ( c1.size( ) != 0 )
      cout << "First element: " << c1.front( ) << endl;

   c1.push_front( 2 );
   if ( c1.size( ) != 0 )
      cout << "New first element: " << c1.front( ) << endl;

// move initialize a list of strings
   list <string> c2;
   string str("a");

   c2.push_front( move( str ) );
   cout << "Moved first element: " << c2.front( ) << endl;
}
  

Anforderungen

Header: <list>

Namespace: std

Siehe auch

Referenz

list Class

Standardvorlagenbibliothek