std::array
| definiert in Header <array>
|
||
template< class T, std::size_t N > struct array; |
(seit C++11) | |
std::array ist ein Container zur Kapselung einer Sequenz konstanter Länge.
Diese Struktur hat dieselbe Semantik wie ein C-Array mit konstanter Größe. Die Größe und Effizienz von array<T,N> ist ebenso, wie die des äquivalenten C-Arrays T[N]. Die Struktur bietet die Vorteile eines Standard Containers, wie eine Methode die die Größe angibt oder Iteratoren.
Der Spezialfall ist ein Array mit einer Größe von null (N == 0).
In diesem Falle gilt array.begin() == array.end(). Der Aufruf von front() oder back() hat undefiniertes Verhalten.
array ist ein Aggregat-Typ (es hat keinen Konstruktor und keine privaten oder geschützten Elemente), was Aggregate-Initialisierung ermöglicht.
Ein array kann ebenso als Tuple von N von Elementen desselben Types genutzt werden.
Mitglied Typen
Mitglied Typ
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
|
Constant random access iterator
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>
|
Member-Funktionen
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. | |
Zugriff auf angegebene Element mit Überprüfung von Grenzen 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. (öffentliche Elementfunktion) | |
Zugriff auf angegebene Element 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. (öffentliche Elementfunktion) | |
Zugriff auf das erste Element 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. (öffentliche Elementfunktion) | |
| Zugriff auf das letzte Element (öffentliche Elementfunktion) | |
(C++11) |
Direkter Zugang zu dem zugrundeliegenden Array (öffentliche Elementfunktion) |
Original: Iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
liefert einen Iterator an den Anfang 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. (öffentliche Elementfunktion) | |
liefert einen Iterator bis zum Ende 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. (öffentliche Elementfunktion) | |
gibt einen umgekehrten Iterator an den Anfang 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. (öffentliche Elementfunktion) | |
gibt einen umgekehrten Iterator bis zum Ende 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. (öffentliche Elementfunktion) | |
Original: Capacity The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
prüft, ob der Container leer ist 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. (öffentliche Elementfunktion) | |
liefert die Anzahl der Elemente 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. (öffentliche Elementfunktion) | |
gibt die maximal mögliche Anzahl von Elementen 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. (öffentliche Elementfunktion) | |
Original: Operations The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
Füllen Sie den Behälter mit angegebenen Wert 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. (öffentliche Elementfunktion) | |
tauscht die Inhalte 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. (öffentliche Elementfunktion) | |
Non-Member-Funktionen
| lexikographischer Vergleich der Werte in array (Funktions-Template) | |
accesses an element of an array (Funktions-Template) | |
spezialisiert die std::swap Algorithmus 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. (Funktions-Template) | |
Helper-Klassen
erhält die Größe eines 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. (class Template-Spezialisierung) | |
ermittelt die Art der Elemente der 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. (class Template-Spezialisierung) | |
Beispiel
#include <string>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <array>
int main()
{
// Erstellen mit Aggregat-Initialisierung
std::array<int, 3> a1{ {1,2,3} }; // doppelte Klammern werden benötigt
std::array<int, 3> a2 = {1, 2, 3}; // außer nach =
std::array<std::string, 2> a3 = { {std::string("a"), "b"} };
// Container Operationen sind möglich
std::sort(a1.begin(), a1.end());
std::reverse_copy(a2.begin(), a2.end(), std::ostream_iterator<int>(std::cout, " "));
// Range basierte for-Schleife ist möglich
for(auto& s: a3)
std::cout << s << ' ';
}
Output:
3 2 1 a b