Namespace
Varianti

std::reference_wrapper

Da cppreference.com.
< cpp‎ | utility‎ | functional

 
 
Utilità libreria
Tipo di supporto (basic types, RTTI, type traits)
Gestione della memoria dinamica
La gestione degli errori
Programma di utilità
Funzioni variadic
Data e ora
Funzione oggetti
initializer_list(C++11)
bitset
hash(C++11)
Gli operatori relazionali
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
Coppie e tuple
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
Swap, in avanti e spostare
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
Funzione oggetti
Funzione wrapper
Original:
Function wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
function(C++11)
mem_fn(C++11)
bad_function_call(C++11)
Associare
Original:
Bind
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
bind(C++11)
is_bind_expression(C++11)
is_placeholder(C++11)
_1, _2, _3, ...(C++11)
Wrapper di riferimento
Original:
Reference wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
reference_wrapper(C++11)
ref
cref
(C++11)
(C++11)
Operatore wrapper
Original:
Operator wrappers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Negatori
Original:
Negators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Sconsigliata a leganti e adattatori
Original:
Deprecated binders and adaptors
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unary_function(deprecato)
binary_function(deprecato)
ptr_fun(deprecato)
pointer_to_unary_function(deprecato)
pointer_to_binary_function(deprecato)
mem_fun(deprecato)
mem_fun_t
mem_fun1_t
const_mem_fun_t
const_mem_fun1_t
(deprecato)
(deprecato)
(deprecato)
(deprecato)
mem_fun_ref(deprecato)
mem_fun_ref_t
mem_fun1_ref_t
const_mem_fun_ref_t
const_mem_fun1_ref_t
(deprecato)
(deprecato)
(deprecato)
(deprecato)
binder1st
binder2nd
(deprecato)
(deprecato)
bind1st
bind2nd
(deprecato)
(deprecato)
 
std::reference_wrapper
Membri funzioni
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.
reference_wrapper::reference_wrapper
reference_wrapper::operator=
reference_wrapper::get
reference_wrapper::operator T&
reference_wrapper::operator()
 
Elemento definito nell'header <functional>
template< class T >
class reference_wrapper;
(dal C++11)
Modello 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.
Original:
Class template 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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funzioni di supporto e std::ref std::cref sono spesso utilizzati per generare std::reference_wrapper oggetti.
Original:
Helper functions std::ref and std::cref are often used to generate std::reference_wrapper objects.
The text has been machine-translated via Google Translate.
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.
Original:
std::reference_wrapper is also used to pass objects to std::bind or to the constructor of std::thread by reference.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Indice

[modifica] 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 puntatore a funzione membro di T0 classe che non accetta argomenti, quindi è argument_type T0*, possibilmente cv-qualified

3) se T è un tipo di classe con un T::argument_type tipo di membro, quindi argument_type è un alias di questo
Original:
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 pointer to member function of class T0 that takes no arguments, then argument_type is T0*, possibly cv-qualified

3) if T is a class type with a member type T::argument_type, then argument_type is an alias of that
The 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 T è un puntatore a funzione membro di T0 classe che accetta un argomento, allora è first_argument_type T0*, possibilmente cv-qualified
3) se T è un tipo di classe con un T::first_argument_type tipo di membro, quindi first_argument_type è un alias di questo

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 T is a pointer to member function of class T0 that takes one argument, then first_argument_type is T0*, possibly cv-qualified
3) if T is a class type with a member type T::first_argument_type, then first_argument_type is an alias of that

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 puntatore a funzione membro di T0 classe che accetta un A1 argomento, allora è second_argument_type A1, possibilmente cv-qualified

3) se T è un tipo di classe con un T::second_argument_type tipo di membro, quindi first_argument_type è un alias di questo
Original:
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 pointer to member function of class T0 that takes one argument A1, then second_argument_type is A1, possibly cv-qualified

3) if T is a class type with a member type T::second_argument_type, then first_argument_type is an alias of that
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica] 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) [modifica]
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) [modifica]
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) [modifica]
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) [modifica]

[modifica] Esempio

Dimostra l'uso di reference_wrapper come contenitore di riferimenti, che consente di accedere al contenitore stesso tramite più indici
Original:
Demonstrates the use of reference_wrapper as a container of references, which makes it possible to access the same container using multiple indexes
The text has been machine-translated via Google Translate.
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

[modifica] 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) [modifica]
(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) [modifica]