Espaces de noms
Variantes
Affichages
Actions

std::vector

De cppreference.com
< cpp‎ | container
 
 
 
std::vector
Les fonctions membres
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::vector
vector::~vector
vector::operator=
vector::assign
vector::get_allocator
Elément d'accès
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::at
vector::operator[]
vector::front
vector::back
vector::data (C++11)
Les itérateurs
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::begin
vector::cbegin

(C++11)
vector::end
vector::cend

(C++11)
vector::rbegin
vector::crbegin

(C++11)
vector::rend
vector::crend

(C++11)
Capacité
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::empty
vector::size
vector::max_size
vector::reserve
vector::capacity
vector::shrink_to_fit (C++11)
Modificateurs
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
vector::clear
vector::insert
vector::emplace (C++11)
vector::erase
vector::push_back
vector::emplace_back (C++11)
vector::pop_back
vector::resize
vector::swap
 
Déclaré dans l'en-tête <vector>
template<

    class T,
    class Allocator = std::allocator<T>

> class vector;

std::vector est un conteneur séquentiel qui encapsule les tableaux de taille dynamique .

Les éléments sont stockés de façon contigüe, ce qui signifie que les éléments sont accessibles non seulement via les itérateurs, mais aussi à partir des pointeurs classiques sur un élément. Cela signifie qu'un pointeur sur un élément d'un vector peut être passé à une fonction qui attend un pointeur sur un élément d'un tableau.

Le stockage du vector est pris en charge automatiquement, pouvant être augmenté ou diminué au besoin. Les vector occupent généralement plus d'espace que les tableaux statiques, du fait que de la mémoire supplémentaire est allouée pour anticiper un accroissement futur. Ainsi, un vector n'a pas besoin de ré-allouer la mémoire chaque fois qu'un élément est inséré, mais seulement lorsque la mémoire additionnelle est épuisée. La quantité totale de mémoire allouée peut être obtenue en utilisant la fonction capacity(). La mémoire additionnelle peut être rendue au système via un appel à shrink_to_fit().

Les ré-allocations sont généralement des opérations coûteuses en termes de performance. La fonction reserve() peut être utilisée pour éliminer les ré-allocations lorsque la quantité maximum d'éléments est connue d'avance.

La complexité (efficacité) des opérations courante sur les vector sont les suivantes :

  • Accès aléatoire - constante O(1)
  • Insertion ou le retrait d'éléments à la fin - constante amortie O(1)
  • Insertion ou le retrait d'éléments - linéaire O(n)

std::vector répond aux exigences des concepts Container, AllocatorAwareContainer, SequenceContainer et ReversibleContainer.

Sommaire

[modifier] Paramètre template

T - Type des éléments.
T doit satisfaire aux exigences de CopyAssignable et CopyConstructible. (avant C++11)

Les exigences imposées sur les éléments dépendent des opérations à réaliser sur le conteneur. En règle générale, il est nécessaire que le type des éléments réponde aux exigences de MoveConstructible et MoveAssignable, mais de nombreuses fonctions de membres imposent des exigences plus strictes.

(depuis C++11)

[edit]

Allocator - Les allocateurs gèrent toutes les demandes d'allocation et de désallocation de la mémoire pour un conteneur générique ou personnalisé. Le type doit répondre aux exigences de Allocator. [edit]

[modifier] Spécialisations

La bibliothèque standard fournit une spécialisation de std::vector pour le type bool, qui est optimisée pour réduire la taille mémoire utilisée par le conteneur.

champ de bits dynamique efficace en espace
(classe générique) [edit]

[modifier] Types des membres

Type du membre Définition
value_type T [edit]
allocator_type Allocator [edit]
size_type Type intégral non signé (généralement size_t)[edit]
difference_type Type intégral signé (généralement ptrdiff_t) [edit]
reference Allocator::reference (avant C++11)
value_type& (depuis C++11) [edit]
const_reference Allocator::const_reference (avant C++11)
const value_type& (depuis C++11) [edit]
pointer Allocator::pointer (avant C++11)
std::allocator_traits<Allocator>::pointer (depuis C++11) [edit]
const_pointer Allocator::const_pointer (avant C++11)
std::allocator_traits<Allocator>::const_pointer (depuis C++11) [edit]
iterator RandomAccessIterator [edit]
const_iterator Itérateur constant à accès aléatoire [edit]
reverse_iterator std::reverse_iterator<iterator> [edit]
const_reverse_iterator std::reverse_iterator<const_iterator> [edit]

[modifier] Fonctions membres

Construit le vector
(fonction membre publique) [edit]
détruit le vector
(fonction membre publique) [edit]
Attribue les valeurs dans le conteneur
(fonction membre publique) [edit]

Attribue les valeurs dans le conteneur
(fonction membre publique) [edit]

Renvoie l'allocateur associé
(fonction membre publique) [edit]

Accès aux éléments
accède à l'élément spécifié avec vérification de bornes
(fonction membre publique) [edit]
accède à l'élément spécifié
(fonction membre publique) [edit]
accède au premier élément
(fonction membre publique) [edit]
accède au dernier élément
(fonction membre publique) [edit]
(C++11)
accède directement au tableau sous-jacent
(fonction membre publique) [edit]
Itérateurs
retourne un itérateur au début
Original:
returns an iterator to the beginning
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
retourne un itérateur à la fin
Original:
returns an iterator to the end
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
retourne un itérateur inversé au début
(fonction membre publique) [edit]
retourne un itérateur inversé à la fin
(fonction membre publique) [edit]
Capacité
vérifie si le conteneur est vide
Original:
checks whether the container is empty
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
retourne le nombre d'éléments
Original:
returns the number of elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
retourne le plus grand nombre possible d'éléments
Original:
returns the maximum possible number of elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
réserve de l'espace mémoire
(fonction membre publique) [edit]
renvoie le nombre d'éléments qui peuvent être contenus dans l'espace mémoire actuellement alloué
(fonction membre publique) [edit]
réduit l'utilisation de la mémoire en libérant la mémoire inutilisée
Original:
reduces memory usage by freeing unused memory
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
Manipulateurs
efface le contenu
Original:
clears the contents
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
insère des éléments
Original:
inserts elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
(C++11)
construit des éléments en mémoire
(fonction membre publique) [edit]
efface des éléments
(fonction membre publique) [edit]
ajoute des éléments à la fin
Original:
adds elements to the end
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
construit des éléments en place à la fin
(fonction membre publique) [edit]
supprime le dernier élément
Original:
removes the last element
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
modifie le nombre d'éléments stockés
Original:
changes the number of elements stored
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]
permute les contenus
Original:
swaps the contents
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction membre publique) [edit]

[modifier] Fonctions libres

compare lexicographiquement les valeurs dans le vector
Original:
lexicographically compares the values in the vector
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction générique) [edit]
l'algorithme spécialisé std::swap
Original:
specializes the std::swap algorithm
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction générique) [edit]