Espaces de noms
Variantes
Affichages
Actions

std::tie

De cppreference.com
< cpp‎ | utility‎ | tuple

 
 
 
std::tuple
Les fonctions membres
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tuple::tuple
tuple::operator=
tuple::swap
Tiers fonctions
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
make_tuple
tie
forward_as_tuple
None
operator=
operator!=
operator<
operator<=
operator>
operator>=
std::swap
get
Classes d'aide
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tuple_size
tuple_element
uses_allocator
ignore
 
Defined in header <tuple>
template< class... Types >
tuple<Types&...> tie( Types&... args );
(depuis C++11)
Crée un tuple de références lvalue à ses arguments ou des instances 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.

Sommaire

[modifier] Paramètres

args -
zéro ou plusieurs arguments lvalue pour construire le tuple
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.

[modifier] Retourne la valeur

Un objet contenant 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.

[modifier] Exceptions

noexcept specification:  
noexcept
   (depuis C++11)

[modifier] Exemple

std::tie peut être utilisé pour introduire comparaison lexicographique à une structure ou à déballer un tuple:
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.

#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";
}

Résultat :

Value was inserted sucessfully
crée un objet tuple du type défini par les types d'arguments
Original:
creates a tuple object of the type defined by the argument types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction générique) [edit]
crée un tuple des références rvalue
Original:
creates a tuple of rvalue references
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction générique) [edit]
crée un tuple en concaténant un certain nombre de tuples
Original:
creates a tuple by concatenating any number of tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction générique) [edit]
valeur réservée pour sauter un élément lorsque vous déballez un tuple utilisant tie
(constante) [edit]