std::array
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Dclar dans l'en-tte <array>
|
||
template< class T, std::size_t N > struct array; |
(depuis C++11) | |
std::array est un conteneur qui encapsule des tableaux de taille constante (connue la compilation).
Cette structure possde la mme smantique de type agrgat qu'un tableau de style C. La taille et l'efficacit de array<T,N> pour un certain nombre d'lments sont quivalentes celles du tableau T[N] de style C correspondant. La structure offre les avantages d'un conteneur standard, telles que la connaissance du nombre d'lments contenus, le support de l'affectation, les itrateurs accs alatoire, etc.
Il existe un cas particulier pour un std::array de longueur zro (N == 0). Dans ce cas, array.begin() == array.end(), qui est une valeur unique. L'effet de l'appel de front() ou back() sur un tableau de taille zro est indfini .
Array est un agrgat (il n'a pas de constructeurs et aucun membre en priv ou protg), ce qui lui permet d'utiliser agrgat d'initialisation.
Un tableau peut aussi tre utilis comme un n-uplet de N lments du mme type.
Types membres
| Type membre | 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
|
Itrateur constant accs alatoire |
reverse_iterator
|
std::reverse_iterator<iterator>
|
const_reverse_iterator
|
std::reverse_iterator<const_iterator>
|
Fonctions membres
Accs aux lments | |
| accde l'lment spcifi avec vrification de bornes (fonction membre publique) | |
| accde l'lment spcifi (fonction membre publique) | |
| accde au premier lment (fonction membre publique) | |
| accde au dernier lment (fonction membre publique) | |
(C++11) |
accde directement au tableau sous-jacent (fonction membre publique) |
Itrateurs | |
retourne un itrateur au dbut 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. (fonction membre publique) | |
retourne un itrateur la fin 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. (fonction membre publique) | |
| retourne un itrateur invers au dbut (fonction membre publique) | |
| retourne un itrateur invers la fin (fonction membre publique) | |
Capacit | |
vrifie si le conteneur est vide 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. (fonction membre publique) | |
retourne le nombre d'lments 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. (fonction membre publique) | |
retourne le plus grand nombre possible d'lments 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. (fonction membre publique) | |
Oprations | |
remplir le rcipient avec la valeur spcifie 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. (fonction membre publique) | |
permute les contenus 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. (fonction membre publique) | |
Fonctions tiers
compare lexicographiquement les valeurs dans le 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. (fonction gnrique) | |
accesses an element of an array (fonction gnrique) | |
l'algorithme spcialis 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. (fonction gnrique) | |
Classes d'aide
obtient la taille d'une 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 gnrique spcialise) | |
obtient le type des lments 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. (classe gnrique spcialise) | |
Exemple
#include <string>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <array>
int main()
{
// La construction utilise l'aggrgat d'initialisation
std::array<int, 3> a1{ {1,2,3} }; // Double accolades requises
std::array<int, 3> a2 = {1, 2, 3}; // sauf aprs un =
std::array<std::string, 2> a3 = { {std::string("a"), "b"} };
// Les oprations sur les conteneurs sont supportes
std::sort(a1.begin(), a1.end());
std::reverse_copy(a2.begin(), a2.end(), std::ostream_iterator<int>(std::cout, " "));
// La boucle "ranged for" est supporte
for(auto& s: a3)
std::cout << s << ' ';
}