| Definido no cabeçalho <array>
|
||
template< class T, std::size_t N > struct array; |
(desde C++11) | |
std::array é um contêiner que encapsula um array de tamanho constante.
Esta estrutura possui a mesma semântica de tipo agregado que o array estilo C. O tamanho e a eficiência do array<T,N>, para uma certa quantidade de elementos, são equivalentes ao array T[N] estilo C correspondente. A estrutura provê os benefícios de um contêiner padrão, tais como o próprio tamanho, suporte a atribuição, acesso randômico, iteradores, etc.
Há um caso especial para array de tamanho zero ((N == 0)). Nesse caso, array.begin() == array.end(), que é algum valor único. O efeito de chamar front() or back() ou back() em um array de tamanho zero é indefinido.
array é um agregado (não possui construtores nem membros privados ou protegidos), o que o permite usar aggregate-initialization.
Um array também pode ser usado como uma tupla de N elementos do mesmo tipo.
Tipos 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. |
Definition |
value_type
|
T
|
size_type
|
size_t
|
difference_type
|
ptrdiff_t
|
reference
|
value_type&
|
const_reference
|
const value_type&
|
pointer
|
T*
|
const_pointer
|
const T*
|
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>
|
Funções 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) | |
Original: Operations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
encher o recipiente com o valor especificado Original: fill the container with specified value 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) | |
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) | |
Não-membros funções
lexicographically compara os valores na array Original: lexicographically compares the values in the array 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) | |
accesses an element of an array (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) | |
Classes auxiliares
obtém o tamanho de um array Original: obtains the size 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. (especialização modelo. classe) | |
obtém o tipo dos elementos de array Original: obtains the type of the elements of array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (especialização modelo. classe) | |
Exemplo
#include <string>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <array>
int main()
{
// construction uses aggregate initialization
std::array<int, 3> a1{ {1,2,3} }; // double-braces required
std::array<int, 3> a2 = {1, 2, 3}; // except after =
std::array<std::string, 2> a3 = { {std::string("a"), "b"} };
// container operations are supported
std::sort(a1.begin(), a1.end());
std::reverse_copy(a2.begin(), a2.end(), std::ostream_iterator<int>(std::cout, " "));
// ranged for loop is supported
for(auto& s: a3)
std::cout << s << ' ';
}
Saída:
3 2 1 a b