23 General utilities library [utilities]

23.14 Function objects [function.objects]

23.14.5 Class template reference_­wrapper [refwrap]

namespace std {
  template<class T> class reference_wrapper {
  public:
    // types
    using type = T;

    // construct/copy/destroy
    template<class U>
      reference_wrapper(U&&) noexcept(see below);
    reference_wrapper(const reference_wrapper& x) noexcept;

    // assignment
    reference_wrapper& operator=(const reference_wrapper& x) noexcept;

    // access
    operator T& () const noexcept;
    T& get() const noexcept;

    // invocation
    template<class... ArgTypes>
      invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&...) const;
  };
  template<class T>
    reference_wrapper(T&) -> reference_wrapper<T>;
}
reference_­wrapper<T> is a CopyConstructible and CopyAssignable wrapper around a reference to an object or function of type T.
reference_­wrapper<T> shall be a trivially copyable type.

23.14.5.1 reference_­wrapper construct/copy/destroy [refwrap.const]

template<class U> reference_wrapper(U&& u) noexcept(see below);
Remarks: Let FUN denote the exposition-only functions
void FUN(T&) noexcept;
void FUN(T&&) = delete;
This constructor shall not participate in overload resolution unless the expression FUN(declval<U>()) is well-formed and is_­same_­v<decay_­t<U>, reference_­wrapper> is false.
The expression inside noexcept is equivalent to noexcept(FUN(declval<U>())).
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.
reference_wrapper(const reference_wrapper& x) noexcept;
Effects: Constructs a reference_­wrapper object that stores a reference to x.get().

23.14.5.2 reference_­wrapper assignment [refwrap.assign]

reference_wrapper& operator=(const reference_wrapper& x) noexcept;
Postconditions: *this stores a reference to x.get().

23.14.5.3 reference_­wrapper access [refwrap.access]

operator T& () const noexcept;
Returns: The stored reference.
T& get() const noexcept;
Returns: The stored reference.

23.14.5.4 reference_­wrapper invocation [refwrap.invoke]

template<class... ArgTypes> invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&... args) const;
Returns: INVOKE(get(), std​::​forward<ArgTypes>(args)...).

23.14.5.5 reference_­wrapper helper functions [refwrap.helpers]

template<class T> reference_wrapper<T> ref(T& t) noexcept;
Returns: reference_­wrapper<T>(t).
template<class T> reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
Returns: ref(t.get()).
template<class T> reference_wrapper<const T> cref(const T& t) noexcept;
Returns: reference_­wrapper <const T>(t).
template<class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Returns: cref(t.get()).