Showing content from https://cplusplus.com/reference_wrapper below:
class template
<functional>
std::reference_wrapper
template <class T> class reference_wrapper;
Reference wrapper
Class that emulates a reference to an element of type T, but which can be copied (it is both copy-constructible and copy-assignable).
Template parameters
-
T
-
Type of the referred element.
This can either be an object or a function.
Member types member type definition type The template parameter (T) result_type If T is a pointer to function or to member function type: the return type of T.
If T is a class, and has a result_type member: T::result_type
.
Otherwise, not defined. argument_type If T is a function type or a pointer to function type taking a single argument: the type of the argument taken by T.
If T is a pointer to member function: the class type of which T is a member (with the same const/volatile qualification as the member function).
If T is a class, and has an argument_type member: T::argument_type
.
Otherwise, not defined. first_argument_type If T is a function type or a pointer to function type taking two arguments: the type of the first argument taken by T.
If T is a pointer to member function taking a single argument: the class type of which T is a member (with the same const/volatile qualification as the member function).
If T is a class, and has a first_argument_type member: T::first_argument_type
.
Otherwise, not defined. second_argument_type If T is a function type or a pointer to function type taking two arguments: The type of the second argument taken by T.
If T is a pointer to member function taking a single argument: the argument taken by T.
If T is a class, and has a second_argument_type member: T::second_argument_type
.
Otherwise, not defined. Note that, except for type, the other member types are not always defined.
Member functions
-
(constructor)
-
Construct reference wrapper (public member function)
-
operator=
-
Copy assignment (public member function)
-
get
-
Access element (public member function)
-
operator()
-
Access element (functional form) (public member function)
-
operator type
-
Cast to reference (public member function)
Non-member helper functions
-
ref
-
Construct reference_wrapper (function template)
-
cref
-
Construct reference_wrapper to const (function template)
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// reference_wrapper example:
#include <iostream> // std::cout
#include <functional> // std::reference_wrapper
int main () {
int a(10),b(20),c(30);
// an array of "references":
std::reference_wrapper<int> refs[] = {a,b,c};
std::cout << "refs:";
for (int& x : refs) std::cout << ' ' << x;
std::cout << '\n';
return 0;
}
Possible output:
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4