Aracılığıyla paylaş


list Sınıfı

C++ Standart Kitaplık liste sınıfı, öğelerini doğrusal bir düzende tutan ve sıra içindeki herhangi bir konumda verimli ekleme ve silme işlemlerine olanak sağlayan bir dizi kapsayıcıları sınıf şablonudur. Dizisi, her biri bir türe Typeüye içeren çift yönlü bağlantılı öğe listesi olarak depolanır.

Sözdizimi

template <class Type, class Allocator= allocator<Type>>
class list

Parametreler

Type
Listede depolanacak öğe veri türü.

Allocator
Listenin bellek ayırması ve serbest bırakılması hakkındaki ayrıntıları kapsülleyen depolanmış ayırıcı nesnesini temsil eden tür. Bu bağımsız değişken isteğe bağlıdır ve varsayılan değerdir allocator<Type>.

Açıklamalar

Kapsayıcı türünün seçimi genelde uygulamanın gerektirdiği arama ve ekleme türüne dayalı olmalıdır. Vektörler, herhangi bir öğeye rastgele erişim premium olduğunda ve öğelerin eklenmesi veya silinmesi yalnızca bir dizinin sonunda gerekli olduğunda bir diziyi yönetmek için tercih edilen kapsayıcı olmalıdır. Rastgele erişim gerektiğinde ve bir dizinin hem başında hem de sonunda eklemeler ve silmeler premium olduğunda sınıf deque kapsayıcısının performansı üstündür.

Liste üyesi işlevleri merge, reverse, unique, removeve remove_if liste nesneleri üzerinde işlem için iyileştirilmiştir ve genel karşılıklarına yüksek performanslı bir alternatif sunar.

Bir üye işlevinin listenin öğelerini eklemesi veya silmesi gerektiğinde liste yeniden konumlandırma gerçekleşir. Bu gibi durumlarda, yalnızca denetlenen dizinin silinmiş bölümlerini işaret eden yineleyiciler veya başvurular geçersiz hale gelir.

Sınıf şablonu listesini ve birkaç destekleyici şablonu tanımlamak container için C++ Standart Kitaplığı standart üst bilgisini <list> ekleyin.

Üyeler

Oluşturucular

Ad Tanım
list Belirli bir boyutta veya belirli bir değerin öğeleriyle ya da belirli bir veya başka bir allocator listenin kopyası olarak bir liste oluşturur.

Tür tanımları

Ad Tanım
allocator_type Liste nesnesinin sınıfını allocator temsil eden bir tür.
const_iterator Listedeki bir öğeyi okuyabilen çift yönlü bir yineleyici sağlayan tür const .
const_pointer Listedeki bir öğeye const işaretçi sağlayan tür.
const_reference Okuma ve işlem gerçekleştirme const amacıyla listede depolanan bir const öğeye başvuru sağlayan tür.
const_reverse_iterator Listedeki herhangi const bir öğeyi okuyabilen çift yönlü bir yineleyici sağlayan tür.
difference_type Aynı listedeki öğelere başvuran iki yineleyici arasındaki farkı sağlayan bir tür.
iterator Listedeki herhangi bir öğeyi okuyabilen veya değiştirebilen çift yönlü bir yineleyici sağlayan tür.
pointer Listedeki bir öğeye işaretçi sağlayan tür.
reference Okuma ve işlem gerçekleştirme const amacıyla listede depolanan bir const öğeye başvuru sağlayan tür.
reverse_iterator Ters çevrilmiş listedeki bir öğeyi okuyabilen veya değiştirebilen çift yönlü bir yineleyici sağlayan tür.
size_type Listedeki öğe sayısını sayan bir tür.
value_type Listede depolanan veri türünü temsil eden bir tür.

İşlevler

Ad Tanım
assign Listedeki öğeleri siler ve yeni bir öğe kümesini hedef listeye kopyalar.
back Listenin son öğesine başvuru döndürür.
begin Listedeki ilk öğeyi ele alan bir yineleyici döndürür.
cbegin Listedeki ilk öğeyi ele alan bir sabit yineleyici döndürür.
cend Listedeki son öğenin başarılı olduğu konumu ele alan bir sabit yineleyici döndürür.
clear Listenin tüm öğelerini siler.
crbegin Ters çevrilmiş listedeki ilk öğeyi ele alan bir sabit yineleyici döndürür.
crend Ters çevrilmiş listedeki son öğenin başarılı olduğu konumu ele alan bir sabit yineleyici döndürür.
emplace Belirtilen konumdaki bir listeye yerinde inşa edilmiş bir öğe ekler.
emplace_back Listenin sonuna yerinde bir öğe ekler.
emplace_front Listenin başına yerinde bir öğe ekler.
empty Listenin boş olup olmadığını sınar.
end Listedeki son öğeden sonra gelen konumu ele alan bir yineleyici döndürür.
erase Listedeki bir öğeyi veya öğe aralığını belirtilen konumlardan kaldırır.
front Listedeki ilk öğeye başvuru döndürür.
get_allocator Liste oluşturmak için kullanılan nesnenin allocator bir kopyasını döndürür.
insert Bir öğeyi veya bir dizi öğeyi ya da öğe aralığını belirtilen konumdaki bir listeye ekler.
max_size Listenin uzunluk üst sınırını döndürür.
merge Öğeleri bağımsız değişken listesinden kaldırır, hedef listeye ekler ve yeni, birleşik öğe kümesini artan düzende veya belirtilen başka bir sırada sıralar.
pop_back Listenin sonundaki öğesini siler.
pop_front Listenin başındaki öğesini siler.
push_back Listenin sonuna öğe ekler.
push_front Listenin başına öğe ekler.
rbegin Ters çevrilmiş listedeki ilk öğeyi ele alan bir yineleyici döndürür.
remove Listede belirtilen değerle eşleşen öğeleri siler.
remove_if Belirtilen koşulun karşılandığı listeden öğeleri siler.
rend Ters çevrilmiş listedeki son öğeden sonra gelen konumu ele alan bir yineleyici döndürür.
resize Liste için yeni bir boyut belirtir.
reverse Öğelerin bir listede yer alma sırasını tersine çevirir.
size Listedeki öğelerin sayısını döndürür.
sort Listenin öğelerini artan düzende veya başka bir sipariş ilişkisine göre düzenler.
splice Öğeleri bağımsız değişken listesinden kaldırır ve hedef listeye ekler.
swap İki liste öğelerini değiştirir.
unique Listeden başka bir ikili koşula uyan bitişik yinelenen öğeleri veya bitişik öğeleri kaldırır.

İşleçler

Ad Tanım
operator= Listenin öğelerini başka bir listenin kopyasıyla değiştirir.

Gereksinimler

Üst Bilgi: <list>

allocator_type

Liste nesnesinin ayırıcı sınıfını temsil eden bir tür.

typedef Allocator allocator_type;

Açıklamalar

allocator_type , şablon parametresinin Allocatoreş anlamlısıdır.

Örnek

örneğine get_allocatorbakın.

assign

Listedeki öğeleri siler ve yeni bir öğe kümesini hedef listeye kopyalar.

void assign(
    size_type Count,
    const Type& Val);

void assign
    initializer_list<Type> IList);

template <class InputIterator>
void assign(
    InputIterator First,
    InputIterator Last);

Parametreler

First
Bağımsız değişken listesinden kopyalanacak öğe aralığındaki ilk öğenin konumu.

Last
bağımsız değişken listesinden kopyalanacak öğe aralığının hemen ötesindeki ilk öğenin konumu.

Count
Listeye eklenen öğenin kopya sayısı.

Val
Listeye eklenen öğenin değeri.

IList
Eklenecek öğeleri içeren initializer_list.

Açıklamalar

Hedef listedeki mevcut öğeleri sildikten sonra, belirtilen öğe aralığını özgün listeden veya başka bir listeden hedef listeye atar veya belirtilen değerin yeni bir öğesinin kopyalarını hedef listeye ekler

Örnek

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

int main()
{
    using namespace std;
    list<int> c1, c2;
    list<int>::const_iterator cIter;

    c1.push_back(10);
    c1.push_back(20);
    c1.push_back(30);
    c2.push_back(40);
    c2.push_back(50);
    c2.push_back(60);

    cout << "c1 =";
    for (auto c : c1)
        cout << " " << c;
    cout << endl;

    c1.assign(++c2.begin(), c2.end());
    cout << "c1 =";
    for (auto c : c1)
        cout << " " << c;
    cout << endl;

    c1.assign(7, 4);
    cout << "c1 =";
    for (auto c : c1)
        cout << " " << c;
    cout << endl;

    c1.assign({ 10, 20, 30, 40 });
    cout << "c1 =";
    for (auto c : c1)
        cout << " " << c;
    cout << endl;
}
c1 = 10 20 30c1 = 50 60c1 = 4 4 4 4 4 4 4c1 = 10 20 30 40

back

Listenin son öğesine başvuru döndürür.

reference back();

const_reference back() const;

İade Değeri

Listenin son öğesi. Liste boşsa, dönüş değeri tanımlanmamış olur.

Açıklamalar

dönüş değeri back bir const_referenceöğesine atanmışsa, liste nesnesi değiştirilemez. değerinin dönüş değeri back bir referenceöğesine atanmışsa, liste nesnesi değiştirilebilir.

1 veya 2 olarak tanımlanan kullanılarak _ITERATOR_DEBUG_LEVEL derlendiğinde, boş bir listedeki bir öğeye erişmeye çalışırsanız bir çalışma zamanı hatası oluşur. Daha fazla bilgi için bkz . İşaretli Yineleyiciler .

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );
   c1.push_back( 11 );

   int& i = c1.back( );
   const int& ii = c1.front( );

   cout << "The last integer of c1 is " << i << endl;
   i--;
   cout << "The next-to-last integer of c1 is " << ii << endl;
}
The last integer of c1 is 11
The next-to-last integer of c1 is 10

begin

Listedeki ilk öğeyi ele alan bir yineleyici döndürür.

const_iterator begin() const;

iterator begin();

İade Değeri

Listedeki ilk öğeyi veya boş bir listenin başarılı olduğu konumu ele alan çift yönlü yineleyici.

Açıklamalar

değerinin dönüş değeri begin bir const_iteratoröğesine atanmışsa, liste nesnesindeki öğeler değiştirilemez. dönüş değeri begin bir iteratoröğesine atanmışsa, liste nesnesindeki öğeler değiştirilebilir.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter;
   list <int>::const_iterator c1_cIter;

   c1.push_back( 1 );
   c1.push_back( 2 );

   c1_Iter = c1.begin( );
   cout << "The first element of c1 is " << *c1_Iter << endl;

*c1_Iter = 20;
   c1_Iter = c1.begin( );
   cout << "The first element of c1 is now " << *c1_Iter << endl;

   // The following line would be an error because iterator is const
   // *c1_cIter = 200;
}
The first element of c1 is 1
The first element of c1 is now 20

cbegin

Aralıktaki ilk öğeyi ele alan bir const yineleyici döndürür.

const_iterator cbegin() const;

İade Değeri

Aralığın const ilk öğesini veya boş aralığın sonunun hemen ötesindeki konumu gösteren çift yönlü erişim yineleyicisi (boş aralık için). cbegin() == cend()

Açıklamalar

değerinin cbegindönüş değeriyle, aralıktaki öğeler değiştirilemez.

Dönüş değerinin olduğunu const_iteratorgaranti etmek için üye işlevinin begin() yerine bu üye işlevini kullanabilirsiniz. Genellikle, aşağıdaki örnekte gösterildiği gibi tür kesinti anahtar sözcüğüyle auto birlikte kullanılır. Örnekte, ve cbegin()destekleyen herhangi bir türde begin() değiştirilebilir (non- const) kapsayıcısı olduğunu düşününContainer.

auto i1 = Container.begin();
// i1 is Container<T>::iterator
auto i2 = Container.cbegin();

// i2 is Container<T>::const_iterator

cend

Bir const aralıktaki son öğenin hemen ötesindeki konumu ele alan bir yineleyici döndürür.

const_iterator cend() const;

İade Değeri

Aralığın const sonunun hemen ötesine işaret eden çift yönlü erişim yineleyicisi.

Açıklamalar

cend bir yineleyicinin aralığının sonunu geçip geçmediğini test etmek için kullanılır.

Dönüş değerinin olduğunu const_iteratorgaranti etmek için üye işlevinin end() yerine bu üye işlevini kullanabilirsiniz. Genellikle, aşağıdaki örnekte gösterildiği gibi tür kesinti anahtar sözcüğüyle auto birlikte kullanılır. Örnekte, ve cend()destekleyen herhangi bir türde end() değiştirilebilir (non- const) kapsayıcısı olduğunu düşününContainer.

auto i1 = Container.end();
// i1 is Container<T>::iterator
auto i2 = Container.cend();

// i2 is Container<T>::const_iterator

tarafından cend döndürülen değer başvurulmamalıdır.

Temizleyin

Listenin tüm öğelerini siler.

void clear();

Örnek

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

int main() {
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   cout << "The size of the list is initially " << c1.size( ) << endl;
   c1.clear( );
   cout << "The size of list after clearing is " << c1.size( ) << endl;
}
The size of the list is initially 3
The size of list after clearing is 0

const_iterator

Listedeki bir öğeyi okuyabilen çift yönlü bir yineleyici sağlayan tür const .

typedef implementation-defined const_iterator;

Açıklamalar

Bir öğenin değerini değiştirmek için bir tür const_iterator kullanılamaz.

Örnek

örneğine backbakın.

const_pointer

Listedeki bir const öğeye işaretçi sağlar.

typedef typename Allocator::const_pointer const_pointer;

Açıklamalar

Bir öğenin değerini değiştirmek için bir tür const_pointer kullanılamaz.

Çoğu durumda, iterator liste nesnesindeki öğelere erişmek için bir kullanılmalıdır.

const_reference

Okuma ve işlem gerçekleştirme const amacıyla listede depolanan bir const öğeye başvuru sağlayan tür.

typedef typename Allocator::const_reference const_reference;

Açıklamalar

Bir öğenin değerini değiştirmek için bir tür const_reference kullanılamaz.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );
   c1.push_back( 20 );

   const list <int> c2 = c1;
   const int &i = c2.front( );
   const int &j = c2.back( );
   cout << "The first element is " << i << endl;
   cout << "The second element is " << j << endl;

   // The following line would cause an error because c2 is const
   // c2.push_back( 30 );
}
The first element is 10
The second element is 20

const_reverse_iterator

Listedeki herhangi const bir öğeyi okuyabilen çift yönlü bir yineleyici sağlayan tür.

typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

Açıklamalar

Bir tür const_reverse_iterator bir öğenin değerini değiştiremez ve listede tersten yinelemek için kullanılır.

Örnek

örneğine rbeginbakın.

crbegin

Ters çevrilmiş listedeki ilk öğeyi ele alan bir sabit yineleyici döndürür.

const_reverse_iterator rbegin() const;

İade Değeri

Ters çevrilmiş listedeki ilk öğeyi ele alan (veya ters çevrilmeyen listlistedeki son öğeyi ele alan) sabit ters çift yönlü yineleyici.

Açıklamalar

crbegin , aynı bir ile kullanıldığı gibi list::begin ters çevrilmiş bir listlisteyle kullanılır.

değerinin crbegindönüş değeriyle liste nesnesi değiştirilemez. list::rbegin bir listede geriye doğru yinelemek için kullanılabilir.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::const_reverse_iterator c1_crIter;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );
   c1_crIter = c1.crbegin( );
   cout << "The last element in the list is " << *c1_crIter << "." << endl;
}
The last element in the list is 30.

crend

Ters çevrilmiş listedeki son öğenin başarılı olduğu konumu ele alan bir sabit yineleyici döndürür.

const_reverse_iterator rend() const;

İade Değeri

Ters çevrilmiş bir öğedeki son öğeyi (ters list çevrilmemiş listöğedeki ilk öğeden önce gelen konum) başarılı olan konumu ele alan en ters çift yönlü yineleyici.

Açıklamalar

crend , aynı bir ile kullanıldığı gibi list::end ters çevrilmiş bir listlisteyle kullanılır.

dönüş değeriyle crendlist nesne değiştirilemez.

crend , ters yineleyicinin sonuna listulaşıp ulaşmadığını test etmek için kullanılabilir.

tarafından crend döndürülen değer başvurulmamalıdır.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::const_reverse_iterator c1_crIter;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   c1_crIter = c1.crend( );
   c1_crIter --;  // Decrementing a reverse iterator moves it forward in
                 // the list (to point to the first element here)
   cout << "The first element in the list is: " << *c1_crIter << endl;
}
The first element in the list is: 10

difference_type

Yineleyiciler tarafından işaret edilen öğeler arasındaki bir aralıktaki bir listenin öğelerinin sayısını göstermek için kullanılabilecek imzalı bir tamsayı türü.

typedef typename Allocator::difference_type difference_type;

Açıklamalar

difference_type, kapsayıcının yineleyicileri çıkarılırken veya artırılırken döndürülen türdür. difference_type genellikle yineleyiciler first ile lastarasındaki [ first, last) aralığındaki öğe sayısını temsil etmek için first kullanılır; öğesinin işaret ettiği öğeyi ve öğesinin işaret lastettiği öğeyi dahil etmek için değil, öğesine kadar olan öğe aralığını içerir.

Küme gibi geri alınabilir kapsayıcılar tarafından desteklenen çift yönlü yineleyiciler sınıfını içeren bir giriş yineleyicisinin gereksinimlerini karşılayan tüm yineleyiciler için kullanılabilir olsa difference_type da, yineleyiciler arasındaki çıkarmanın yalnızca Sınıf gibi vector rastgele erişimli bir kapsayıcı tarafından sağlanan rastgele erişim yineleyicileri tarafından desteklendiğini unutmayın.

Örnek

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

int main( )
{
   using namespace std;

   list <int> c1;
   list <int>::iterator   c1_Iter, c2_Iter;

   c1.push_back( 30 );
   c1.push_back( 20 );
   c1.push_back( 30 );
   c1.push_back( 10 );
   c1.push_back( 30 );
   c1.push_back( 20 );

   c1_Iter = c1.begin( );
   c2_Iter = c1.end( );

    list <int>::difference_type df_typ1, df_typ2, df_typ3;

   df_typ1 = count( c1_Iter, c2_Iter, 10 );
   df_typ2 = count( c1_Iter, c2_Iter, 20 );
   df_typ3 = count( c1_Iter, c2_Iter, 30 );
   cout << "The number '10' is in c1 collection " << df_typ1 << " times.\n";
   cout << "The number '20' is in c1 collection " << df_typ2 << " times.\n";
   cout << "The number '30' is in c1 collection " << df_typ3 << " times.\n";
}
The number '10' is in c1 collection 1 times.
The number '20' is in c1 collection 2 times.
The number '30' is in c1 collection 3 times.

emplace

Belirtilen konumdaki bir listeye yerinde inşa edilmiş bir öğe ekler.

void emplace(iterator Where, Type&& val);

Parametreler

Where
Hedefteki list ilk öğenin eklendiği konum.

val
öğesinin sonuna listeklendi.

Açıklamalar

Bir özel durum oluşturulursa, list unaltered bırakılır ve özel durum yeniden oluşturulur.

Örnek

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

int main( )
{
   using namespace std;
   list <string> c2;
   string str("a");

   c2.emplace(c2.begin(), move( str ) );
   cout << "Moved first element: " << c2.back( ) << endl;
}
Moved first element: a

emplace_back

Listenin sonuna yerinde bir öğe ekler.

void emplace_back(Type&& val);

Parametreler

val
öğesinin sonuna listeklendi.

Açıklamalar

Bir özel durum oluşturulursa, list unaltered bırakılır ve özel durum yeniden oluşturulur.

Örnek

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

int main( )
{
   using namespace std;
   list <string> c2;
   string str("a");

   c2.emplace_back( move( str ) );
   cout << "Moved first element: " << c2.back( ) << endl;
}
Moved first element: a

emplace_front

Listenin başına yerinde bir öğe ekler.

void emplace_front(Type&& val);

Parametreler

val
öğesinin başına listeklenen öğesi.

Açıklamalar

Bir özel durum oluşturulursa, list unaltered bırakılır ve özel durum yeniden oluşturulur.

Örnek

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

int main( )
{
   using namespace std;
   list <string> c2;
   string str("a");

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

empty

Listenin boş olup olmadığını sınar.

bool empty() const;

İade Değeri

true liste boşsa; false liste boş değilse.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );
   if ( c1.empty( ) )
      cout << "The list is empty." << endl;
   else
      cout << "The list is not empty." << endl;
}
The list is not empty.

end

Listedeki son öğeden sonra gelen konumu ele alan bir yineleyici döndürür.

const_iterator end() const;
iterator end();

İade Değeri

Listedeki son öğenin başarılı olduğu konumu ele alan çift yönlü yineleyici. Liste boşsa, öğesini seçin list::end == list::begin.

Açıklamalar

end , yineleyicinin listesinin sonuna ulaşıp ulaşmadığını test etmek için kullanılır.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   c1_Iter = c1.end( );
   c1_Iter--;
   cout << "The last integer of c1 is " << *c1_Iter << endl;

   c1_Iter--;
*c1_Iter = 400;
   cout << "The new next-to-last integer of c1 is "
        << *c1_Iter << endl;

   // If a const iterator had been declared instead with the line:
   // list <int>::const_iterator c1_Iter;
   // an error would have resulted when inserting the 400

   cout << "The list is now:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
}
The last integer of c1 is 30
The new next-to-last integer of c1 is 400
The list is now: 10 400 30

erase

Listedeki bir öğeyi veya öğe aralığını belirtilen konumlardan kaldırır.

iterator erase(iterator Where);
iterator erase(iterator first, iterator last);

Parametreler

Where
Listeden kaldırılacak öğenin konumu.

first
Listeden kaldırılan ilk öğenin konumu.

last
Listeden kaldırılan son öğenin hemen ötesinde konum.

İade Değeri

Kaldırılan öğelerin ötesinde kalan ilk öğeyi belirten çift yönlü yineleyici veya böyle bir öğe yoksa listenin sonuna bir işaretçi.

Açıklamalar

Yeniden konumlandırma gerçekleşmez, bu nedenle yineleyiciler ve başvurular yalnızca silinen öğeler için geçersiz hale gelir.

erase hiçbir zaman özel durum oluşturmaz.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator Iter;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );
   c1.push_back( 40 );
   c1.push_back( 50 );
   cout << "The initial list is:";
   for ( Iter = c1.begin( ); Iter != c1.end( ); Iter++ )
      cout << " " << *Iter;
   cout << endl;

   c1.erase( c1.begin( ) );
   cout << "After erasing the first element, the list becomes:";
   for ( Iter = c1.begin( ); Iter != c1.end( ); Iter++ )
      cout << " " << *Iter;
   cout << endl;
   Iter = c1.begin( );
   Iter++;
   c1.erase( Iter, c1.end( ) );
   cout << "After erasing all elements but the first, the list becomes: ";
   for (Iter = c1.begin( ); Iter != c1.end( ); Iter++ )
      cout << " " << *Iter;
   cout << endl;
}
The initial list is: 10 20 30 40 50
After erasing the first element, the list becomes: 20 30 40 50
After erasing all elements but the first, the list becomes:  20

front

Listedeki ilk öğeye başvuru döndürür.

reference front();
const_reference front() const;

İade Değeri

Liste boşsa, dönüş tanımlanmamış olur.

Açıklamalar

dönüş değeri front bir const_referenceöğesine atanmışsa, liste nesnesi değiştirilemez. değerinin dönüş değeri front bir referenceöğesine atanmışsa, liste nesnesi değiştirilebilir.

1 veya 2 olarak tanımlanan kullanılarak _ITERATOR_DEBUG_LEVEL derlendiğinde, boş bir listedeki bir öğeye erişmeye çalışırsanız bir çalışma zamanı hatası oluşur. Daha fazla bilgi için bkz . İşaretli Yineleyiciler .

Örnek

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

int main() {
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );

   int& i = c1.front();
   const int& ii = c1.front();

   cout << "The first integer of c1 is " << i << endl;
   i++;
   cout << "The first integer of c1 is " << ii << endl;
}
The first integer of c1 is 10
The first integer of c1 is 11

get_allocator

Liste oluşturmak için kullanılan ayırıcı nesnesinin bir kopyasını döndürür.

Allocator get_allocator() const;

İade Değeri

Liste tarafından kullanılan ayırıcı.

Açıklamalar

Liste sınıfı için ayırıcılar, sınıfın depolamayı nasıl yöneteceğini belirtir. C++ Standart Kitaplığı kapsayıcı sınıfları ile sağlanan varsayılan ayırıcılar çoğu programlama gereksinimi için yeterlidir. Kendi ayırıcı sınıfınızı yazmak ve kullanmak gelişmiş bir C++ konusudur.

Örnek

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

int main( )
{
   using namespace std;
   // The following lines declare objects
   // that use the default allocator.
   list <int> c1;
   list <int, allocator<int> > c2 = list <int, allocator<int> >( allocator<int>( ) );

   // c3 will use the same allocator class as c1
   list <int> c3( c1.get_allocator( ) );

   list<int>::allocator_type xlst = c1.get_allocator( );
   // You can now call functions on the allocator class used by c1
}

insert

Bir öğeyi veya bir dizi öğeyi ya da öğe aralığını belirtilen konumdaki bir listeye ekler.

iterator insert(iterator Where, const Type& Val);
iterator insert(iterator Where, Type&& Val);

void insert(iterator Where, size_type Count, const Type& Val);
iterator insert(iterator Where, initializer_list<Type> IList);

template <class InputIterator>
void insert(iterator Where, InputIterator First, InputIterator Last);

Parametreler

Where
Hedef listedeki ilk öğenin eklendiği konum.

Val
Listeye eklenen öğenin değeri.

Count
Listeye eklenen öğe sayısı.

First
Kopyalanacak bağımsız değişken listesindeki öğe aralığındaki ilk öğenin konumu.

Last
Kopyalanacak bağımsız değişken listesindeki öğe aralığının ötesindeki ilk öğenin konumu.

İade Değeri

İlk iki ekleme işlevi, yeni öğenin listeye eklendiği konumu gösteren bir yineleyici döndürür.

Örnek

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

int main()
{
    using namespace std;
    list <int> c1, c2;
    list <int>::iterator Iter;

    c1.push_back(10);
    c1.push_back(20);
    c1.push_back(30);
    c2.push_back(40);
    c2.push_back(50);
    c2.push_back(60);

    cout << "c1 =";
    for (auto c : c1)
        cout << " " << c;
    cout << endl;

    Iter = c1.begin();
    Iter++;
    c1.insert(Iter, 100);
    cout << "c1 =";
    for (auto c : c1)
        cout << " " << c;
    cout << endl;

    Iter = c1.begin();
    Iter++;
    Iter++;
    c1.insert(Iter, 2, 200);

    cout << "c1 =";
    for(auto c : c1)
        cout << " " << c;
    cout << endl;

    c1.insert(++c1.begin(), c2.begin(), --c2.end());

    cout << "c1 =";
    for (auto c : c1)
        cout << " " << c;
    cout << endl;

    // initialize a list of strings by moving
    list < string > c3;
    string str("a");

    c3.insert(c3.begin(), move(str));
    cout << "Moved first element: " << c3.front() << endl;

    // Assign with an initializer_list
    list <int> c4{ {1, 2, 3, 4} };
    c4.insert(c4.begin(), { 5, 6, 7, 8 });

    cout << "c4 =";
    for (auto c : c4)
        cout << " " << c;
    cout << endl;
}

iterator

Listedeki herhangi bir öğeyi okuyabilen veya değiştirebilen çift yönlü bir yineleyici sağlayan tür.

typedef implementation-defined iterator;

Açıklamalar

Bir öğenin değerini değiştirmek için bir tür iterator kullanılabilir.

Örnek

örneğine beginbakın.

list

Belirli bir boyutun listesini veya belirli bir değerin öğeleriyle ya da belirli bir ayırıcıyla ya da başka bir listenin tümünün veya bir bölümünün kopyası olarak oluşturur.

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);
list(list&& Right);
list(initializer_list<Type> IList, const Allocator& Al);

template <class InputIterator>
list(InputIterator First, InputIterator Last);

template <class InputIterator>
list(InputIterator First, InputIterator Last, const Allocator& Al);

Parametreler

Al
Bu nesneyle kullanılacak kaynak ayırıcı sınıfı.

Count
Listede yer alan öğe sayısı.

Val
Listedeki öğelerin değeri.

Right
Oluşturulacak listenin kopya olacağı liste.

First
Kopyalanacak öğe aralığındaki ilk öğenin konumu.

Last
Kopyalanacak öğe aralığının ötesindeki ilk öğenin konumu.

IList
Kopyalanacak öğeleri içeren initializer_list.

Açıklamalar

Tüm oluşturucular bir ayırıcı nesnesi (Al) depolar ve listeyi başlatır.

get_allocator , liste oluşturmak için kullanılan ayırıcı nesnesinin bir kopyasını döndürür.

İlk iki oluşturucu boş bir başlangıç listesi, ikincisi kullanılacak ayırıcı türünü (Al) belirtir.

Üçüncü oluşturucu, sınıfı Typeiçin varsayılan değerde belirtilen sayıda (Count) öğe yinelemesini belirtir.

Dördüncü ve beşinci oluşturucular değerinin Val(Count) öğelerinin tekrarını belirtir.

Altıncı oluşturucu, listesinin Rightbir kopyasını belirtir.

Yedinci oluşturucu listesini Righttaşır.

Sekizinci oluşturucu, öğeleri belirtmek için bir initializer_list kullanır.

Sonraki iki oluşturucu bir liste aralığını [First, Last) kopyalar.

Oluşturucuların hiçbiri geçici yeniden yükleme gerçekleştirmez.

Örnek

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

int main()
{
    using namespace std;
    // 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)
    list <int>::iterator 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 (auto c : c1)
        cout << " " << c;
    cout << endl;

    cout << "c2 =";
    for (auto c : c2)
        cout << " " << c;
    cout << endl;

    cout << "c3 =";
    for (auto c : c3)
        cout << " " << c;
    cout << endl;

    cout << "c4 =";
    for (auto c : c4)
        cout << " " << c;
    cout << endl;

    cout << "c5 =";
    for (auto c : c5)
        cout << " " << c;
    cout << endl;

    cout << "c6 =";
    for (auto c : c6)
        cout << " " << c;
    cout << endl;

    // Move list c6 to list c7
    list <int> c7(move(c6));
    cout << "c7 =";
    for (auto c : c7)
        cout << " " << c;
    cout << endl;

    // Construct with initializer_list
    list<int> c8({ 1, 2, 3, 4 });
    cout << "c8 =";
    for (auto c : c8)
        cout << " " << c;
    cout << endl;
}
c1 = 0 0 0c2 = 2 2 2 2 2c3 = 1 1 1c4 = 2 2 2 2 2c5 = 2 2c6 = 2 2 2c7 = 2 2 2c8 = 1 2 3 4

max_size

Listenin uzunluk üst sınırını döndürür.

size_type max_size() const;

İade Değeri

Listenin mümkün olan en uzun uzunluğu.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::size_type i;

   i = c1.max_size( );
   cout << "Maximum possible length of the list is " << i << "." << endl;
}

merge

Öğeleri bağımsız değişken listesinden kaldırır, hedef listeye ekler ve yeni, birleşik öğe kümesini artan düzende veya belirtilen başka bir sırada sıralar.

void merge(list<Type, Allocator>& right);

template <class Traits>
void merge(list<Type, Allocator>& right, Traits comp);

Parametreler

right
Hedef listeyle birleştirilecek bağımsız değişken listesi.

comp
Hedef listenin öğelerini sıralamak için kullanılan karşılaştırma işleci.

Açıklamalar

Bağımsız değişken listesi right hedef listeyle birleştirilir.

Hem bağımsız değişken hem de hedef listeler, elde edilen sıranın sıralanması için aynı karşılaştırma ilişkisiyle sıralanmalıdır. İlk üye işlevinin varsayılan sırası artan düzendir. İkinci üye işlevi, sınıfının Traitskullanıcı tarafından belirtilen karşılaştırma işlemini comp uygular.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1, c2, c3;
   list <int>::iterator c1_Iter, c2_Iter, c3_Iter;

   c1.push_back( 3 );
   c1.push_back( 6 );
   c2.push_back( 2 );
   c2.push_back( 4 );
   c3.push_back( 5 );
   c3.push_back( 1 );

   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;

   c2.merge( c1 );  // Merge c1 into c2 in (default) ascending order
   c2.sort( greater<int>( ) );
   cout << "After merging c1 with c2 and sorting with >: 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;

   c2.merge( c3, greater<int>( ) );
   cout << "After merging c3 with c2 according to the '>' comparison relation: c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
}
c1 = 3 6
c2 = 2 4
After merging c1 with c2 and sorting with >: c2 = 6 4 3 2
c3 = 5 1
After merging c3 with c2 according to the '>' comparison relation: c2 = 6 5 4 3 2 1

operator=

Listenin öğelerini başka bir listenin kopyasıyla değiştirir.

list& operator=(const list& right);
list& operator=(list&& right);

Parametreler

right
içine list kopyalanan list.

Açıklamalar

bir listiçindeki mevcut öğeleri sildikten sonra işleci içindekileri right kopyalar veya içine listtaşır.

Örnek

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

int main( )
{
   using namespace std;
   list<int> v1, v2, v3;
   list<int>::iterator iter;

   v1.push_back(10);
   v1.push_back(20);
   v1.push_back(30);
   v1.push_back(40);
   v1.push_back(50);

   cout << "v1 = " ;
   for (iter = v1.begin(); iter != v1.end(); iter++)
      cout << *iter << " ";
   cout << endl;

   v2 = v1;
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << *iter << " ";
   cout << endl;

// move v1 into v2
   v2.clear();
   v2 = forward< list<int> >(v1);
   cout << "v2 = ";
   for (iter = v2.begin(); iter != v2.end(); iter++)
      cout << *iter << " ";
   cout << endl;
}

pointer

Listedeki bir öğeye işaretçi sağlar.

typedef typename Allocator::pointer pointer;

Açıklamalar

Bir öğenin değerini değiştirmek için bir tür pointer kullanılabilir.

Çoğu durumda, iterator liste nesnesindeki öğelere erişmek için bir kullanılmalıdır.

pop_back

Listenin sonundaki öğesini siler.

void pop_back();

Açıklamalar

Son öğe boş olmamalıdır. pop_back hiçbir zaman özel durum oluşturmaz.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;

   c1.push_back( 1 );
   c1.push_back( 2 );
   cout << "The first element is: " << c1.front( ) << endl;
   cout << "The last element is: " << c1.back( ) << endl;

   c1.pop_back( );
   cout << "After deleting the element at the end of the list, "
           "the last element is: " << c1.back( ) << endl;
}
The first element is: 1
The last element is: 2
After deleting the element at the end of the list, the last element is: 1

pop_front

Listenin başındaki öğesini siler.

void pop_front();

Açıklamalar

İlk öğe boş olmamalıdır. pop_front hiçbir zaman özel durum oluşturmaz.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;

   c1.push_back( 1 );
   c1.push_back( 2 );
   cout << "The first element is: " << c1.front( ) << endl;
   cout << "The second element is: " << c1.back( ) << endl;

   c1.pop_front( );
   cout << "After deleting the element at the beginning of the list, "
         "the first element is: " << c1.front( ) << endl;
}
The first element is: 1
The second element is: 2
After deleting the element at the beginning of the list, the first element is: 2

push_back

Listenin sonuna öğe ekler.

void push_back(const Type& val);
void push_back(Type&& val);

Parametreler

val
listenin sonuna eklenen öğesi.

Açıklamalar

Bir özel durum oluşturulursa, liste değiştirilmeden bırakılır ve özel durum yeniden oluşturulur.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;

   c1.push_back( 1 );
   if ( c1.size( ) != 0 )
      cout << "Last element: " << c1.back( ) << endl;

   c1.push_back( 2 );
   if ( c1.size( ) != 0 )
      cout << "New last element: " << c1.back( ) << endl;

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

   c2.push_back( move( str ) );
   cout << "Moved first element: " << c2.back( ) << endl;
}
Last element: 1
New last element: 2
Moved first element: a

push_front

Listenin başına öğe ekler.

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

Parametreler

val
öğesini listenin başına ekler.

Açıklamalar

Bir özel durum oluşturulursa, liste değiştirilmeden bırakılır ve özel durum yeniden oluşturulur.

Örnek

// 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;
}
First element: 1
New first element: 2
Moved first element: a

rbegin

Ters çevrilmiş listedeki ilk öğeyi ele alan bir yineleyici döndürür.

const_reverse_iterator rbegin() const;
reverse_iterator rbegin();

İade Değeri

Ters çevrilmiş listedeki ilk öğeyi (veya ters çevrilmemiş listedeki son öğeyi ele alan) ters çift yönlü yineleyici.

Açıklamalar

rbegin , tıpkı bir listeyle kullanıldığı gibi begin ters çevrilmiş bir listeyle kullanılır.

dönüş değeri rbegin bir const_reverse_iteratoröğesine atanmışsa, liste nesnesi değiştirilemez. değerinin dönüş değeri rbegin bir reverse_iteratoröğesine atanmışsa, liste nesnesi değiştirilebilir.

rbegin bir listede geriye doğru yinelemek için kullanılabilir.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter;
   list <int>::reverse_iterator c1_rIter;

   // If the following line replaced the line above, *c1_rIter = 40;
   // (below) would be an error
   //list <int>::const_reverse_iterator c1_rIter;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );
   c1_rIter = c1.rbegin( );
   cout << "The last element in the list is " << *c1_rIter << "." << endl;

   cout << "The list is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   // rbegin can be used to start an iteration through a list in
   // reverse order
   cout << "The reversed list is:";
   for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
      cout << " " << *c1_rIter;
   cout << endl;

   c1_rIter = c1.rbegin( );
*c1_rIter = 40;
   cout << "The last element in the list is now " << *c1_rIter << "." << endl;
}
The last element in the list is 30.
The list is: 10 20 30
The reversed list is: 30 20 10
The last element in the list is now 40.

reference

Listede depolanan bir öğeye başvuru sağlayan tür.

typedef typename Allocator::reference reference;

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );
   c1.push_back( 20 );

   int &i = c1.front( );
   int &j = c1.back( );
   cout << "The first element is " << i << endl;
   cout << "The second element is " << j << endl;
}
The first element is 10
The second element is 20

remove

Listede belirtilen değerle eşleşen öğeleri siler.

void remove(const Type& val);

Parametreler

val
Bir öğe tarafından tutulursa bu öğenin listeden kaldırılmasına neden olan değer.

Açıklamalar

Kalan öğelerin sırası etkilenmez.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter, c2_Iter;

   c1.push_back( 5 );
   c1.push_back( 100 );
   c1.push_back( 5 );
   c1.push_back( 200 );
   c1.push_back( 5 );
   c1.push_back( 300 );

   cout << "The initial list is c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   list <int> c2 = c1;
   c2.remove( 5 );
   cout << "After removing elements with value 5, the list becomes c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
}
The initial list is c1 = 5 100 5 200 5 300
After removing elements with value 5, the list becomes c2 = 100 200 300

remove_if

Belirtilen koşulun karşılandığı bir listeden öğeleri siler.

template <class Predicate>
void remove_if(Predicate pred)

Parametreler

pred
Bir öğe tarafından karşılanırsa bu öğenin listeden silinmesine neden olan birli koşul.

Örnek

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

template <class T> class is_odd : public std::unary_function<T, bool>
{
public:
   bool operator( ) ( T& val )
   {
   return ( val % 2 ) == 1;
   }
};

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter, c2_Iter;

   c1.push_back( 3 );
   c1.push_back( 4 );
   c1.push_back( 5 );
   c1.push_back( 6 );
   c1.push_back( 7 );
   c1.push_back( 8 );

   cout << "The initial list is c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   list <int> c2 = c1;
   c2.remove_if( is_odd<int>( ) );

   cout << "After removing the odd elements, "
        << "the list becomes c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;
}
The initial list is c1 = 3 4 5 6 7 8
After removing the odd elements, the list becomes c2 = 4 6 8

rend

Ters çevrilmiş listedeki son öğeyi izleyen konumu ele alan bir yineleyici döndürür.

const_reverse_iterator rend() const;
reverse_iterator rend();

İade Değeri

Ters çevrilmiş listedeki son öğeyi (ters çevrilmiş listedeki ilk öğeden önce gelen konum) başarılı olan konumu ele alan ters çift yönlü yineleyici.

Açıklamalar

rend , tıpkı bir listeyle kullanıldığı gibi end ters çevrilmiş bir listeyle kullanılır.

dönüş değeri rend bir const_reverse_iteratoröğesine atanmışsa, liste nesnesi değiştirilemez. değerinin dönüş değeri rend bir reverse_iteratoröğesine atanmışsa, liste nesnesi değiştirilebilir.

rend bir ters yineleyicinin listesinin sonuna ulaşıp ulaşmadığını test etmek için kullanılabilir.

tarafından rend döndürülen değer başvurulmamalıdır.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter;
   list <int>::reverse_iterator c1_rIter;

   // If the following line had replaced the line above, an error would
   // have resulted in the line modifying an element (commented below)
   // because the iterator would have been const
   // list <int>::const_reverse_iterator c1_rIter;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   c1_rIter = c1.rend( );
   c1_rIter --;  // Decrementing a reverse iterator moves it forward in
                 // the list (to point to the first element here)
   cout << "The first element in the list is: " << *c1_rIter << endl;

   cout << "The list is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   // rend can be used to test if an iteration is through all of the
   // elements of a reversed list
   cout << "The reversed list is:";
   for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
      cout << " " << *c1_rIter;
   cout << endl;

   c1_rIter = c1.rend( );
   c1_rIter--;  // Decrementing the reverse iterator moves it backward
                // in the reversed list (to the last element here)

*c1_rIter = 40;  // This modification of the last element would have
                    // caused an error if a const_reverse iterator had
                    // been declared (as noted above)

   cout << "The modified reversed list is:";
   for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
      cout << " " << *c1_rIter;
   cout << endl;
}
The first element in the list is: 10
The list is: 10 20 30
The reversed list is: 30 20 10
The modified reversed list is: 30 20 40

resize

Liste için yeni bir boyut belirtir.

void resize(size_type _Newsize);
void resize(size_type _Newsize, Type val);

Parametreler

_Newsize
Listenin yeni boyutu.

val
Yeni boyut özgün boyuttan daha büyükse, listeye eklenecek yeni öğelerin değeri. Değer atlanırsa, yeni öğelere sınıfı için varsayılan değer atanır.

Açıklamalar

Listenin boyutu istenen boyuttan küçükse, _Newsizeöğeler istenen boyuta ulaşana kadar listeye eklenir.

Listenin boyutu istenen boyuttan büyükse, listenin sonuna en yakın öğeler, boyutuna ulaşana _Newsizekadar silinir.

Listenin mevcut boyutu istenen boyutla aynıysa hiçbir işlem yapılmaz.

size listenin geçerli boyutunu yansıtır.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   c1.resize( 4,40 );
   cout << "The size of c1 is " << c1.size( ) << endl;
   cout << "The value of the last element is " << c1.back( ) << endl;

   c1.resize( 5 );
   cout << "The size of c1 is now " << c1.size( ) << endl;
   cout << "The value of the last element is now " << c1.back( ) << endl;

   c1.resize( 2 );
   cout << "The reduced size of c1 is: " << c1.size( ) << endl;
   cout << "The value of the last element is now " << c1.back( ) << endl;
}
The size of c1 is 4
The value of the last element is 40
The size of c1 is now 5
The value of the last element is now 0
The reduced size of c1 is: 2
The value of the last element is now 20

reverse

Öğelerin bir listede yer alma sırasını tersine çevirir.

void reverse();

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter;

   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

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

   c1.reverse( );
   cout << "Reversed c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
}
c1 = 10 20 30
Reversed c1 = 30 20 10

reverse_iterator

Ters çevrilmiş listedeki bir öğeyi okuyabilen veya değiştirebilen çift yönlü bir yineleyici sağlayan tür.

typedef std::reverse_iterator<iterator> reverse_iterator;

Açıklamalar

Bir tür reverse_iterator , listede tersten yinelemek için kullanılır.

Örnek

örneğine rbeginbakın.

size

Listedeki öğelerin sayısını döndürür.

size_type size() const;

İade Değeri

Listenin geçerli uzunluğu.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::size_type i;

   c1.push_back( 5 );
   i = c1.size( );
   cout << "List length is " << i << "." << endl;

   c1.push_back( 7 );
   i = c1.size( );
   cout << "List length is now " << i << "." << endl;
}
List length is 1.
List length is now 2.

size_type

Listedeki öğe sayısını sayan bir tür.

typedef typename Allocator::size_type size_type;

Örnek

örneğine sizebakın.

sort

Bir listenin öğelerini artan düzende veya kullanıcı tarafından belirtilen başka bir düzene göre düzenler.

void sort();

template <class Traits>
    void sort(Traits comp);

Parametreler

comp
Ardışık öğeleri sıralamak için kullanılan karşılaştırma işleci.

Açıklamalar

İlk üye işlevi, öğeleri varsayılan olarak artan sırada yerleştirir.

Üye şablonu işlevi, öğelerini sınıfının Traitskullanıcı tarafından belirtilen karşılaştırma işlemine comp göre sıralar.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter;

   c1.push_back( 20 );
   c1.push_back( 10 );
   c1.push_back( 30 );

   cout << "Before sorting: c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   c1.sort( );
   cout << "After sorting c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   c1.sort( greater<int>( ) );
   cout << "After sorting with 'greater than' operation, c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
}
Before sorting: c1 = 20 10 30
After sorting c1 = 10 20 30
After sorting with 'greater than' operation, c1 = 30 20 10

splice

Kaynak listeden öğeleri kaldırır ve bir hedef listeye ekler.

// insert the entire source list
void splice(const_iterator Where, list<Type, Allocator>& Source);
void splice(const_iterator Where, list<Type, Allocator>&& Source);

// insert one element of the source list
void splice(const_iterator Where, list<Type, Allocator>& Source, const_iterator Iter);
void splice(const_iterator Where, list<Type, Allocator>&& Source, const_iterator Iter);

// insert a range of elements from the source list
void splice(const_iterator Where, list<Type, Allocator>& Source, const_iterator First, const_iterator Last);
void splice(const_iterator Where, list<Type, Allocator>&& Source, const_iterator First, const_iterator Last);

Parametreler

Where
Hedef listede daha önce eklenecek konum.

Source
Hedef listeye eklenecek kaynak liste.

Iter
Kaynak listeden eklenecek öğe.

First
Kaynak listeden eklenecek aralıktaki ilk öğe.

Last
Kaynak listeden eklenecek aralıktaki son öğenin ötesindeki ilk konum.

Açıklamalar

İlk üye işlev çifti, kaynak listedeki tüm öğeleri, başvuruda bulunduğu Where konumdan önce hedef listeye ekler ve kaynak listeden tüm öğeleri kaldırır. (&Source eşit thisolmamalıdır.)

İkinci üye işlev çifti tarafından Iter başvuruda bulunılan öğeyi, başvuruda bulunduğu hedef listedeki Where konumdan önce ekler ve Iter'i kaynak listeden kaldırır. (Ise Where == Iter || Where == ++Iterhiçbir değişiklik olmaz.)

Üçüncü üye işlev çifti, [ First, Last) tarafından belirlenen aralığı, tarafından başvuruda bulunılan Where hedef listedeki öğeden önce ekler ve bu öğe aralığını kaynak listeden kaldırır. (Ise &Source == this, aralık [First, Last) tarafından Whereişaret edilen öğeyi içermemelidir.)

Aralıklı splice öğeleri ve &Source != thiseklerseN, sınıfın iterator nesnesi artımlı N zamanlar olur.

Her durumda, spliced öğelerine başvuran yineleyiciler, işaretçiler veya başvurular geçerli kalır ve hedef kapsayıcıya aktarılır.

Örnek

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

using namespace std;

template <typename S> void print(const S& s) {
    cout << s.size() << " elements: ";

    for (const auto& p : s) {
        cout << "(" << p << ") ";
    }

    cout << endl;
}

int main()
{
    list<int> c1{10,11};
    list<int> c2{20,21,22};
    list<int> c3{30,31};
    list<int> c4{40,41,42,43};

    list<int>::iterator where_iter;
    list<int>::iterator first_iter;
    list<int>::iterator last_iter;

    cout << "Beginning state of lists:" << endl;
    cout << "c1 = ";
    print(c1);
    cout << "c2 = ";
    print(c2);
    cout << "c3 = ";
    print(c3);
    cout << "c4 = ";
    print(c4);

    where_iter = c2.begin();
    ++where_iter; // start at second element
    c2.splice(where_iter, c1);
    cout << "After splicing c1 into c2:" << endl;
    cout << "c1 = ";
    print(c1);
    cout << "c2 = ";
    print(c2);

    first_iter = c3.begin();
    c2.splice(where_iter, c3, first_iter);
    cout << "After splicing the first element of c3 into c2:" << endl;
    cout << "c3 = ";
    print(c3);
    cout << "c2 = ";
    print(c2);

    first_iter = c4.begin();
    last_iter = c4.end();
    // set up to get the middle elements
    ++first_iter;
    --last_iter;
    c2.splice(where_iter, c4, first_iter, last_iter);
    cout << "After splicing a range of c4 into c2:" << endl;
    cout << "c4 = ";
    print(c4);
    cout << "c2 = ";
    print(c2);
}
Beginning state of lists:c1 = 2 elements: (10) (11)c2 = 3 elements: (20) (21) (22)c3 = 2 elements: (30) (31)c4 = 4 elements: (40) (41) (42) (43)After splicing c1 into c2:c1 = 0 elements:c2 = 5 elements: (20) (10) (11) (21) (22)After splicing the first element of c3 into c2:c3 = 1 elements: (31)c2 = 6 elements: (20) (10) (11) (30) (21) (22)After splicing a range of c4 into c2:c4 = 2 elements: (40) (43)c2 = 8 elements: (20) (10) (11) (30) (41) (42) (21) (22)

swap

İki liste öğelerini değiştirir.

void swap(list<Type, Allocator>& right);
friend void swap(list<Type, Allocator>& left, list<Type, Allocator>& right)

Parametreler

right
Değiştirilecek öğeleri sağlayan liste veya öğelerinin listedeki öğelerle değiştirileceği liste left.

left
Öğelerinin listedeki öğelerle değiştirileceği bir liste right.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1, c2, c3;
   list <int>::iterator c1_Iter;

   c1.push_back( 1 );
   c1.push_back( 2 );
   c1.push_back( 3 );
   c2.push_back( 10 );
   c2.push_back( 20 );
   c3.push_back( 100 );

   cout << "The original list c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   c1.swap( c2 );

   cout << "After swapping with c2, list c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   swap( c1,c3 );

   cout << "After swapping with c3, list c1 is:";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;
}
The original list c1 is: 1 2 3
After swapping with c2, list c1 is: 10 20
After swapping with c3, list c1 is: 100

unique

Listedeki diğer bazı ikili koşulu karşılayan bitişik yinelenen öğeleri veya bitişik öğeleri kaldırır.

void unique();

template <class BinaryPredicate>
void unique(BinaryPredicate pred);

Parametreler

pred
Ardışık öğeleri karşılaştırmak için kullanılan ikili koşul.

Açıklamalar

Bu işlev, tüm yinelenen öğelerin bitişik olması için listenin sıralandığını varsayar. Bitişik olmayan yinelemeler silinmez.

İlk üye işlevi, önceki öğesine eşit olan her öğeyi kaldırır.

İkinci üye işlevi, önceki öğesiyle karşılaştırıldığında koşul işlevini pred karşılayan her öğeyi kaldırır. Bağımsız değişken için üst bilgide <functional> bildirilen ikili işlev nesnelerinden herhangi birini kullanabilir veya kendi nesnenizi pred oluşturabilirsiniz.

Örnek

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

int main( )
{
   using namespace std;
   list <int> c1;
   list <int>::iterator c1_Iter, c2_Iter,c3_Iter;
   not_equal_to<int> mypred;

   c1.push_back( -10 );
   c1.push_back( 10 );
   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 20 );
   c1.push_back( -10 );

   cout << "The initial list is c1 =";
   for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
      cout << " " << *c1_Iter;
   cout << endl;

   list <int> c2 = c1;
   c2.unique( );
   cout << "After removing successive duplicate elements, c2 =";
   for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
      cout << " " << *c2_Iter;
   cout << endl;

   list <int> c3 = c2;
   c3.unique( mypred );
   cout << "After removing successive unequal elements, c3 =";
   for ( c3_Iter = c3.begin( ); c3_Iter != c3.end( ); c3_Iter++ )
      cout << " " << *c3_Iter;
   cout << endl;
}
The initial list is c1 = -10 10 10 20 20 -10
After removing successive duplicate elements, c2 = -10 10 20 -10
After removing successive unequal elements, c3 = -10 -10

value_type

Listede depolanan veri türünü temsil eden bir tür.

typedef typename Allocator::value_type value_type;

Açıklamalar

value_type , şablon parametresinin Typeeş anlamlısıdır.

Örnek

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

int main( )
{
   using namespace std;
   list<int>::value_type AnInt;
   AnInt = 44;
   cout << AnInt << endl;
}
44