std::array
|
|
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. |
| Elemento definito nell'header <array>
|
||
template< class T, std::size_t N > struct array; |
(dal C++11) | |
std::array è un contenitore che racchiude un array di dimensione costante.
Questa struct ha la stessa semantica di tipo di un array in stile C. La dimensione e la performance di un array<T,N> per un certo numero di elementi è equivalente alla dimensione e alla performance del rispettivo array in stile C T[N]. La struct provvede gli stessi vantaggi di un contenitore standard, come conoscerne la dimensione, supportare l'assegnamento, gli iteratori di accesso casuale, etc.
È previsto il caso speciale per gli array di dimensione 0 (tt|N == 0). In questo caso array.begin() == array.end(), rappresentato da un valore unico. Chiamare front() o back() nel caso di array di dimensione zero genera un comportamento non definito.
array è un tipo aggregato (non ha costruttori, non ha membri privati né protetti), il che permette di utilizzare la specifica inizializzazione aggregata.
Un array può anche essere utilizzato come una tupla di N elementi dello stesso tipo.
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
|
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
|
Iteratore ad accesso casuale su costanti |
reverse_iterator
|
std::reverse_iterator<iterator>
|
const_reverse_iterator
|
std::reverse_iterator<const_iterator>
|
Membri funzioni
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) | |
Original: Operations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
riempire il contenitore con il valore specificato 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. (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) | |
Non membri funzioni
lessicografico confronta i valori nella 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. (funzione di modello) | |
accesses an element of an array (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) | |
Helper classi
ottiene la dimensione di un 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. (classe modello di specializzazione) | |
ottiene il tipo di elementi di 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. (classe modello di specializzazione) | |
Esempio
#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 << ' ';
}
Output:
3 2 1 a b