Freigeben über


list::list

Erstellt eine Liste einer bestimmten Größe oder mit Elementen eines bestimmten Werts oder mit einer bestimmten Belegungsfunktion oder als Kopie von alle oder nur einen Teil einer anderen Liste.

list( );
explicit list(
   const Allocator& _Al
);
explicit list(
   size_type _Count
);
list(
   size_type _Count,
   const Type& _Val
);
list(
   size_type _Count,
   const Type& _Val,
   const Allocator& _Al
);
list(
   const list& _Right
);
template<class InputIterator>
   list(
      InputIterator _First,
      InputIterator _Last
   );
template<class InputIterator >
   list(
      InputIterator _First,
      InputIterator _Last,
      const Allocator& _Al
   );
list(
   list&& _Right
);

Parameter

Parameter

Description

_Al

Die allocator-Klasse, die mit diesem Objekt verwendet werden soll.

_Count

Die Anzahl der Elemente in der Liste erstellt.

_Val

Der Wert der Elemente in der Liste erstellt.

_Right

Die Liste, in der die erstellte Liste, eine Kopie sein soll.

_First

Die Position des ersten Elements im Bereich von Elementen kopiert werden.

_Last

Die Position des ersten Elements über den Bereich von Elementen hinaus kopiert werden.

Hinweise

Alle Konstruktoren speichern ein allocator-Objekt (_Al) und initialisieren die Liste.

get_allocator gibt eine Kopie des allocator-Objekts zurück, das verwendet wird, um eine Liste zu erstellen.

Die ersten beiden Konstruktoren geben eine leere ursprüngliche Liste, die zweite, den zu verwendenden Belegungsfunktionstyp (_Al) angibt.

Der dritte Konstruktor gibt eine Wiederholung einer angegebenen Anzahl (_Count) Elemente des Standardwerts für Klasse Typ an.

Die vierten und fünften Konstruktoren geben eine Wiederholung von (_Count) Elementen des Werts _Val an.

Der 6. Konstruktor wird eine Kopie der Liste _Right an.

Die folgenden zwei Konstruktoren kopieren den Bereich [_First, _Last) einer Liste.

Der letzte Konstruktor verschiebt die Liste _Right.

Keine der Konstruktoren führen alle Zwischenneuzuordnungen aus.

Beispiel

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

int main( ) 
{
   using namespace std;
   list <int>::iterator c1_Iter, c2_Iter, c3_Iter, c4_Iter, c5_Iter, c6_Iter, c7_Iter;

   // Create an empty list c0
   list <int> c0;

   // Create a list c1 with 3 elements of default value 0
   list <int> c1( 3 );

   // Create a list c2 with 5 elements of value 2
   list <int> c2( 5, 2 );

   // Create a list c3 with 3 elements of value 1 and with the 
   // allocator of list c2
   list <int> c3( 3, 1, c2.get_allocator( ) );

   // Create a copy, list c4, of list c2
   list <int> c4(c2);

   // Create a list c5 by copying the range c4[_First, _Last)
   c4_Iter = c4.begin( );
   c4_Iter++;
   c4_Iter++;
   list <int> c5( c4.begin( ), c4_Iter );

   // Create a list c6 by copying the range c4[_First, _Last) and with 
   // the allocator of list c2
   c4_Iter = c4.begin( );
   c4_Iter++;
   c4_Iter++;
   c4_Iter++;
   list <int> c6( c4.begin( ), c4_Iter, c2.get_allocator( ) );

   cout << "c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
   
   cout << "c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;

   cout << "c3 =";
   for ( c3_Iter = c3.begin( ); c3_Iter != c3.end( ); c3_Iter++ )
      cout << " " << *c3_Iter;
   cout << endl;

   cout << "c4 =";
   for ( c4_Iter = c4.begin( ); c4_Iter != c4.end( ); c4_Iter++ )
      cout << " " << *c4_Iter;
   cout << endl;

   cout << "c5 =";
   for ( c5_Iter = c5.begin( ); c5_Iter != c5.end( ); c5_Iter++ )
      cout << " " << *c5_Iter;
   cout << endl;

   cout << "c6 =";
   for ( c6_Iter = c6.begin( ); c6_Iter != c6.end( ); c6_Iter++ )
      cout << " " << *c6_Iter;
   cout << endl;

   // Move list c6 to list c7
   list <int> c7( move(c6) );
   list <int>::iterator c7_Iter,
   
   cout << "c7 =" ;
   for ( c7_Iter = c7.begin( ) ; c7_Iter != c7.end( ) ; c7_Iter++ )
      cout << " " << *c7_Iter;
   cout << endl;
}
  

Anforderungen

Header: <list>

Namespace: std

Siehe auch

Referenz

list Class

list::list (STL Samples)

Standardvorlagenbibliothek