std::forward_as_tuple
Da cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Definido no cabeçalho <tuple>
|
||
template< class... Types > tuple<Types...> forward_as_tuple( Types&&... args ); |
(desde C++11) | |
Constrói uma tupla de referências para os argumentos em
args
adequadas para encaminhar como um argumento para uma função. A tupla tem membros de dados de referência quando rvalue rvalues são usados como argumentos, e outra tem membros lvalue de dados de referência. Se rvalues são utilizados, o resultado desta função deve ser consumida antes do ponto de sequência seguinte.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.
Índice |
[editar] Parâmetros
args | - | zero ou mais argumentos para construir a tupla
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. |
[editar] Valor de retorno
Um objeto
std::tuple
criado como se por 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.
[editar] Exceções
[editar] Exemplo
#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); }
Saída:
m[10] = aaaaaaaaaaaaaaaaaaaa
cria um objeto tuple do tipo definido pelo tipo de argumentoOriginal: 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. (modelo de função) | |
cria um tuple de referências lvalue ou desempacota a tupla em objetos individuaisOriginal: 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. (modelo de função) | |
cria um tuple pela concatenação de qualquer número de tuplasOriginal: 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. (modelo de função) |