22 General utilities library [utilities] (original) (raw)
22.10 Function objects [function.objects]
22.10.6 Class template reference_wrapper [refwrap]
22.10.6.1 General [refwrap.general]
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 noexcept(is_nothrow_invocable_v<T&, ArgTypes...>);friend constexpr bool operator==(reference_wrapper, reference_wrapper);friend constexpr bool operator==(reference_wrapper, const T&);friend constexpr bool operator==(reference_wrapper, reference_wrapper<const T>);friend constexpr auto operator<=>(reference_wrapper, reference_wrapper);friend constexpr auto operator<=>(reference_wrapper, const T&);friend constexpr auto operator<=>(reference_wrapper, reference_wrapper<const T>);};template<class T> reference_wrapper(T&) -> reference_wrapper<T>;}
The template parameter T of reference_wrappermay be an incomplete type.
[Note 1:
Using the comparison operators described in [refwrap.comparisons]with T being an incomplete type can lead to an ill-formed program with no diagnostic required ([temp.point], [temp.constr.atomic]).
— _end note_]
22.10.6.2 Constructors [refwrap.const]
template<class U> constexpr reference_wrapper(U&& u) noexcept(_see below_);
Let FUN denote the exposition-only functionsvoid FUN(T&) noexcept;void FUN(T&&) = delete;
Constraints: The expression FUN(declval<U>()) is well-formed andis_same_v<remove_cvref_t<U>, reference_wrapper> is false.
Effects: Creates a variable ras if by T& r = std::forward<U>(u), then constructs a reference_wrapper object that stores a reference to r.
Remarks: The exception specification is equivalent tonoexcept(FUN(declval<U>())).
constexpr reference_wrapper(const reference_wrapper& x) noexcept;
Effects: Constructs a reference_wrapper object that stores a reference to x.get().
22.10.6.3 Assignment [refwrap.assign]
constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;
Postconditions: *this stores a reference to x.get().
22.10.6.4 Access [refwrap.access]
constexpr operator T& () const noexcept;
Returns: The stored reference.
constexpr T& get() const noexcept;
Returns: The stored reference.
22.10.6.5 Invocation [refwrap.invoke]
template<class... ArgTypes> constexpr invoke_result_t<T&, ArgTypes...> operator()(ArgTypes&&... args) const noexcept(is_nothrow_invocable_v<T&, ArgTypes...>);
Mandates: T is a complete type.
Returns: INVOKE(get(), std::forward<ArgTypes>(args)...) ([func.require]).
22.10.6.6 Comparisons [refwrap.comparisons]
friend constexpr bool operator==(reference_wrapper x, reference_wrapper y);
Constraints: The expression x.get() == y.get() is well-formed and its result is convertible to bool.
Returns: x.get() == y.get().
friend constexpr bool operator==(reference_wrapper x, const T& y);
Constraints: The expression x.get() == y is well-formed and its result is convertible to bool.
friend constexpr bool operator==(reference_wrapper x, reference_wrapper<const T> y);
Constraints: is_const_v<T> is false and the expression x.get() == y.get() is well-formed and its result is convertible to bool.
Returns: x.get() == y.get().
friend constexpr auto operator<=>(reference_wrapper x, reference_wrapper y);
Constraints: The expression synth-three-way(x.get(), y.get())is well-formed.
Returns: synth-three-way(x.get(), y.get()).
friend constexpr auto operator<=>(reference_wrapper x, const T& y);
Constraints: The expression synth-three-way(x.get(), y)is well-formed.
Returns: synth-three-way(x.get(), y).
friend constexpr auto operator<=>(reference_wrapper x, reference_wrapper<const T> y);
Constraints: is_const_v<T> is false.
The expression synth-three-way(x.get(), y.get())is well-formed.
Returns: synth-three-way(x.get(), y.get()).
22.10.6.7 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;
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;
22.10.6.8 common_reference related specializations [refwrap.common.ref]
namespace std { template<class T> constexpr bool is-ref-wrapper = false; template<class T> constexpr bool is-ref-wrapper<reference_wrapper<T>> = true;template<class R, class T, class RQ, class TQ> concept ref-wrap-common-reference-exists-with = is-ref-wrapper<R> && requires { typename common_reference_t<typename R::type&, TQ>; } && convertible_to<RQ, common_reference_t<typename R::type&, TQ>>;template<class R, class T, template<class> class RQual, template<class> class TQual> requires (ref-wrap-common-reference-exists-with<R, T, RQual<R>, TQual<T>> && <T, R, TQual<T>, RQual<R>>) struct basic_common_reference<R, T, RQual, TQual> { using type = common_reference_t<typename R::type&, TQual<T>>;};template<class T, class R, template<class> class TQual, template<class> class RQual> requires (ref-wrap-common-reference-exists-with<R, T, RQual<R>, TQual<T>> &&
<T, R, TQual<T>, RQual<R>>) struct basic_common_reference<T, R, TQual, RQual> { using type = common_reference_t<typename R::type&, TQual<T>>;};}