std::tie
De 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. |
<metanoindex/>
<tbody> </tbody>| Definido no cabeçalho <tuple>
|
||
template< class... Types > tuple<Types&...> tie( Types&... args ); |
(desde C++11) | |
Cria uma tupla de referências lvalue aos seus argumentos ou instâncias 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.
Parâmetros
| args | - | zero ou mais argumentos lvalue para construir a 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. |
Valor de retorno
Um objeto que contém
std::tuple lvalue referenes.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.
Exceções
Exemplo
std::tie pode ser utilizada para introduzir lexicographical comparação a uma estrutura ou a um tuplo descompactar:
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";
}
Saída:
Value was inserted sucessfully
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 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. (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) | |
espaço reservado para pular um elemento quando descompactar um tuple usando 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. (constante) |