std::tuple
Aus cppreference.com
| definiert in Header <tuple>
|
||
template< class... Types > class tuple; |
(seit C++11) | |
Das Klassentemplate
std::tuple ist eine Collection fester Größe mit heterogenen Werte. Es ist die Verallgemeinerung von std::pair .Original:
Class template
std::tuple is a fixed-size collection of heterogeneous values. It is a generalization of std::pair.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Member-Funktionen
baut eine neue tuple Original: constructs a new tuple The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (öffentliche Elementfunktion) | |
ordnet den Inhalt eines tuple zum anderenOriginal: assigns the contents of one tuple to anotherThe 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 von zwei tuples Original: swaps the contents of two tuples 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
erzeugt eine tuple Objekt des Typs von den Argumenttypen definiertOriginal: creates a tuple object of the type defined by the argument typesThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
erzeugt ein tuple aus lvalue Referenzen oder entpackt ein Tupel in einzelne ObjekteOriginal: creates a tuple of lvalue references or unpacks a tuple into individual objectsThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
erzeugt ein tuple aus rvalue ReferenzenOriginal: creates a tuple of rvalue referencesThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
erzeugt ein tuple durch Verketten einer beliebigen Anzahl von TupelnOriginal: creates a tuple by concatenating any number of tuplesThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
Zugriff auf das angegebene Element des Tupels Original: tuple accesses specified element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
lexikographisch vergleicht die Werte in dem Tupel Original: lexicographically compares the values in the tuple The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
(C++11) |
spezialisiert den 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
Beispiel
#include <tuple>
#include <iostream>
#include <string>
#include <stdexcept>
std::tuple<double, char, std::string> get_student(int id)
{
if (id == 0) return std::make_tuple(3.8, 'A', "Lisa Simpson");
if (id == 1) return std::make_tuple(2.9, 'C', "Milhouse Van Houten");
if (id == 2) return std::make_tuple(1.7, 'D', "Ralph Wiggum");
throw std::invalid_argument("id");
}
int main()
{
auto student0 = get_student(0);
std::cout << "ID: 0, "
<< "GPA: " << std::get<0>(student0) << ", "
<< "grade: " << std::get<1>(student0) << ", "
<< "name: " << std::get<2>(student0) << '\n';
double gpa1;
char grade1;
std::string name1;
std::tie(gpa1, grade1, name1) = get_student(1);
std::cout << "ID: 1, "
<< "GPA: " << gpa1 << ", "
<< "grade: " << grade1 << ", "
<< "name: " << name1 << '\n';
}
Output:
ID: 0, GPA: 3.8, grade: A, name: Lisa Simpson
ID: 1, GPA: 2.9, grade: C, name: Milhouse Van Houten
