std::reference_wrapper
![]() | Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate. La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
Definido en el archivo de encabezado <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 .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
objetos . 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 .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.
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 tipo de clase con un T::argument_type tipo de miembro, entonces argument_type es un alias de esoOriginal: 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) 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 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) 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 tipo de clase con un T::second_argument_type tipo de miembro, entonces first_argument_type es un alias de esoOriginal: 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. |
[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. (función miembro pública) | |
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. (función miembro pública) | |
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. (función miembro pública) | |
llama a la función almacenada (función miembro pública) |
[editar]Ejemplo
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';}
Salida:
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 un envoltorio de referencia (std::reference_wrapper) con un tipo deducido de su argumento. (plantilla de función) |
(C++11) | Vincula uno o más argumentos a un objeto función. (plantilla de función) |