◐ Shell
clean mode source ↗

std::array – cppreference.com

Aus cppreference.com

<tbody> </tbody>

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 [edit]
size_type size_t [edit]
difference_type ptrdiff_t [edit]
reference value_type& [edit]
const_reference const value_type& [edit]
pointer T*[edit]
const_pointer const T*[edit]
iterator RandomAccessIterator [edit]
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.

[edit]
reverse_iterator std::reverse_iterator<iterator> [edit]
const_reverse_iterator std::reverse_iterator<const_iterator> [edit]

Member-Funktionen

Elementzugriff

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) [edit]

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) [edit]

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) [edit]
Zugriff auf das letzte Element
(öffentliche Elementfunktion) [edit]

(C++11)

Direkter Zugang zu dem zugrundeliegenden Array
(öffentliche Elementfunktion) [edit]

Iteratoren

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) [edit]

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) [edit]

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) [edit]

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) [edit]

Kapazität

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) [edit]

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) [edit]

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) [edit]

Operations

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) [edit]

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) [edit]

Non-Member-Funktionen

lexikographischer Vergleich der Werte in array
(Funktions-Template) [edit]
accesses an element of an array
(Funktions-Template) [edit]

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) [edit]

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) [edit]

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) [edit]

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: