20 General utilities library [utilities]
20.14.5 Class template reference_wrapper [refwrap]
namespace std {
template<class T> class reference_wrapper {
public:
using type = T;
template<class U>
constexpr reference_wrapper(U&&) noexcept(see below);
constexpr reference_wrapper(const reference_wrapper& x) noexcept;
constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;
constexpr operator T& () const noexcept;
constexpr T& get() const noexcept;
template<class... ArgTypes>
constexpr invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&...) const;
};
template<class T>
reference_wrapper(T&) -> reference_wrapper<T>;
}
reference_wrapper<T> is a
Cpp17CopyConstructible and
Cpp17CopyAssignable wrapper
around a reference to an object or function of type
T. The template parameter
T of
reference_wrapper
may be an incomplete type
.template<class U>
constexpr reference_wrapper(U&& u) noexcept(see below);
Let
FUN denote the exposition-only functions
void FUN(T&) noexcept;
void FUN(T&&) = delete;
Constraints: The expression
FUN(declval<U>()) is well-formed and
is_same_v<remove_cvref_t<U>, reference_wrapper> is
false. Effects: Creates a variable
r
as if by
T& r = std::forward<U>(u),
then constructs a
reference_wrapper object
that stores a reference to
r. Remarks: The expression inside
noexcept
is equivalent to
noexcept(FUN(declval<U>())). constexpr reference_wrapper(const reference_wrapper& x) noexcept;
Effects: Constructs a
reference_wrapper object that
stores a reference to
x.get(). constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;
Postconditions: *this stores a reference to
x.get(). constexpr operator T& () const noexcept;
Returns: The stored reference
. constexpr T& get() const noexcept;
Returns: The stored reference
. template<class... ArgTypes>
constexpr invoke_result_t<T&, ArgTypes...>
operator()(ArgTypes&&... args) const;
Mandates: T is a complete type
. Returns: INVOKE(get(), std::forward<ArgTypes>(args)...). The template parameter
T of
the following
ref and
cref function templates
may be an incomplete type
. template<class T> constexpr reference_wrapper<T> ref(T& t) noexcept;
Returns: reference_wrapper<T>(t). template<class T> constexpr reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
template<class T> constexpr reference_wrapper<const T> cref(const T& t) noexcept;
Returns: reference_wrapper <const T>(t). template<class T> constexpr reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;