std::vector
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Defined in header <vector>
|
||
template< class T, |
||
std::vector
sequenza è un contenitore che racchiude in sé gli array dinamici dimensioni.Original:
std::vector
is a sequence container that encapsulates dynamic size arrays.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Gli elementi sono memorizzati in modo contiguo, il che significa che gli elementi non si può accedere solo attraverso iteratori, ma anche utilizzando offset su puntatori regolari elementi. Ciò significa che un puntatore ad un elemento di un vettore può essere passato a qualsiasi funzione che prevede un puntatore a un elemento di un array.
Original:
The elements are stored contiguously, which means that elements can be accessed not only through iterators, but also using offsets on regular pointers to elements. This means that a pointer to an element of a vector may be passed to any function that expects a pointer to an element of an array.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
La memorizzazione del vettore viene gestita automaticamente, in fase di espansione e contrazione come necessario. Vettori di solito occupano più spazio di array statici, perché allocare più memoria per gestire la crescita futura. In questo modo un vettore non ha bisogno di riassegnare ogni volta che viene inserito un elemento, ma solo quando la memoria aggiuntiva è esaurita. La quantità totale di memoria allocata può essere interrogato con la funzione
capacity()
. Memoria supplementare può essere restituito al sistema tramite una chiamata a shrink_to_fit()
.Original:
The storage of the vector is handled automatically, being expanded and contracted as needed. Vectors usually occupy more space than static arrays, because more memory is allocated to handle future growth. This way a vector does not need to reallocate each time an element is inserted, but only when the additional memory is exhausted. The total amount of allocated memory can be queried using
capacity()
function. Extra memory can be returned to the system via a call to shrink_to_fit()
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Riassegnazioni di solito sono operazioni costose in termini di prestazioni.
reserve()
funzione può essere utilizzata per eliminare riassegnazioni se il numero di elementi è noto in anticipo.Original:
Reallocations are usually costly operations in terms of performance.
reserve()
function can be used to eliminate reallocations if the number of elements is known beforehand.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
La complessità (efficienza) di operazioni comuni sui vettori è il seguente:
Original:
The complexity (efficiency) of common operations on vectors is as follows:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- Accesso casuale - O(1) costanteOriginal:Random access - constant O(1)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - L'inserimento o la rimozione di elementi, alla fine - ammortizzato O(1) costanteOriginal:Insertion or removal of elements at the end - amortized constant O(1)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Inserimento o la rimozione di elementi - lineare distanza dalla fine della O(n) vettoreOriginal:Insertion or removal of elements - linear in distance to the end of the vector O(n)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std::vector
soddisfi i requisiti di Container
, AllocatorAwareContainer
, SequenceContainer
e ReversibleContainer
.Original:
std::vector
meets the requirements of Container
, AllocatorAwareContainer
, SequenceContainer
and ReversibleContainer
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Specializzazioni
La libreria standard fornisce una specializzazione per il
std::vector
bool tipo, che è ottimizzato per l'efficienza dello spazio.Original:
The standard library provides a specialization of
std::vector
for the type bool, which is optimized for space efficiency.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
spazio-efficiente bitset dinamica Original: space-efficient dynamic bitset The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe template) |
[modifica] Membri tipi
Membro tipo
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
T
|
allocator_type
|
Allocator
|
size_type
|
Unsigned tipo integrale (di solito size_t)
Original: Unsigned integral type (usually size_t) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
difference_type
|
Signed integer type (usually ptrdiff_t) |
reference
|
Allocator::reference (C fino + 11)value_type& (dal C++11)
|
const_reference
|
Allocator::const_reference (C fino + 11)const value_type& (dal C++11)
|
pointer
|
Allocator::pointer (C fino + 11)std::allocator_traits<Allocator>::pointer (dal C++11) |
const_pointer
|
Allocator::const_pointer (C fino + 11) std::allocator_traits<Allocator>::const_pointer (dal C++11) |
iterator
|
RandomAccessIterator
|
const_iterator
|
Costante iteratore ad accesso casuale
Original: Constant random access iterator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
reverse_iterator
|
std::reverse_iterator<iterator> |
const_reverse_iterator
|
std::reverse_iterator<const_iterator> |
[modifica] Membri funzioni
costruisce il vector Original: constructs the vector The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
destructs the vector (metodo pubblico) | |
assegna valori al contenitore Original: assigns values to the container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
assegna valori al contenitore Original: assigns values to the container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
restituisce l'allocatore associato Original: returns the associated allocator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
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. | |
accedere elemento specificato con verifica dei limiti Original: access specified element with bounds checking The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
accedere elemento specificato Original: access specified element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
accedere al primo elemento Original: access the first element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
access the last element (metodo pubblico) | |
(C++11) |
accesso diretto alla matrice sottostante Original: direct access to the underlying array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) |
Original: Iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
restituisce un iteratore all'inizio 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. (metodo pubblico) | |
restituisce un iteratore fino alla fine 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. (metodo pubblico) | |
restituisce un iteratore inverso all'inizio Original: returns a reverse 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. (metodo pubblico) | |
restituisce un iteratore inverso alla fine Original: returns a reverse 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. (metodo pubblico) | |
Original: Capacity The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
verifica se il contenitore è vuoto 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. (metodo pubblico) | |
restituisce il numero di elementi 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. (metodo pubblico) | |
restituisce il massimo numero possibile di elementi 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. (metodo pubblico) | |
riserve di stoccaggio Original: reserves storage The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
restituisce il numero di elementi che possono essere tenuti in deposito attualmente assegnate Original: returns the number of elements that can be held in currently allocated storage The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
(C++11) |
riduce l'utilizzo della memoria da liberare la memoria inutilizzata 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. (metodo pubblico) |
Original: Modifiers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
cancella il contenuto 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. (metodo pubblico) | |
inserti di elementi 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. (metodo pubblico) | |
(C++11) |
constructs element in-place (metodo pubblico) |
cancella elementi Original: erases elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
aggiunge elementi alla fine 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. (metodo pubblico) | |
(C++11) |
costruisce elementi in-posto alla fine Original: constructs elements in-place at the end The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) |
rimuove l'ultimo elemento 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. (metodo pubblico) | |
changes the number of elements stored (metodo pubblico) | |
swap il contenuto 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. (metodo pubblico) |
[modifica] Non membri funzioni
lessicografico confronta i valori nella 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. (funzione di modello) | |
specializzata l'algoritmo 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. (funzione di modello) |