20 General utilities library [utilities]

20.14 Function objects [function.objects]

20.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>
      constexpr reference_wrapper(U&&) noexcept(see below);
    constexpr reference_wrapper(const reference_wrapper& x) noexcept;

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

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

    // invocation
    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.
reference_­wrapper<T> is a trivially copyable type.
The template parameter T of reference_­wrapper may be an incomplete type.

20.14.5.1 Constructors and destructor [refwrap.const]

template<class U> constexpr 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<remove_­cvref_­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.
constexpr reference_wrapper(const reference_wrapper& x) noexcept;
Effects: Constructs a reference_­wrapper object that stores a reference to x.get().

20.14.5.2 Assignment [refwrap.assign]

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

20.14.5.3 Access [refwrap.access]

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

20.14.5.4 Invocation [refwrap.invoke]

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)...).

20.14.5.5 Helper functions [refwrap.helpers]

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;
Returns: ref(t.get()).
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;
Returns: cref(t.get()).

20.14.5.6 Transformation type trait unwrap_­reference [refwrap.unwrapref]

template<class T> struct unwrap_reference;
If T is a specialization reference_­wrapper<X> for some type X, the member typedef type of unwrap_­reference<T> is X&, otherwise it is T.
template<class T> struct unwrap_ref_decay;
The member typedef type of unwrap_­ref_­decay<T> denotes the type unwrap_­reference_­t<decay_­t<T>>.