std::forward_as_tuple
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...> forward_as_tuple( Types&&... args); | (dal C++11) | |
Costruisce una tupla di riferimenti agli argomenti in
args
adatti per la trasmissione come argomento di una funzione. La tupla ha rvalue membri dati di riferimento quando rvalues sono utilizzati come argomenti, e ha altrimenti lvalue membri dati di riferimento. Se rvalues vengono utilizzati, il risultato di questa funzione deve essere consumato prima del punto di sequenza successiva.Original:
Constructs a tuple of references to the arguments in
args
suitable for forwarding as an argument to a function. The tuple has rvalue reference data members when rvalues are used as arguments, and otherwise has lvalue reference data members. If rvalues are used, the result of this function must be consumed before the next sequence point.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 per costruire la tupla da Original: zero or more 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 creato
std::tuple
come per std::tuple<Types&&...>(std::forward<Types>(args)...)Original:
A
std::tuple
object created as if by std::tuple<Types&&...>(std::forward<Types>(args)...)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
#include <iostream>#include <map>#include <tuple>#include <string> int main(){std::map<int, std::string> m; // same as m.emplace(10, 20, 'a'); m.emplace(std::forward_as_tuple(10, std::string(20, 'a')));std::cout<<"m[10] = "<< m[10]<<'\n'; // The following is an error: it produces a// std::tuple<int&&, std::string&&> holding two dangling references.//// auto t = std::forward_as_tuple(10, std::string(20, 'a'));// m.emplace(t);}
Output:
m[10] = aaaaaaaaaaaaaaaaaaaa
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 lvalue o spacchetta una tupla in singoli oggettiOriginal: creates a tuple of lvalue references or unpacks a tuple into individual objectsThe 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) |