std::tie
Aus 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. |
definiert in Header <tuple> | ||
template<class... Types> tuple<Types&...> tie( Types&... args); | (seit C++11) | |
Erstellt einen Tupel lvalue Verweise auf seine Argumente oder Instanzen von 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.
Inhaltsverzeichnis |
[Bearbeiten]Parameter
args | - | null oder mehr lvalue Argumente, um die Tupel aus zu bauen 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. |
[Bearbeiten]Rückgabewert
A
std::tuple
Objekt mit 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.
[Bearbeiten]Ausnahmen
[Bearbeiten]Beispiel
std::tie können verwendet werden, um die Einführung lexikographische Vergleich zu einer Struktur oder ein Tupel auszupacken werden:
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.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";}
Output:
Value was inserted sucessfully
erzeugt eine tuple Objekt des Typs von den Argumenttypen definiertOriginal: 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. (Funktions-Template) | |
erzeugt ein tuple aus rvalue ReferenzenOriginal: 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. (Funktions-Template) | |
erzeugt ein tuple durch Verketten einer beliebigen Anzahl von TupelnOriginal: 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. (Funktions-Template) | |
Platzhalter, um ein Element zu überspringen, wenn Auspacken einer tuple mit tieOriginal: placeholder to skip an element when unpacking a tuple using tieThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (konstanten) |