std::reference_wrapper
|
|
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. |
<metanoindex/>
<tbody> </tbody>| Elemento definito nell'header <functional>
|
||
template< class T > class reference_wrapper; |
(dal C++11) | |
std::reference_wrapper Class è un CopyConstructible e wrapper CopyAssignable intorno ad un riferimento all'oggetto o il riferimento per un funzionamento di tipo T. Istanze di std::reference_wrapper sono oggetti (può essere copiato o conservati in contenitori), ma sono implicitamente convertibile T&, in modo che possano essere utilizzati come argomenti con le funzioni che richiedono il tipo sottostante per riferimento.std::reference_wrapper is a CopyConstructible and CopyAssignable wrapper around a reference to object or reference to function of type T. Instances of std::reference_wrapper are objects (can be copied or stored in containers), but they are implicitly convertible to T&, so that they can be used as arguments with the functions that take the underlying type by reference.You can help to correct and verify the translation. Click here for instructions.
std::reference_wrapper oggetti. std::reference_wrapper objects. You can help to correct and verify the translation. Click here for instructions.
std::reference_wrapper viene utilizzato anche per passare gli oggetti di std::bind o al costruttore di std::thread di riferimento.std::reference_wrapper is also used to pass objects to std::bind or to the constructor of std::thread by reference.You can help to correct and verify the translation. Click here for instructions.
Membri tipi
tipo
Original: type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
definition |
type
|
T
|
result_type
|
Il tipo restituito di
T T se è una funzione. Altrimenti, non definito Original: The return type of T if T is a function. Otherwise, not defined The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
argument_type
|
1) se
T è una funzione o un puntatore a funzione che prende un argomento di tipo A1, allora argument_type è A1.2) se T è un tipo di classe con un T::argument_type tipo di membro, quindi argument_type è un alias di questoOriginal: 1) if T is a function or pointer to function that takes one argument of type A1, then argument_type is A1.2) if T is a class type with a member type T::argument_type, then argument_type is an alias of thatThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
first_argument_type
|
1) se
T è una funzione o un puntatore a funzione che prende due argomenti di tipo s A1 e A2, quindi first_argument_type è A1.2) se Original: 1) if T is a function or pointer to function that takes two arguments of type s A1 and A2, then first_argument_type is A1.2) if The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
second_argument_type
|
1) se
T è una funzione o un puntatore a funzione che prende due argomenti di tipo s A1 e A2, quindi second_argument_type è A2.2) se T è un tipo di classe con un T::second_argument_type tipo di membro, quindi first_argument_type è un alias di questoOriginal: 1) if T is a function or pointer to function that takes two arguments of type s A1 and A2, then second_argument_type is A2.2) if T is a class type with a member type T::second_argument_type, then first_argument_type is an alias of thatThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Membri funzioni
contiene un riferimento a un oggetto std::reference_wrapper nuovo Original: stores a reference in a new std::reference_wrapper object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
riassocia un std::reference_wrapper Original: rebinds a std::reference_wrapper The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
accede al riferimento memorizzato Original: accesses the stored reference The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
chiama la funzione memorizzato Original: calls the stored function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |
Esempio
You can help to correct and verify the translation. Click here for instructions.
#include <algorithm>
#include <list>
#include <vector>
#include <iostream>
#include <functional>
int main()
{
std::list<int> l = {-4, -3, -2, -1, 0, 1, 2, 3, 4};
std::vector<std::reference_wrapper<int>> v(l.begin(), l.end());
std::random_shuffle(v.begin(), v.end());
std::vector<std::reference_wrapper<int>> v2(v.begin(), v.end());
std::partition(v2.begin(), v2.end(), [](int n){return n<0;});
std::cout << "Contents of the list: ";
for(int n: l) {
std::cout << n << ' ';
}
std::cout << '\n';
std::cout << "Contents of the list, shuffled: ";
for(int i: v) {
std::cout << i << ' ';
}
std::cout << '\n';
std::cout << "Shuffled elements, partitioned: ";
for(int i: v2) {
std::cout << i << ' ';
}
std::cout << '\n';
}
Output:
Contents of the list: -4 -3 -2 -1 0 1 2 3 4
Contents of the list, shuffled: 0 -1 3 4 -4 1 -2 -3 2
Shuffled elements, partitioned: -3 -1 -2 -4 4 1 3 0 2
Vedi anche
(C++11) (C++11) |
crea un std::reference_wrapper con un tipo dedotta dal suo argomento Original: creates a std::reference_wrapper with a type deduced from its argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione di modello) |
(C++11) |
lega uno o più argomenti a un oggetto funzione Original: binds one or more arguments to a function object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione di modello) |