File indexing completed on 2026-05-03 08:13:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___FUNCTIONAL_REFERENCE_WRAPPER_H
0011 #define _LIBCPP___CXX03___FUNCTIONAL_REFERENCE_WRAPPER_H
0012
0013 #include <__cxx03/__compare/synth_three_way.h>
0014 #include <__cxx03/__concepts/boolean_testable.h>
0015 #include <__cxx03/__config>
0016 #include <__cxx03/__functional/invoke.h>
0017 #include <__cxx03/__functional/weak_result_type.h>
0018 #include <__cxx03/__memory/addressof.h>
0019 #include <__cxx03/__type_traits/enable_if.h>
0020 #include <__cxx03/__type_traits/is_const.h>
0021 #include <__cxx03/__type_traits/remove_cvref.h>
0022 #include <__cxx03/__type_traits/void_t.h>
0023 #include <__cxx03/__utility/declval.h>
0024 #include <__cxx03/__utility/forward.h>
0025
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 # pragma GCC system_header
0028 #endif
0029
0030 _LIBCPP_BEGIN_NAMESPACE_STD
0031
0032 template <class _Tp>
0033 class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> {
0034 public:
0035
0036 typedef _Tp type;
0037
0038 private:
0039 type* __f_;
0040
0041 static void __fun(_Tp&) _NOEXCEPT;
0042 static void __fun(_Tp&&) = delete;
0043
0044 public:
0045 template <class _Up,
0046 class = __void_t<decltype(__fun(std::declval<_Up>()))>,
0047 __enable_if_t<!__is_same_uncvref<_Up, reference_wrapper>::value, int> = 0>
0048 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper(_Up&& __u)
0049 _NOEXCEPT_(noexcept(__fun(std::declval<_Up>()))) {
0050 type& __f = static_cast<_Up&&>(__u);
0051 __f_ = std::addressof(__f);
0052 }
0053
0054
0055 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 operator type&() const _NOEXCEPT { return *__f_; }
0056 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 type& get() const _NOEXCEPT { return *__f_; }
0057
0058
0059 template <class... _ArgTypes>
0060 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<type&, _ArgTypes...>::type
0061 operator()(_ArgTypes&&... __args) const
0062 #if _LIBCPP_STD_VER >= 17
0063
0064
0065 noexcept(is_nothrow_invocable_v<_Tp&, _ArgTypes...>)
0066 #endif
0067 {
0068 return std::__invoke(get(), std::forward<_ArgTypes>(__args)...);
0069 }
0070
0071 #if _LIBCPP_STD_VER >= 26
0072
0073
0074
0075 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, reference_wrapper __y)
0076 requires requires {
0077 { __x.get() == __y.get() } -> __boolean_testable;
0078 }
0079 {
0080 return __x.get() == __y.get();
0081 }
0082
0083 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, const _Tp& __y)
0084 requires requires {
0085 { __x.get() == __y } -> __boolean_testable;
0086 }
0087 {
0088 return __x.get() == __y;
0089 }
0090
0091 _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, reference_wrapper<const _Tp> __y)
0092 requires(!is_const_v<_Tp>) && requires {
0093 { __x.get() == __y.get() } -> __boolean_testable;
0094 }
0095 {
0096 return __x.get() == __y.get();
0097 }
0098
0099 _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(reference_wrapper __x, reference_wrapper __y)
0100 requires requires { std::__synth_three_way(__x.get(), __y.get()); }
0101 {
0102 return std::__synth_three_way(__x.get(), __y.get());
0103 }
0104
0105 _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(reference_wrapper __x, const _Tp& __y)
0106 requires requires { std::__synth_three_way(__x.get(), __y); }
0107 {
0108 return std::__synth_three_way(__x.get(), __y);
0109 }
0110
0111 _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(reference_wrapper __x, reference_wrapper<const _Tp> __y)
0112 requires(!is_const_v<_Tp>) && requires { std::__synth_three_way(__x.get(), __y.get()); }
0113 {
0114 return std::__synth_three_way(__x.get(), __y.get());
0115 }
0116
0117 #endif
0118 };
0119
0120 #if _LIBCPP_STD_VER >= 17
0121 template <class _Tp>
0122 reference_wrapper(_Tp&) -> reference_wrapper<_Tp>;
0123 #endif
0124
0125 template <class _Tp>
0126 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper<_Tp> ref(_Tp& __t) _NOEXCEPT {
0127 return reference_wrapper<_Tp>(__t);
0128 }
0129
0130 template <class _Tp>
0131 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper<_Tp>
0132 ref(reference_wrapper<_Tp> __t) _NOEXCEPT {
0133 return __t;
0134 }
0135
0136 template <class _Tp>
0137 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper<const _Tp> cref(const _Tp& __t) _NOEXCEPT {
0138 return reference_wrapper<const _Tp>(__t);
0139 }
0140
0141 template <class _Tp>
0142 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference_wrapper<const _Tp>
0143 cref(reference_wrapper<_Tp> __t) _NOEXCEPT {
0144 return __t;
0145 }
0146
0147 template <class _Tp>
0148 void ref(const _Tp&&) = delete;
0149 template <class _Tp>
0150 void cref(const _Tp&&) = delete;
0151
0152 _LIBCPP_END_NAMESPACE_STD
0153
0154 #endif