◐ Shell
clean mode source ↗

std::tuple - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<tbody> </tbody>

Elemento definito nell'header

<tuple>

template< class... Types > class tuple;

(dal C++11)

Modello std::tuple classe è un insieme di dimensioni fisse di valori eterogenei. Si tratta di una generalizzazione di 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.

Membri funzioni

costruisce un nuovo 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.


(metodo pubblico)

assegna il contenuto di una tuple all'altro

Original:

assigns the contents of one tuple to another

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(metodo pubblico)

scambia il contenuto di due 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.


(metodo pubblico)

Non membri funzioni

crea un oggetto tuple del tipo definito dai tipi di argomenti

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.


(funzione di modello) [modifica]

crea un tuple di riferimenti lvalue o spacchetta una tupla in singoli oggetti

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.


(funzione di modello) [modifica]

crea un tuple di riferimenti 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.


(funzione di modello) [modifica]

crea un tuple concatenando un numero qualsiasi di tuple

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.


(funzione di modello) [modifica]

tupla accede elemento specificato

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.


(funzione di modello) [modifica]

lessicografico confronta i valori nella tupla

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.


(funzione di modello) [modifica]

specializzata l'algoritmo 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.


(funzione di modello) [modifica]

Helper classi

ottiene la dimensione della tuple al momento della compilazione

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 modello di specializzazione) [modifica]

ottiene il tipo dell'elemento specificato

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 modello di specializzazione) [modifica]

specializzata il tratto tipo 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 modello di specializzazione) [modifica]

segnaposto per saltare un elemento quando si scompatta un tuple utilizzando

tie

Original:

placeholder to skip an element when unpacking a tuple using

tie

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(costante) [modifica]

Esempio

#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