std::reference_wrapper::reference_wrapper

From cppreference.com
 
 
 
Function objects
Function wrappers
(C++11)
(C++11)
Bind
(C++11)
Function invocation
(C++17)
Reference wrappers
(C++11)(C++11)
Operator wrappers
Negators
(deprecated)
(deprecated)

(deprecated)
(deprecated)
Searchers
Old binders and adaptors
(until C++17)
(until C++17)
(until C++17)
(until C++17)
(until C++17)(until C++17)(until C++17)(until C++17)
(until C++17)(until C++17)
(until C++17)(until C++17)

(until C++17)
(until C++17)(until C++17)(until C++17)(until C++17)
 
 
(1)
reference_wrapper( T& x ) noexcept;
reference_wrapper( T&& x ) = delete;
(until C++20)
template< class U >
reference_wrapper( U&& x ) noexcept(/*see below*/) ;
(since C++20)
reference_wrapper( const reference_wrapper& other ) noexcept;
(2)

Constructs a new reference wrapper.

1) Stores a reference to x. Construction from a temporary object is not allowed.

(until C++20)

1) Converts x to T& as if by T& t = std::forward<U>(x);, then stores a reference to t. This overload only participates in overload resolution if std::is_same_v<std::remove_cvref_t<U>, reference_wrapper> is false and the expression FUN(std::declval<U>()) is well-formed, where FUN names the set of imaginary functions

void FUN(T&) noexcept;
void FUN(T&&) = delete;
(since C++20)

2) Copy constructor. Stores a reference to other.get().

Parameters

x - an object to wrap
other - another reference wrapper

Exceptions

1)
noexcept specification:  
noexcept(noexcept(FUN(std::declval<U>())))
where FUN is the set of imaginary functions described in the description above.
(since C++20)

Notes

The pre-C++20 deleted constructor from T&& still participates in the formation of implicit conversion sequences, which can lead to unexpected results in overload resolution. The C++20 change (via LWG issue 2993) rectifies this problem.