std::vector
Da cppreference.com
Definido no cabeçalho <vector> | ||
template< class T, | (1) | |
namespace pmr { template<class T> | (2) | |
1)
std::vector
é um recipiente sequencial que encapsula vetores de tamanho dinâmico.
Original:
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.
2)
std::pmr::vector
é um alias template que usa um polymorphic allocator.
Original:
is an alias template that uses a polymorphic allocator.
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.
Os elementos são armazenados de forma contígua, o que significa que os elementos podem ser acessados não só através de iteradores, mas também com deslocamentos em ponteiros regulares aos elementos. Isto significa que um ponteiro para um elemento de um vector pode ser passado para qualquer função que espera um ponteiro para um elemento de uma matriz.
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.
O armazenamento do vector é feita automaticamente, sendo expandido e contraído, conforme necessário. Vetores geralmente ocupam mais espaço do que arrays estáticos, porque mais memória é alocada para lidar com o crescimento futuro. Desta forma, um vector não necessita de reatribuir cada vez que um elemento é inserido, mas apenas quando a memória adicional está esgotado. A quantidade total de memória alocada pode ser consultada usando função
capacity()
. Memória extra pode ser retornada para o sistema através de uma chamada 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.
Realocações geralmente são operações onerosas em termos de desempenho. A função
reserve()
pode ser usada para eliminar realocações se o número de elementos for previamente conhecido.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.
A complexidade (eficiência) de operações comuns de vetores é como se segue:
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.
- Acesso aleatório𝓞(1)Original:Random access - constantThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Inserção ou remoção de elementos ao final𝓞(1)Original:Insertion or removal of elements at the end - amortized constantThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Inserção ou remoção de elementos - linear𝓞(n)Original:Insertion or removal of elements - linear in the distance to the end of the vectorThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
std::vector
(para T
diferente de bool
) atenda aos requisitos de Container, AllocatorAwareContainer, SequenceContainer, ContiguousContainer(desde C++17) e ReversibleContainer. Original:
std::vector
(for T
other than bool
) meets the requirements of Container, AllocatorAwareContainer, SequenceContainer, ContiguousContainer(desde C++17) 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.
Funções membros de std::vector são constexpr: é possível criar e usar objetos std::vector na avaliação de uma constant expression.Original: Member functions of std::vector are constexpr: it is possible to create and use std::vector objects in the evaluation of a constant expression.The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. Entretanto, objetos std::vector geralmente não podem ser constexpr, porque qualquer armazenamento alocado dinamicamente deve ser liberado na mesma avaliação de constant expression.Original: However, std::vector objects generally cannot be constexpr, because any dynamically allocated storage must be released in the same evaluation of constant expression.The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | (desde C++20) |
[editar]Parâmetros de Template
T | - | O tipo dos elementos . Original: The type of the elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions.
| ||||||
Allocator | - | Um allocator que é usado para alocar/liberar memória e construir/destruir os elementos na memória. O tipo deve atender os requisitos de Allocator. Original: An allocator that is used to acquire/release memory and to construct/destroy the elements in that memory. The type must meet the requirements of The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. O comportamento é indefinido (até C++20)Original: The behavior is undefined The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. O programa é malformado (desde C++20)Original: The program is ill-formed The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. se Allocator::value_typeOriginal: if The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. não é o mesmo que T. Original: is not the same as The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[editar]Especializações
A biblioteca padrão provê uma especialização de
std::vector
para o tipo bool, que pode ser otimizada para eficiência espaço.Original:
The standard library provides a specialization of
std::vector
for the type bool, which may be 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.
espaço eficiente bitset dinâmico 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. (modelo de classe) |
[editar]Invalidação de Iteradores
Operações Original: Operations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | Invalidado Original: Invalidated The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
---|---|
Todas as operações somente leitura Original: All read only operations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | Nunca Original: Never The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
swap, std::swap | end() |
clear, operator=, assign | Nunca Original: Always The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
reserve, shrink_to_fit | Se a capacidade do vetor mudou, todos eles. Se não, nenhum. Original: If the vector changed capacity, all of them. If not, none. The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
erase | Elementos apagados e todos os elementos após ele (incluindo end()) Original: Erased elements and all elements after them (including end()) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
push_back, emplace_back | Se a capacidade do vetor mudou, todos eles. Se não, somente end(). Original: If the vector changed capacity, all of them. If not, only end(). The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
insert, emplace | Se a capacidade do vetor mudou, todos eles. Se não, somente aquele nó ou após o ponto de inserção (incluindo end()). Original: If the vector changed capacity, all of them. If not, only those at or after the insertion point (including end()). The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
resize | Se a capacidade do vetor mudou, todos eles. Se não, somente end() e qualquer elemento apagado. Original: If the vector changed capacity, all of them. If not, only end() and any elements erased. The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
pop_back | O elemento apagado e end(). Original: The element erased and The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[editar]Tipos de membro
Tipo de membro 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. | Definição Original: Definition The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
value_type | T |
allocator_type | Allocator |
size_type | Tipo integral sem sinal (geralmente 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 | tipo inteiro com sinal (geralmente ptrdiff_t) Original: Signed integer type (usually The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
reference | Allocator::reference (até C++11)value_type& (desde C++11) |
const_reference | Allocator::const_reference (até C++11)const value_type& (desde C++11) |
pointer | Allocator::pointer (até C++11)std::allocator_traits<Allocator>::pointer(desde C++11) |
const_pointer | Allocator::const_pointer(até C++11) std::allocator_traits<Allocator>::const_pointer(desde C++11) |
iterator | RandomAccessIterator |
const_iterator | Iterador constante acesso aleatório 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> |
[editar]Funções membro
constrói o 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. (função pública membro) | |
destrói o vector Original: destructs the vector The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |
atribui valores para o recipiente 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. (função pública membro) | |
atribui valores para o recipiente 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. (função pública membro) | |
retorna o alocador de associado 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. (função pública membro) | |
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. | |
acessar o elemento especificado com verificação de limites 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. (função pública membro) | |
acessar o elemento especificado 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. (função pública membro) | |
acesso ao primeiro 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. (função pública membro) | |
access the last element (função pública membro) | |
(C++11) | acesso directo para a matriz subjacente 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. (função pública membro) |
Original: Iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
retorna um iterador para o começo 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. (função pública membro) | |
retorna um iterador para o fim 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. (função pública membro) | |
retorna um iterador inverso ao início 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. (função pública membro) | |
retorna um iterador inverso até ao fim 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. (função pública membro) | |
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 o recipiente estiver vazio 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. (função pública membro) | |
devolve o número de elementos 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. (função pública membro) | |
retorna o número máximo possível de elementos 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. (função pública membro) | |
As reservas de armazenagem 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. (função pública membro) | |
retorna o número de elementos que podem ser mantidos em armazenamento atualmente alocado 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. (função pública membro) | |
(C++11) | reduz o uso de memória, liberando memória não utilizada 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. (função pública membro) |
Original: Modifiers The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
apaga o conteúdo 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. (função pública membro) | |
insere elementos 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. (função pública membro) | |
(C++11) | constructs element in-place (função pública membro) |
apaga elementos 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. (função pública membro) | |
adiciona elementos ao fim 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. (função pública membro) | |
(C++11) | constrói elementos no lugar, na extremidade 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. (função pública membro) |
remove o último 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. (função pública membro) | |
changes the number of elements stored (função pública membro) | |
Trocar o conteúdo 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. (função pública membro) |
[editar]Não-membros funções
lexicographically compara os valores na 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. (modelo de função) | |
o algoritmo especializado 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. (modelo de função) |
[editar]Deduction guides(desde C++17)
[editar]Exemplo
Saída:
v = { 7, 5, 16, 8, 25, 13, };
[editar]Relatório de defeitos
Predefinição:dr list beginPredefinição:dr list itemPredefinição:dr list itemPredefinição:dr list end