std::reference_wrapper
<metanoindex/>
<tbody> </tbody>| definiert in Header <functional>
|
||
template< class T > class reference_wrapper; |
(seit C++11) | |
std::reference_wrapper ist ein CopyConstructible und CopyAssignable Wrapper um einen Verweis auf Objekt oder auf der Art T funktionieren. Instanzen std::reference_wrapper sind Objekte (kann kopiert oder gespeichert werden in Containern), aber sie sind implizit konvertierbar T&, so dass sie als Argumente mit den Funktionen, die den zugrunde liegenden Typ nehmen durch Bezugnahme verwendet werden kann .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 Objekte generieren . std::reference_wrapper objects. You can help to correct and verify the translation. Click here for instructions.
std::reference_wrapper wird auch verwendet, um Objekte zu std::bind oder an den Konstruktor std::thread durch Verweis übergeben .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.
Mitglied Typen
Typ
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
|
Der Rückgabetyp
T wenn T ist eine Funktion. Andernfalls nicht definiert 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) wenn
T wird eine Funktion oder ein Zeiger auf eine Funktion, die ein Argument vom Typ A1 nimmt, dann argument_type ist A1.2) wenn T ist ein Klasse Typ mit einem Mitglied Typs T::argument_type, dann argument_type ist ein Alias dafürOriginal: 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) wenn
T wird eine Funktion oder ein Zeiger auf eine Funktion, die zwei Argumente vom Typ s dauert A1 und A2, dann first_argument_type ist A1.2) wenn 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) wenn
T wird eine Funktion oder ein Zeiger auf eine Funktion, die zwei Argumente vom Typ s dauert A1 und A2, dann second_argument_type ist A2.2) wenn T ist ein Klasse Typ mit einem Mitglied Typs T::second_argument_type, dann first_argument_type ist ein Alias dafürOriginal: 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. |
Member-Funktionen
speichert einen Verweis in einem neuen std::reference_wrapper Objekt 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. (öffentliche Elementfunktion) | |
Rebinds eine 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. (öffentliche Elementfunktion) | |
greift auf die gespeicherten Referenzdaten 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. (öffentliche Elementfunktion) | |
ruft die gespeicherte Funktion 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. (öffentliche Elementfunktion) | |
Beispiel
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
