std::tie
De cppreference.com
![]() | Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate. La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
Definido en el archivo de encabezado <tuple> | ||
template<class... Types> tuple<Types&...> tie( Types&... args); | (desde C++11) | |
Crea una tupla de referencias lvalue a sus argumentos o instancias de std::ignore .
Original:
Creates a tuple of lvalue references to its arguments or instances of std::ignore.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Contenido |
[editar]Parámetros
args | - | cero o más argumentos lvalue para la construcción de la tupla Original: zero or more lvalue arguments to construct the tuple from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[editar]Valor de retorno
Un objeto que contiene referencias al respecto
std::tuple
lvalue .Original:
A
std::tuple
object containing lvalue referenes.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar]Excepciones
[editar]Ejemplo
std::tie se puede utilizar para introducir lexicográfico comparación con una estructura o desempaquetar una tupla:
Original:
std::tie can be used to introduce lexicographical comparison to a struct or to unpack a tuple:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ejecuta este código
#include <iostream>#include <string>#include <set>#include <tuple> struct S {int n;std::string s;float d;bool operator<(const S& rhs)const{// compares n to rhs.n,// then s to rhs.s,// then d to rhs.dreturn std::tie(n, s, d)< std::tie(rhs.n, rhs.s, rhs.d);}}; int main(){std::set<S> set_of_s;// S is LessThanComparable S value{42, "Test", 3.14};std::set<S>::iterator iter;bool inserted;// unpacks the return value of insert into iter and inserted std::tie(iter, inserted)= set_of_s.insert(value);if(inserted)std::cout<<"Value was inserted sucessfully\n";}
Salida:
Value was inserted sucessfully
Crea un objeto de tupla del tipo definido por los tipos de argumentos. (plantilla de función) | |
Crea una tupla de referencias r-valor. (plantilla de función) | |
Crea una tupla mediante la concatenación de cualquier número de tuplas. (plantilla de función) | |
Marcador de posición para saltarse un elemento cuando se desempaca una tupla utilizando tie. (constante) |