std::tuple
De cppreference.com.
|
|
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éfini dans l'en-tête <tuple>
|
||
| template< class... Types > class tuple; |
(depuis C++11) | |
La class template std::tuple est une collection de taille fixe à valeurs hétérogènes. Il s'agit d'une généralisation de std::pair .
Sommaire |
[modifier] Fonctions membres
construit un nouveau tuple (fonction membre publique) | |
affecte le contenu d'un tuple à un autre (fonction membre publique) | |
échange les contenus de deux tuples (fonction membre publique) | |
[modifier] Fonctions tiers
| crée un objet tuple du type défini par les types d'argumentsOriginal: 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. (fonction générique) | |
| crée un tuple de références lvalue ou décompresse un tuple dans des objets individuelsOriginal: 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. (fonction générique) | |
| crée un tuple des références rvalueOriginal: 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. (fonction générique) | |
| crée un tuple en concaténant un certain nombre de tuplesOriginal: 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. (fonction générique) | |
| tuple accède élément spécifié 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. (fonction générique) | |
| compare lexicographiquement les valeurs dans le tuple 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. (fonction générique) | |
| (C++11) |
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 de tuple au moment de la compilation Original: obtains the size of tuple at compile time 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 de l'élément spécifié Original: obtains the type of the specified element 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) | |
| (C++11) |
se spécialise le trait de type std::uses_allocator Original: specializes the std::uses_allocator type trait 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) |
valeur réservée pour sauter un élément lorsque vous déballez un tuple utilisant tie (constante) | |
[modifier] Exemple
#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) << ", " << "note : " << std::get<1>(student0) << ", " << "nom : " << 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 << ", " << "note : " << grade1 << ", " << "nom : " << name1 << '\n'; }