std::tie
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. |
Elemento definito nell'header <tuple>
|
||
template< class... Types > tuple<Types&...> tie( Types&... args ); |
(dal C++11) | |
Crea una tupla di riferimenti lvalue alle sue argomentazioni o istanze di 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.
Indice |
[modifica] Parametri
args | - | zero o più argomenti lvalue per costruire la tupla da
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. |
[modifica] Valore di ritorno
Un oggetto che contiene
std::tuple
referenes 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.
[modifica] Eccezioni
[modifica] Esempio
std::tie può essere utilizzato per introdurre confronto lessicografico di una struttura o di estrarre 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.
#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.d return 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"; }
Output:
Value was inserted sucessfully
crea un oggetto tuple del tipo definito dai tipi di argomentiOriginal: 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. (funzione di modello) | |
crea un tuple di riferimenti 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. (funzione di modello) | |
crea un tuple concatenando un numero qualsiasi di tupleOriginal: 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. (funzione di modello) | |
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) |