30#ifndef _GLIBCXX_REFWRAP_H
31#define _GLIBCXX_REFWRAP_H 1
33#pragma GCC system_header
35#if __cplusplus < 201103L
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
54 template<
typename _Res,
typename... _ArgTypes>
55 struct _Maybe_unary_or_binary_function { };
58 template<
typename _Res,
typename _T1>
59 struct _Maybe_unary_or_binary_function<_Res, _T1>
63 template<
typename _Res,
typename _T1,
typename _T2>
64 struct _Maybe_unary_or_binary_function<_Res, _T1, _T2>
67 template<
typename _Signature>
68 struct _Mem_fn_traits;
70 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
71 struct _Mem_fn_traits_base
73 using __result_type = _Res;
75 = _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...>;
76 using __arity = integral_constant<size_t,
sizeof...(_ArgTypes)>;
79#define _GLIBCXX_MEM_FN_TRAITS2(_CV, _REF, _LVAL, _RVAL) \
80 template<typename _Res, typename _Class, typename... _ArgTypes> \
81 struct _Mem_fn_traits<_Res (_Class::*)(_ArgTypes...) _CV _REF> \
82 : _Mem_fn_traits_base<_Res, _CV _Class, _ArgTypes...> \
84 using __vararg = false_type; \
86 template<typename _Res, typename _Class, typename... _ArgTypes> \
87 struct _Mem_fn_traits<_Res (_Class::*)(_ArgTypes... ...) _CV _REF> \
88 : _Mem_fn_traits_base<_Res, _CV _Class, _ArgTypes...> \
90 using __vararg = true_type; \
93#define _GLIBCXX_MEM_FN_TRAITS(_REF, _LVAL, _RVAL) \
94 _GLIBCXX_MEM_FN_TRAITS2( , _REF, _LVAL, _RVAL) \
95 _GLIBCXX_MEM_FN_TRAITS2(const , _REF, _LVAL, _RVAL) \
96 _GLIBCXX_MEM_FN_TRAITS2(volatile , _REF, _LVAL, _RVAL) \
97 _GLIBCXX_MEM_FN_TRAITS2(const volatile, _REF, _LVAL, _RVAL)
103#if __cplusplus > 201402L
109#undef _GLIBCXX_MEM_FN_TRAITS
110#undef _GLIBCXX_MEM_FN_TRAITS2
113 template<
typename _Functor,
typename = __
void_t<>>
114 struct _Maybe_get_result_type
117 template<
typename _Functor>
118 struct _Maybe_get_result_type<_Functor,
119 __void_t<typename _Functor::result_type>>
120 {
typedef typename _Functor::result_type result_type; };
126 template<
typename _Functor>
127 struct _Weak_result_type_impl
128 : _Maybe_get_result_type<_Functor>
132 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
133 struct _Weak_result_type_impl<_Res(_ArgTypes...) _GLIBCXX_NOEXCEPT_QUAL>
134 {
typedef _Res result_type; };
137 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
138 struct _Weak_result_type_impl<_Res(_ArgTypes......) _GLIBCXX_NOEXCEPT_QUAL>
139 {
typedef _Res result_type; };
142 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
143 struct _Weak_result_type_impl<_Res(*)(_ArgTypes...) _GLIBCXX_NOEXCEPT_QUAL>
144 {
typedef _Res result_type; };
147 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
149 _Weak_result_type_impl<_Res(*)(_ArgTypes......) _GLIBCXX_NOEXCEPT_QUAL>
150 {
typedef _Res result_type; };
153 template<
typename _Functor,
154 bool = is_member_function_pointer<_Functor>::value>
155 struct _Weak_result_type_memfun
156 : _Weak_result_type_impl<_Functor>
160 template<
typename _MemFunPtr>
161 struct _Weak_result_type_memfun<_MemFunPtr, true>
163 using result_type =
typename _Mem_fn_traits<_MemFunPtr>::__result_type;
167 template<
typename _Func,
typename _Class>
168 struct _Weak_result_type_memfun<_Func _Class::*, false>
175 template<
typename _Functor>
176 struct _Weak_result_type
177 : _Weak_result_type_memfun<typename remove_cv<_Functor>::type>
180#if __cplusplus <= 201703L
182 template<
typename _Tp,
typename = __
void_t<>>
183 struct _Refwrap_base_arg1
187 template<
typename _Tp>
188 struct _Refwrap_base_arg1<_Tp,
189 __void_t<typename _Tp::argument_type>>
191 typedef typename _Tp::argument_type argument_type;
195 template<
typename _Tp,
typename = __
void_t<>>
196 struct _Refwrap_base_arg2
200 template<
typename _Tp>
201 struct _Refwrap_base_arg2<_Tp,
202 __void_t<typename _Tp::first_argument_type,
203 typename _Tp::second_argument_type>>
205 typedef typename _Tp::first_argument_type first_argument_type;
206 typedef typename _Tp::second_argument_type second_argument_type;
215 template<
typename _Tp>
216 struct _Reference_wrapper_base
217 : _Weak_result_type<_Tp>, _Refwrap_base_arg1<_Tp>, _Refwrap_base_arg2<_Tp>
221 template<
typename _Res,
typename _T1 _GLIBCXX_NOEXCEPT_PARM>
222 struct _Reference_wrapper_base<_Res(_T1) _GLIBCXX_NOEXCEPT_QUAL>
223 : unary_function<_T1, _Res>
226 template<
typename _Res,
typename _T1>
227 struct _Reference_wrapper_base<_Res(_T1) const>
228 : unary_function<_T1, _Res>
231 template<
typename _Res,
typename _T1>
232 struct _Reference_wrapper_base<_Res(_T1) volatile>
233 : unary_function<_T1, _Res>
236 template<
typename _Res,
typename _T1>
237 struct _Reference_wrapper_base<_Res(_T1) const volatile>
238 : unary_function<_T1, _Res>
242 template<
typename _Res,
typename _T1,
typename _T2 _GLIBCXX_NOEXCEPT_PARM>
243 struct _Reference_wrapper_base<_Res(_T1, _T2) _GLIBCXX_NOEXCEPT_QUAL>
244 : binary_function<_T1, _T2, _Res>
247 template<
typename _Res,
typename _T1,
typename _T2>
248 struct _Reference_wrapper_base<_Res(_T1, _T2) const>
249 : binary_function<_T1, _T2, _Res>
252 template<
typename _Res,
typename _T1,
typename _T2>
253 struct _Reference_wrapper_base<_Res(_T1, _T2) volatile>
254 : binary_function<_T1, _T2, _Res>
257 template<
typename _Res,
typename _T1,
typename _T2>
258 struct _Reference_wrapper_base<_Res(_T1, _T2) const volatile>
259 : binary_function<_T1, _T2, _Res>
263 template<
typename _Res,
typename _T1 _GLIBCXX_NOEXCEPT_PARM>
264 struct _Reference_wrapper_base<_Res(*)(_T1) _GLIBCXX_NOEXCEPT_QUAL>
265 : unary_function<_T1, _Res>
269 template<
typename _Res,
typename _T1,
typename _T2 _GLIBCXX_NOEXCEPT_PARM>
270 struct _Reference_wrapper_base<_Res(*)(_T1, _T2) _GLIBCXX_NOEXCEPT_QUAL>
271 : binary_function<_T1, _T2, _Res>
274 template<typename _Tp, bool = is_member_function_pointer<_Tp>::value>
275 struct _Reference_wrapper_base_memfun
276 : _Reference_wrapper_base<_Tp>
279 template<
typename _MemFunPtr>
280 struct _Reference_wrapper_base_memfun<_MemFunPtr, true>
281 : _Mem_fn_traits<_MemFunPtr>::__maybe_type
283 using result_type =
typename _Mem_fn_traits<_MemFunPtr>::__result_type;
293 template<
typename _Tp>
295#if __cplusplus <= 201703L
298 :
public _Reference_wrapper_base_memfun<typename remove_cv<_Tp>::type>
306 static void _S_fun(_Tp&&) =
delete;
308 template<
typename _Up,
typename _Up2 = __remove_cvref_t<_Up>>
318 template<
typename _Up,
typename = __not_same<_Up>,
typename
319 = decltype(reference_wrapper::_S_fun(std::declval<_Up>()))>
322 noexcept(
noexcept(reference_wrapper::_S_fun(std::declval<_Up>())))
323 : _M_data(reference_wrapper::_S_fun(std::forward<_Up>(__uref)))
332 operator _Tp&()
const noexcept
333 {
return this->get(); }
340 template<
typename... _Args>
342 typename result_of<_Tp&(_Args&&...)>::type
343 operator()(_Args&&... __args)
const
345#if __cplusplus > 201703L
346 if constexpr (is_object_v<type>)
347 static_assert(
sizeof(type),
"type must be complete");
353#if __cpp_deduction_guides
354 template<
typename _Tp>
361 template<
typename _Tp>
368 template<
typename _Tp>
374 template<
typename _Tp>
375 void ref(
const _Tp&&) =
delete;
377 template<
typename _Tp>
378 void cref(
const _Tp&&) =
delete;
381 template<
typename _Tp>
388 template<
typename _Tp>
392 {
return { __t.get() }; }
396_GLIBCXX_END_NAMESPACE_VERSION
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
Primary class template for reference_wrapper.
constexpr reference_wrapper< _Tp > ref(_Tp &__t) noexcept
constexpr reference_wrapper< _Tp > ref(reference_wrapper< _Tp > __t) noexcept
std::ref overload to prevent wrapping a reference_wrapper
constexpr reference_wrapper< const _Tp > cref(const _Tp &__t) noexcept
Denotes a const reference should be taken to a variable.
constexpr reference_wrapper< const _Tp > cref(reference_wrapper< _Tp > __t) noexcept
std::cref overload to prevent wrapping a reference_wrapper
Define a member typedef type only if a boolean constant is true.