Espacios de nombres
Variantes
Acciones

std::tuple::tuple

De cppreference.com
< cpp‎ | utility‎ | tuple
 
 
Biblioteca de servicios
 
std::tuple
Funciones miembro
tuple::tuple
Funciones no miembro
(hasta C++20)(hasta C++20)(hasta C++20)(hasta C++20)(hasta C++20)(C++20)
Guías de deducción(C++17)
Clases asistentes
 
Definido en el archivo de encabezado <tuple>
constexpr tuple();
(1) (desde C++11)
(condicionalmente explícito)
tuple( const Types&... args );
(2) (desde C++11)
(constexpr desde C++14)
(condicionalmente explícito)
template< class... UTypes >
tuple( UTypes&&... args );
(3) (desde C++11)
(constexpr desde C++14)
(condicionalmente explícito)
template< class... UTypes >
tuple( const tuple<UTypes...>& other );
(4) (desde C++11)
(constexpr desde C++14)
(condicionalmente explícito)
template <class... UTypes>
tuple( tuple<UTypes...>&& other );
(5) (desde C++11)
(constexpr desde C++14)
(condicionalmente explícito)
template< class U1, class U2 >
tuple( const pair<U1,U2>& p );
(6) (desde C++11)
(constexpr desde C++14)
(condicionalmente explícito)
template< class U1, class U2 >
tuple( pair<U1,U2>&& p );
(7) (desde C++11)
(constexpr desde C++14)
(condicionalmente explícito)
tuple( const tuple& other ) = default;
(8) (desde C++11)
tuple( tuple&& other ) = default;
(9) (desde C++11)
template< class Alloc >
tuple( std::allocator_arg_t, const Alloc& a );
(10) (desde C++11)
(constexpr desde C++20)
(condicionalmente explícito)
template< class Alloc >

tuple( std::allocator_arg_t, const Alloc& a,

       const Types&... args );
(11) (desde C++11)
(constexpr desde C++20)
(condicionalmente explícito)
template< class Alloc, class... UTypes >

tuple( std::allocator_arg_t, const Alloc& a,

       UTypes&&... args );
(12) (desde C++11)
(constexpr desde C++20)
(condicionalmente explícito)
template <class Alloc, class... UTypes>

tuple( std::allocator_arg_t, const Alloc& a,

       const tuple<UTypes...>& other );
(13) (desde C++11)
(constexpr desde C++20)
(condicionalmente explícito)
template< class Alloc, class... UTypes >

tuple( std::allocator_arg_t, const Alloc& a,

       tuple<UTypes...>&& other );
(14) (desde C++11)
(constexpr desde C++20)
(condicionalmente explícito)
template< class Alloc, class U1, class U2 >

tuple( std::allocator_arg_t, const Alloc& a,

       const pair<U1, U2>& p );
(15) (desde C++11)
(constexpr desde C++20)
(condicionalmente explícito)
template< class Alloc, class U1, class U2 >

tuple( std::allocator_arg_t, const Alloc& a,

       pair<U1, U2>&& p );
(16) (desde C++11)
(constexpr desde C++20)
(condicionalmente explícito)
template< class Alloc >

tuple( std::allocator_arg_t, const Alloc& a,

       const tuple& other );
(17) (desde C++11)
(constexpr desde C++20)
template< class Alloc >

tuple( std::allocator_arg_t, const Alloc& a,

       tuple&& other );
(18) (desde C++11)
(constexpr desde C++20)
Crea una nueva tupla .
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.
1)
Por defecto constructor. Valor inicializa todos los elementos .
Original:
Default constructor. Value-initializes all elements.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
Inicializa cada elemento de la tupla con el parámetro correspondiente .
Original:
Initializes each element of the tuple with the corresponding parameter.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
Inicializa cada elemento de la tupla con el valor correspondiente en std::forward<Utypes>(args) .
Original:
Initializes each element of the tuple with the corresponding value in std::forward<Utypes>(args).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
Para todos i en sizeof...(UTypes), inicializa i-ésimo elemento de la tupla con std::get<i>(other) .
Original:
For all i in sizeof...(UTypes), initializes ith element of the tuple with std::get<i>(other).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
Para todos i en sizeof...(UTypes), inicializa i-ésimo elemento de la tupla con std::forward<Ui>(std::get<i>(other)) .
Original:
For all i in sizeof...(UTypes), initializes ith element of the tuple with std::forward<Ui>(std::get<i>(other)).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
Construye una tupla 2-elemento con el primer elemento construido a partir de p.first y el segundo elemento de p.second
Original:
Constructs a 2-element tuple with the first element constructed from p.first and the second element from p.second
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7)
Construye una tupla 2-elemento con el primer elemento construido a partir de std::forward<U1>(p.first) y el segundo elemento de std::forward<U2>(p.second)
Original:
Constructs a 2-element tuple with the first element constructed from std::forward<U1>(p.first) and the second element from std::forward<U2>(p.second)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
8)
Generado por el compilador constructor de copia. Inicializa cada elemento de la tupla con el elemento correspondiente de other
Original:
Compiler-generated copy constructor. Initializes each element of the tuple with the corresponding element of other
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
9)
Generado por el compilador constructor movimiento. Inicializa cada i-ésimo elemento de la tupla con std::forward<Ui>(std::get<i>(other)) .
Original:
Compiler-generated move constructor. Initializes each ith element of the tuple with std::forward<Ui>(std::get<i>(other)).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
10 a 18) Idéntica a 01.09, excepto que cada elemento es creado por' usos construcción-repartidor, es decir, se pasa el objeto a Becario como un argumento adicional para el constructor de cada elemento para el que std::uses_allocator<Ui, Alloc>::value es true .
Original:
10 - 18) Identical to 1-9 except each element is created by uses-allocator construction, that is, the Allocator object a is passed as an additional argument to the constructor of each element for which std::uses_allocator<Ui, Alloc>::value is true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Parámetros

args - Los valores utilizados para inicializar cada elemento de la tupla.
other - Una tupla de valores que se utilizan para inicializar cada elemento de la tupla.
p - Par de valores que se utilizan para inicializar los dos elementos de esta tupla de dos.
a - Asignador a utilizar en la construcción que usa asignadores.

[editar] Ejemplo

#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <memory>
 
// helper function to print a tuple of any size
template<class Tuple, std::size_t N>
struct TuplePrinter {
    static void print(const Tuple& t) 
    {
        TuplePrinter<Tuple, N-1>::print(t);
        std::cout << ", " << std::get<N-1>(t);
    }
};
 
template<class Tuple>
struct TuplePrinter<Tuple, 1>{
    static void print(const Tuple& t) 
    {
        std::cout << std::get<0>(t);
    }
};
 
template<class... Args>
void print(const std::tuple<Args...>& t) 
{
    std::cout << "(";
    TuplePrinter<decltype(t), sizeof...(Args)>::print(t);
    std::cout << ")\n";
}
// end helper function
 
int main()
{
    std::tuple<int, std::string, double> t1;
    std::cout << "Value-initialized: "; print(t1);
    std::tuple<int, std::string, double> t2(42, "Test", -3.14);
    std::cout << "Initialized with values: "; print(t2);
    std::tuple<char, std::string, int> t3(t2);
    std::cout << "Implicitly converted: "; print(t3);
    std::tuple<int, double> t4(std::make_pair(42, 3.14));
    std::cout << "Constructed from a pair"; print(t4);
 
    // given Allocator my_alloc with a single-argument constructor my_alloc(int)
    // use my_alloc(1) to allocate 10 ints in a vector
    std::vector<int, my_alloc> v(10, 1, my_alloc(1));
    // use my_alloc(2) to allocate 10 ints in a vector in a tuple
    std::tuple<int, std::vector<int, my_alloc>, double> t5(std::allocator_arg,
                                                           my_alloc(2), 42, v,  -3.14);
}

Salida:

Value-initialized: (0, , 0)
Initialized with values: (42, Test, -3.14)
Implicitly converted: (*, Test, -3)
Constructed from a pair(42, 3.14)

[editar] Véase también

Crea un objeto de tupla del tipo definido por los tipos de argumentos.
(plantilla de función) [editar]
Crea una tupla de referencias lvalue o desempaca una tupla en objetos individuales.
(plantilla de función) [editar]
Crea una tupla de referencias r-valor.
(plantilla de función) [editar]