Espaços nominais
Variantes
Acções

std::vector

Da cppreference.com
< cpp‎ | container
 
 
 
std::vector
Funções de membro
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
acesso. Elemento
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)
Iteradores
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)
Capacidade
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)
Modificadores
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
 
Definido no cabeçalho <vector>
template<

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

>class vector;
(1)
namespace pmr {

    template<class T>
    using vector = std::vector<T, std::pmr::polymorphic_allocator<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.
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.


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.


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.


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.


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.
  • Acesso aleatório
    Original:
    Random access - constant
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
    𝓞(1)
  • Inserção ou remoção de elementos ao final
    Original:
    Insertion or removal of elements at the end - amortized constant
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
    𝓞(1)
  • Inserção ou remoção de elementos - linear
    Original:
    Insertion or removal of elements - linear in the distance to the end of the vector
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
    𝓞(n)


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.


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)

Índice

[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.
.
T
deve atender os requisitos de
Original:
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.
CopyAssignable
e
Original:
and
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CopyConstructible.
(até C++11)
Os requisitos que são impostos aos elementos dependem das operações realizadas no container
Original:
The requirements that are imposed on the elements depend on the actual operations performed on the container
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.
Geralmente, requer que o tipo de elemento seja um tipo completo e atenda os requisitos de Erasable, mas muitas funções membros impõem requisitos estritos
Original:
Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.
(desde C++11)
(até C++17)
Os requisitos que são impostos aos elementos dependem das operações realizadas no container
Original:
The requirements that are imposed on the elements depend on the actual operations performed on the container
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.
Geralmente, requer que o tipo de elemento atenda aos requisitos de Erasable, mas qualquer função membro impõe requisitos estritos
Original:
Generally, it is required that element type meets the requirements of Erasable, but many member functions impose stricter requirements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.
Este container (mas não seus membros) podem ser instanciados com um elemento de tipo imcompleto se o alocador satisfizer
Original:
This container (but not its members) can be instantiated with an incomplete element type if the allocator satisfies the
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
allocator completeness requirements.

Feature testing macro: __cpp_lib_incomplete_container_elements

(desde C++17)

[edit]

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
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.
Allocator.
O comportamento é indefinido
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.
(até C++20)
O programa é malformado
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.
(desde C++20)
se
Original:
if
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Allocator::value_type
não é o mesmo que
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.
T. [edit]

[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.
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)[edit]

[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::swapend()
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
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.
end().

[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_typeT[edit]
allocator_typeAllocator[edit]
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.
[edit]
difference_type
tipo inteiro com sinal (geralmente
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.
ptrdiff_t) [edit]
referenceAllocator::reference(até C++11)
value_type&(desde C++11)[edit]
const_referenceAllocator::const_reference(até C++11)
const value_type&(desde C++11)[edit]
pointerAllocator::pointer(até C++11)
std::allocator_traits<Allocator>::pointer(desde C++11)[edit]
const_pointerAllocator::const_pointer(até C++11)
std::allocator_traits<Allocator>::const_pointer(desde C++11)[edit]
iteratorRandomAccessIterator[edit]
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.
[edit]
reverse_iteratorstd::reverse_iterator<iterator>[edit]
const_reverse_iteratorstd::reverse_iterator<const_iterator>[edit]

[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)[edit]
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)[edit]
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)[edit]
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)[edit]
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)[edit]
Elemento de acesso
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)[edit]
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)[edit]
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)[edit]
access the last element
(função pública membro)[edit]
(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)[edit]
Iteradores
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)[edit]
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)[edit]
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)[edit]
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)[edit]
Capacidade
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)[edit]
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)[edit]
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)[edit]
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)[edit]
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)[edit]
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)[edit]
Modificadores
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)[edit]
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)[edit]
(C++11)
constructs element in-place
(função pública membro)[edit]
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)[edit]
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)[edit]
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)[edit]
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)[edit]
changes the number of elements stored
(função pública membro)[edit]
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)[edit]

[editar]Não-membros funções

Predefinição:cpp/container/dsc erase seq
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)[edit]
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)[edit]

[editar]Deduction guides(desde C++17)

[editar]Exemplo

#include <iostream>#include <vector>   int main(){// Cria um vetor contendo inteiros std::vector<int> v ={7, 5, 16, 8};   // Adiciona 2 elementos a mais no vetor v.push_back(25); v.push_back(13);   // Imprime o vetorstd::cout<<"v = { ";for(int n : v){std::cout<< n <<", ";}std::cout<<"}; \n";}

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

close