Namensräume
Varianten
Aktionen

std::reference_wrapper

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

 
 
 
Function-Objekte
Funktionswrapper
function(C++11)
mem_fn(C++11)
bad_function_call(C++11)
Bindung
bind(C++11)
is_bind_expression(C++11)
is_placeholder(C++11)
_1, _2, _3, ...(C++11)
Referenzwrapper
reference_wrapper(C++11)
ref
cref
(C++11)
(C++11)
Operatorwrapper
Verneinung
Veraltete Binder und Adapter
unary_function(veraltet)
binary_function(veraltet)
ptr_fun(veraltet)
pointer_to_unary_function(veraltet)
pointer_to_binary_function(veraltet)
mem_fun(veraltet)
mem_fun_t
mem_fun1_t
const_mem_fun_t
const_mem_fun1_t
(veraltet)
(veraltet)
(veraltet)
(veraltet)
mem_fun_ref(veraltet)
mem_fun_ref_t
mem_fun1_ref_t
const_mem_fun_ref_t
const_mem_fun1_ref_t
(veraltet)
(veraltet)
(veraltet)
(veraltet)
binder1st
binder2nd
(veraltet)
(veraltet)
bind1st
bind2nd
(veraltet)
(veraltet)
 
std::reference_wrapper
Member-Funktionen
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()
 
definiert in Header <functional>
template< class T >
class reference_wrapper;
(seit C++11)
Vorlage Klasse 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 .
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.
Hilfsfunktionen std::ref und std::cref werden oft verwendet, um std::reference_wrapper Objekte generieren .
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 wird auch verwendet, um Objekte zu std::bind oder an den Konstruktor std::thread durch Verweis übergeben .
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.

Inhaltsverzeichnis

[Bearbeiten] 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 wird ein Zeiger auf Elementfunktion der Klasse T0, die keine Argumente übernimmt, dann argument_type ist T0*, möglicherweise cv-qualified

3) wenn T ist ein Klasse Typ mit einem Mitglied Typs T::argument_type, dann argument_type ist ein Alias ​​dafür
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) 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 T wird ein Zeiger auf Elementfunktion der Klasse T0, die ein Argument, dann first_argument_type ist T0*, möglicherweise cv-qualified
3) wenn T ist ein Klasse Typ mit einem Mitglied Typs T::first_argument_type, dann first_argument_type ist ein Alias ​​dafür

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) 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 wird ein Zeiger auf Elementfunktion der Klasse T0, die ein Argument A1 nimmt, dann second_argument_type ist A1, möglicherweise cv-qualified

3) wenn T ist ein Klasse Typ mit einem Mitglied Typs T::second_argument_type, dann first_argument_type ist ein Alias ​​dafür
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.

[Bearbeiten] 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) [edit]
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) [edit]
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) [edit]
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) [edit]

[Bearbeiten] Beispiel

Zeigt die Verwendung von reference_wrapper als Behälter von Referenzen, die es ermöglichen, den gleichen Behälter unter Verwendung mehrerer Indizes zugreifen können
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

[Bearbeiten] Siehe auch

(C++11)
(C++11)
schafft eine std::reference_wrapper mit einer Art von Argument abgeleitet
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.

(Funktions-Template) [edit]
(C++11)
bindet ein oder mehrere Argumente an eine Funktion Objekt
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.

(Funktions-Template) [edit]