Espaços nominais
Variantes
Acções

std::reference_wrapper

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

 
 
Biblioteca de utilitários
Digite apoio (basic types, RTTI, type traits)
Gerenciamento de memória dinâmica
De tratamento de erros
Utilidades do programa
Variadic funções
Data e hora
Objetos de função
(C++11)
Os operadores relacionais
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>=
Pares e tuplas
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.
(C++11)
Troque, avançar e avançar
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.
(C++11)
(C++11)
(C++11)
 
Objetos de função


Invólucros de função
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.
(C++11)
(C++11)
Ligar
Original:
Bind
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Invólucros de referência
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)
(C++11)(C++11)
Invólucros operador
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.
Negadores
Original:
Negators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Obsoleta ligantes e adaptadores
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.
(obsoleta)
(obsoleta)
(obsoleta)
(obsoleta)
(obsoleta)(obsoleta)(obsoleta)(obsoleta)
(obsoleta)
(obsoleta)(obsoleta)
(obsoleta)(obsoleta)
 
std::reference_wrapper
Funções de membro
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()
 
Definido no cabeçalho <functional>
template<class T >
class reference_wrapper;
(desde C++11)
std::reference_wrapper modelo de classe é um CopyConstructible e wrapper CopyAssignable em torno de uma referência ao objeto ou referência a funcionar de T tipo. Instâncias de std::reference_wrapper são objectos (podem ser copiados ou armazenados em recipientes), mas são implicitamente conversível T&, de modo que eles podem ser usados ​​como argumentos com as funções que o tipo subjacente por referência.
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.
Funções auxiliares std::ref e std::cref são muitas vezes utilizados para gerar std::reference_wrapper objetos.
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 também é usado para passar objetos para std::bind ou para o construtor de std::thread por referência.
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.

Índice

[editar]Tipos de membro

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
typeT
result_type
O tipo de retorno T se T é uma função. Caso contrário, não definido
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 é uma função ou ponteiro para função que recebe um argumento do tipo A1, então argument_type é A1.

2) se T é um ponteiro para função de membro de T0 classe que não tem argumentos, então argument_type é T0*, possivelmente cv-qualified

3) se T é um tipo de classe com um tipo T::argument_type membro, então argument_type é um apelido para isso
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 é uma função ou ponteiro para função que recebe dois argumentos do tipo s A1 e A2, então first_argument_type é A1.

2) se T é um ponteiro para função de membro de T0 classe que tem um argumento, então é first_argument_typeT0*, possivelmente cv-qualified
3) se T é um tipo de classe com um tipo T::first_argument_type membro, então first_argument_type é um apelido para isso

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 é uma função ou ponteiro para função que recebe dois argumentos do tipo s A1 e A2, então second_argument_type é A2.

2) se T é um ponteiro para função de membro de T0 classe que leva um A1 argumento, então é second_argument_typeA1, possivelmente cv-qualified

3) se T é um tipo de classe com um tipo T::second_argument_type membro, então first_argument_type é um apelido para isso
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.

[editar]Funções de membro

armazena uma referência num objecto std::reference_wrapper novo
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.

(função pública membro)[edit]
religa um 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.

(função pública membro)[edit]
acessa a referência armazenada
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.

(função pública membro)[edit]
chama a função armazenada
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.

(função pública membro)[edit]

[editar]Exemplo

Demonstra o uso de um recipiente como reference_wrapper de referências, o que torna possível o acesso ao mesmo recipiente utilizando vários índices
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';}

Saída:

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

[editar]Veja também

(C++11)
(C++11)
cria um std::reference_wrapper com um tipo de deduzir o seu argumento
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.

(modelo de função)[edit]
(C++11)
se liga um ou mais argumentos para um objeto de função
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.

(modelo de função)[edit]
close