Freigeben über


list::push_front

Fügt am Anfang einer Liste ein Element hinzu.

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

Parameter

Parameter

Beschreibung

_Val

Das am Anfang der Liste hinzugefügte Element.

Hinweise

Wenn eine Ausnahme ausgelöst wird, bleibt die Liste unverändert, 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-Klasse

Standardvorlagenbibliothek