std::vector
| Dclar dans l'en-tte <vector>
|
||
template< class T, class Allocator = std::allocator<T> > class vector; |
||
std::vector est un conteneur squentiel qui encapsule les tableaux de taille dynamique .
Les lments sont stocks de faon contige, ce qui signifie que les lments sont accessibles non seulement via les itrateurs, mais aussi partir des pointeurs classiques sur un lment. Cela signifie qu'un pointeur sur un lment d'un vector peut tre pass une fonction qui attend un pointeur sur un lment d'un tableau.
Le stockage du vector est pris en charge automatiquement, pouvant tre augment ou diminu au besoin. Les vector occupent gnralement plus d'espace que les tableaux statiques, du fait que de la mmoire supplmentaire est alloue pour anticiper un accroissement futur. Ainsi, un vector n'a pas besoin de r-allouer la mmoire chaque fois qu'un lment est insr, mais seulement lorsque la mmoire additionnelle est puise. La quantit totale de mmoire alloue peut tre obtenue en utilisant la fonction capacity(). La mmoire additionnelle peut tre rendue au systme via un appel shrink_to_fit().
Les r-allocations sont gnralement des oprations coteuses en termes de performance. La fonction reserve() peut tre utilise pour liminer les r-allocations lorsque la quantit maximum d'lments est connue d'avance.
La complexit (efficacit) des oprations courante sur les vector sont les suivantes :
- Accs alatoire - constante O(1)
- Insertion ou le retrait d'lments la fin - constante amortie O(1)
- Insertion ou le retrait d'lments - linaire O(n)
std::vector rpond aux exigences des concepts Container, AllocatorAwareContainer, SequenceContainer et ReversibleContainer.
Paramtre template
| T | - | Type des lments.
| ||||
| Allocator | - | Les allocateurs grent toutes les demandes d'allocation et de dsallocation de la mmoire pour un conteneur gnrique ou personnalis. Le type doit rpondre aux exigences de Allocator.
|
Spcialisations
La bibliothque standard fournit une spcialisation de std::vector pour le type bool, qui est optimise pour rduire la taille mmoire utilise par le conteneur.
| champ de bits dynamique efficace en espace (classe gnrique) | |
Types des membres
| Type du membre | Dfinition |
value_type
|
T
|
allocator_type
|
Allocator
|
size_type
|
Type intgral non sign (gnralement size_t)
|
difference_type
|
Type intgral sign (gnralement ptrdiff_t)
|
reference
|
Allocator::reference (avant C++11)value_type& (depuis C++11)
|
const_reference
|
Allocator::const_reference (avant C++11)const value_type& (depuis C++11)
|
pointer
|
Allocator::pointer (avant C++11)std::allocator_traits<Allocator>::pointer (depuis C++11)
|
const_pointer
|
Allocator::const_pointer (avant C++11)std::allocator_traits<Allocator>::const_pointer (depuis C++11)
|
iterator
|
RandomAccessIterator
|
const_iterator
|
Itrateur constant accs alatoire |
reverse_iterator
|
std::reverse_iterator<iterator>
|
const_reverse_iterator
|
std::reverse_iterator<const_iterator>
|
Fonctions membres
Construit le vector (fonction membre publique) | |
dtruit le vector (fonction membre publique) | |
| Attribue les valeurs dans le conteneur (fonction membre publique) | |
|
Attribue les valeurs dans le conteneur | |
|
Renvoie l'allocateur associ | |
Accs aux lments | |
| accde l'lment spcifi avec vrification de bornes (fonction membre publique) | |
| accde l'lment spcifi (fonction membre publique) | |
| accde au premier lment (fonction membre publique) | |
| accde au dernier lment (fonction membre publique) | |
(C++11) |
accde directement au tableau sous-jacent (fonction membre publique) |
Itrateurs | |
retourne un itrateur au dbut 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) | |
retourne un itrateur 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) | |
| retourne un itrateur invers au dbut (fonction membre publique) | |
| retourne un itrateur invers la fin (fonction membre publique) | |
Capacit | |
vrifie 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) | |
retourne le nombre d'lments 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) | |
retourne le plus grand nombre possible d'lments 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) | |
| rserve de l'espace mmoire (fonction membre publique) | |
| renvoie le nombre d'lments qui peuvent tre contenus dans l'espace mmoire actuellement allou (fonction membre publique) | |
(C++11) |
rduit l'utilisation de la mmoire en librant la mmoire inutilise 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) |
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) | |
insre des lments 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) | |
(C++11) |
construit des lments en mmoire (fonction membre publique) |
| efface des lments (fonction membre publique) | |
ajoute des lments 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) | |
(C++11) |
construit des lments en place la fin (fonction membre publique) |
supprime le dernier lment 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) | |
modifie le nombre d'lments stocks 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) | |
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) | |
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 gnrique) | |
l'algorithme spcialis 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 gnrique) | |