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. |
Déclaré dans l'en-tête <array>
|
||
template< class T, |
(depuis C++11) | |
std::array
est un conteneur qui encapsule des tableaux de taille constante (connue à la compilation).
Cette structure possède la même sémantique de type agrégat qu'un tableau de style C. La taille et l'efficacité de array<T,N> pour un certain nombre d'éléments 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'éléments contenus, le support de l'affectation, les itérateurs à accès aléatoire, etc.
Il existe un cas particulier pour un std::array
de longueur zéro (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 zéro est indéfini .
Array
est un agrégat (il n'a pas de constructeurs et aucun membre en privé ou protégé), ce qui lui permet d'utiliser agrégat d'initialisation.
Un tableau peut aussi être utilisé comme un n-uplet de N
éléments du même type.
Sommaire |
[modifier] 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
|
Itérateur constant à accès aléatoire |
reverse_iterator
|
std::reverse_iterator<iterator> |
const_reverse_iterator
|
std::reverse_iterator<const_iterator> |
[modifier] Fonctions membres
Accès aux éléments | |
accède à l'élément spécifié avec vérification de bornes (fonction membre publique) | |
accède à l'élément spécifié (fonction membre publique) | |
accède au premier élément (fonction membre publique) | |
accède au dernier élément (fonction membre publique) | |
(C++11) |
accède directement au tableau sous-jacent (fonction membre publique) |
Itérateurs | |
retourne un itérateur au début 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 itérateur à 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 itérateur inversé au début (fonction membre publique) | |
retourne un itérateur inversé à la fin (fonction membre publique) | |
Capacité | |
vérifie 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'éléments 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'éléments 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) | |
Opérations | |
remplir le récipient avec la valeur spécifiée 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) |
[modifier] 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 générique) | |
accesses an element of an array (fonction générique) | |
l'algorithme spécialisé 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 générique) |
[modifier] 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 générique spécialisée) | |
obtient le type des éléments 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 générique spécialisée) |
[modifier] Exemple
#include <string> #include <iterator> #include <iostream> #include <algorithm> #include <array> int main() { // La construction utilise l'aggrégat d'initialisation std::array<int, 3> a1{ {1,2,3} }; // Double accolades requises std::array<int, 3> a2 = {1, 2, 3}; // sauf après un = std::array<std::string, 2> a3 = { {std::string("a"), "b"} }; // Les opérations sur les conteneurs sont supportées std::sort(a1.begin(), a1.end()); std::reverse_copy(a2.begin(), a2.end(), std::ostream_iterator<int>(std::cout, " ")); // La boucle "ranged for" est supportée for(auto& s: a3) std::cout << s << ' '; }