std::tuple
De cppreference.com
<tbody>
</tbody>
| Dclar dans l'en-tte <tuple>
|
||
template< class... Types > class tuple; |
(depuis C++11) | |
La class template std::tuple est une collection de taille fixe valeurs htrognes. Il s'agit d'une gnralisation de std::pair .
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) | |
Fonctions tiers
cre un objet tuple du type dfini 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 gnrique) | |
cre un tuple de rfrences lvalue ou dcompresse 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 gnrique) | |
cre un tuple des rfrences 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 gnrique) | |
cre un tuple en concatnant 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 gnrique) | |
tuple accde lment spcifi 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 gnrique) | |
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 gnrique) | |
(C++11) |
l'algorithme spcialis 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 gnrique) |
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 gnrique spcialise) | |
obtient le type de l'lment spcifi 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 gnrique spcialise) | |
(C++11) |
se spcialise 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 gnrique spcialise) |
valeur rserve pour sauter un lment lorsque vous dballez un tuple utilisant tie (constante) | |
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';
}