Espacios de nombres
Variantes
Acciones

std::reference_wrapper

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

 
 
Utilidades de la biblioteca
Escriba apoyo (basic types, RTTI, type traits)
Gestión de memoria dinámica
Gestión de errores
Programa de servicios públicos
Funciones variadic
Fecha y hora
Objetos Function
initializer_list(C++11)
bitset
hash(C++11)
Operadores relacionales
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 y 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.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
Cambiar, hacia adelante y mover
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)
 
Objetos Function
Envoltorios de función
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)
Enlazar
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)
Envolturas de referencia
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)
Envoltorios 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.
Desaprobado aglutinantes y 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.
unary_function(obsoleto)
binary_function(obsoleto)
ptr_fun(obsoleto)
pointer_to_unary_function(obsoleto)
pointer_to_binary_function(obsoleto)
mem_fun(obsoleto)
mem_fun_t
mem_fun1_t
const_mem_fun_t
const_mem_fun1_t
(obsoleto)
(obsoleto)
(obsoleto)
(obsoleto)
mem_fun_ref(obsoleto)
mem_fun_ref_t
mem_fun1_ref_t
const_mem_fun_ref_t
const_mem_fun1_ref_t
(obsoleto)
(obsoleto)
(obsoleto)
(obsoleto)
binder1st
binder2nd
(obsoleto)
(obsoleto)
bind1st
bind2nd
(obsoleto)
(obsoleto)
 
std::reference_wrapper
Las funciones miembro
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()
 
Defined in header <functional>
template< class T >
class reference_wrapper;
(desde C++11)
std::reference_wrapper clase de plantilla es una CopyConstructible y la envoltura alrededor CopyAssignable una referencia al objeto o referencia a funcionar de T tipo. Las instancias de std::reference_wrapper son objetos (puede ser copiado o almacenado en contenedores), pero son implícitamente convertible a T&, de modo que puedan ser utilizados como argumentos con las funciones que toman el tipo subyacente por referencia .
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.
Las funciones de ayuda std::ref y std::cref se utilizan a menudo para generar 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 también se utiliza para pasar objetos a std::bind o al constructor de std::thread por referencia .
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.

Contenido

[editar] Tipos de miembros

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
El tipo de retorno de T si T es una función. De lo contrario, no definida
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) si T es una función o un puntero a una función que toma un argumento de tipo A1, entonces argument_type es A1.

2) si T es un puntero a función miembro de clase T0 que no toma ningún argumento, entonces es argument_type T0*, posiblemente cv-qualified

3) si T es un tipo de clase con un T::argument_type tipo de miembro, entonces argument_type es un alias de eso
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) si T es una función o un puntero a una función que toma dos argumentos de tipo s A1 A2 y, a continuación, first_argument_type es A1.

2) si T es un puntero a función miembro de clase T0 que toma un argumento, entonces es first_argument_type T0*, posiblemente cv-qualified
3) si T es un tipo de clase con un T::first_argument_type tipo de miembro, entonces first_argument_type es un alias de eso

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) si T es una función o un puntero a una función que toma dos argumentos de tipo s A1 A2 y, a continuación, second_argument_type es A2.

2) si T es un puntero a la función miembro de T0 clase que toma un argumento A1, entonces second_argument_type es A1, posiblemente cv-qualified

3) si T es un tipo de clase con un T::second_argument_type tipo de miembro, entonces first_argument_type es un alias de eso
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] Las funciones miembro

almacena una referencia a un objeto std::reference_wrapper nuevo
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.

(miembro público función) [edit]
vuelve a enlazar una 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.

(miembro público función) [edit]
accede a la referencia almacenada
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.

(miembro público función) [edit]
llama a la función almacenada
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.

(miembro público función) [edit]

[editar] Ejemplo

Muestra el uso de reference_wrapper como un contenedor de referencias, lo que hace posible acceder al mismo recipiente utilizando varios í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';
}

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

[editar] Ver también

(C++11)
(C++11)
crea una std::reference_wrapper con un tipo de deducir de su 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.

(función de plantilla) [edit]
(C++11)
se une uno o más argumentos a un objeto de función
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.

(función de plantilla) [edit]