Espaces de noms
Variantes
Affichages
Actions

std::tuple

De cppreference.com
< cpp‎ | utility


 
 
 
std::tuple
Les fonctions membres
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tuple::tuple
tuple::operator=
tuple::swap
Tiers fonctions
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
make_tuple
tie
forward_as_tuple
None
operator=
operator!=
operator<
operator<=
operator>
operator>=
std::swap
get
Classes d'aide
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tuple_size
tuple_element
uses_allocator
ignore
 
Defined in header <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'arguments
Original:
creates a tuple object of the type defined by the argument types
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) [edit]
crée un tuple de références lvalue ou décompresse un tuple dans des objets individuels
Original:
creates a tuple of lvalue references or unpacks a tuple into individual objects
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) [edit]
crée un tuple des références rvalue
Original:
creates a tuple of rvalue references
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) [edit]
crée un tuple en concaténant un certain nombre de tuples
Original:
creates a tuple by concatenating any number of tuples
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) [edit]
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) [edit]
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) [edit]
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) [edit]

[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) [edit]
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) [edit]
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) [edit]
valeur réservée pour sauter un élément lorsque vous déballez un tuple utilisant tie
(constante) [edit]

[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';
}