30 #ifndef _GLIBCXX_REFWRAP_H
31 #define _GLIBCXX_REFWRAP_H 1
33 #pragma GCC system_header
35 #if __cplusplus >= 201103L
41 namespace std _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 template<
typename _Res,
typename... _ArgTypes>
53 struct _Maybe_unary_or_binary_function { };
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
60 template<
typename _Res,
typename _T1>
61 struct _Maybe_unary_or_binary_function<_Res, _T1>
65 template<
typename _Res,
typename _T1,
typename _T2>
66 struct _Maybe_unary_or_binary_function<_Res, _T1, _T2>
69 #pragma GCC diagnostic pop
71 template<
typename _Signature>
72 struct _Mem_fn_traits;
74 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
75 struct _Mem_fn_traits_base
77 using __result_type = _Res;
79 = _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...>;
80 using __arity = integral_constant<size_t,
sizeof...(_ArgTypes)>;
83 #define _GLIBCXX_MEM_FN_TRAITS2(_CV, _REF, _LVAL, _RVAL) \
84 template<typename _Res, typename _Class, typename... _ArgTypes> \
85 struct _Mem_fn_traits<_Res (_Class::*)(_ArgTypes...) _CV _REF> \
86 : _Mem_fn_traits_base<_Res, _CV _Class, _ArgTypes...> \
88 using __vararg = false_type; \
90 template<typename _Res, typename _Class, typename... _ArgTypes> \
91 struct _Mem_fn_traits<_Res (_Class::*)(_ArgTypes... ...) _CV _REF> \
92 : _Mem_fn_traits_base<_Res, _CV _Class, _ArgTypes...> \
94 using __vararg = true_type; \
97 #define _GLIBCXX_MEM_FN_TRAITS(_REF, _LVAL, _RVAL) \
98 _GLIBCXX_MEM_FN_TRAITS2( , _REF, _LVAL, _RVAL) \
99 _GLIBCXX_MEM_FN_TRAITS2(const , _REF, _LVAL, _RVAL) \
100 _GLIBCXX_MEM_FN_TRAITS2(volatile , _REF, _LVAL, _RVAL) \
101 _GLIBCXX_MEM_FN_TRAITS2(const volatile, _REF, _LVAL, _RVAL)
107 #if __cplusplus > 201402L
113 #undef _GLIBCXX_MEM_FN_TRAITS
114 #undef _GLIBCXX_MEM_FN_TRAITS2
117 template<
typename _Functor,
typename = __
void_t<>>
118 struct _Maybe_get_result_type
121 template<
typename _Functor>
122 struct _Maybe_get_result_type<_Functor,
123 __void_t<typename _Functor::result_type>>
124 {
typedef typename _Functor::result_type result_type; };
130 template<
typename _Functor>
131 struct _Weak_result_type_impl
132 : _Maybe_get_result_type<_Functor>
136 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
137 struct _Weak_result_type_impl<_Res(_ArgTypes...) _GLIBCXX_NOEXCEPT_QUAL>
138 {
typedef _Res result_type; };
141 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
142 struct _Weak_result_type_impl<_Res(_ArgTypes......) _GLIBCXX_NOEXCEPT_QUAL>
143 {
typedef _Res result_type; };
146 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
147 struct _Weak_result_type_impl<_Res(*)(_ArgTypes...) _GLIBCXX_NOEXCEPT_QUAL>
148 {
typedef _Res result_type; };
151 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
153 _Weak_result_type_impl<_Res(*)(_ArgTypes......) _GLIBCXX_NOEXCEPT_QUAL>
154 {
typedef _Res result_type; };
157 template<
typename _Functor,
158 bool = is_member_function_pointer<_Functor>::value>
159 struct _Weak_result_type_memfun
160 : _Weak_result_type_impl<_Functor>
164 template<
typename _MemFunPtr>
165 struct _Weak_result_type_memfun<_MemFunPtr, true>
167 using result_type =
typename _Mem_fn_traits<_MemFunPtr>::__result_type;
171 template<
typename _Func,
typename _Class>
172 struct _Weak_result_type_memfun<_Func _Class::*, false>
179 template<
typename _Functor>
180 struct _Weak_result_type
181 : _Weak_result_type_memfun<typename remove_cv<_Functor>::type>
184 #if __cplusplus <= 201703L
186 template<
typename _Tp,
typename = __
void_t<>>
187 struct _Refwrap_base_arg1
191 template<
typename _Tp>
192 struct _Refwrap_base_arg1<_Tp,
193 __void_t<typename _Tp::argument_type>>
195 typedef typename _Tp::argument_type argument_type;
199 template<
typename _Tp,
typename = __
void_t<>>
200 struct _Refwrap_base_arg2
204 template<
typename _Tp>
205 struct _Refwrap_base_arg2<_Tp,
206 __void_t<typename _Tp::first_argument_type,
207 typename _Tp::second_argument_type>>
209 typedef typename _Tp::first_argument_type first_argument_type;
210 typedef typename _Tp::second_argument_type second_argument_type;
219 template<
typename _Tp>
220 struct _Reference_wrapper_base
221 : _Weak_result_type<_Tp>, _Refwrap_base_arg1<_Tp>, _Refwrap_base_arg2<_Tp>
225 #pragma GCC diagnostic push
226 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
229 template<
typename _Res,
typename _T1 _GLIBCXX_NOEXCEPT_PARM>
230 struct _Reference_wrapper_base<_Res(_T1) _GLIBCXX_NOEXCEPT_QUAL>
231 : unary_function<_T1, _Res>
234 template<
typename _Res,
typename _T1>
235 struct _Reference_wrapper_base<_Res(_T1) const>
236 : unary_function<_T1, _Res>
239 template<
typename _Res,
typename _T1>
240 struct _Reference_wrapper_base<_Res(_T1) volatile>
241 : unary_function<_T1, _Res>
244 template<
typename _Res,
typename _T1>
245 struct _Reference_wrapper_base<_Res(_T1) const volatile>
246 : unary_function<_T1, _Res>
250 template<
typename _Res,
typename _T1,
typename _T2 _GLIBCXX_NOEXCEPT_PARM>
251 struct _Reference_wrapper_base<_Res(_T1, _T2) _GLIBCXX_NOEXCEPT_QUAL>
252 : binary_function<_T1, _T2, _Res>
255 template<
typename _Res,
typename _T1,
typename _T2>
256 struct _Reference_wrapper_base<_Res(_T1, _T2) const>
257 : binary_function<_T1, _T2, _Res>
260 template<
typename _Res,
typename _T1,
typename _T2>
261 struct _Reference_wrapper_base<_Res(_T1, _T2) volatile>
262 : binary_function<_T1, _T2, _Res>
265 template<
typename _Res,
typename _T1,
typename _T2>
266 struct _Reference_wrapper_base<_Res(_T1, _T2) const volatile>
267 : binary_function<_T1, _T2, _Res>
271 template<
typename _Res,
typename _T1 _GLIBCXX_NOEXCEPT_PARM>
272 struct _Reference_wrapper_base<_Res(*)(_T1) _GLIBCXX_NOEXCEPT_QUAL>
273 : unary_function<_T1, _Res>
277 template<
typename _Res,
typename _T1,
typename _T2 _GLIBCXX_NOEXCEPT_PARM>
278 struct _Reference_wrapper_base<_Res(*)(_T1, _T2) _GLIBCXX_NOEXCEPT_QUAL>
279 : binary_function<_T1, _T2, _Res>
282 template<typename _Tp, bool = is_member_function_pointer<_Tp>::value>
283 struct _Reference_wrapper_base_memfun
284 : _Reference_wrapper_base<_Tp>
287 template<
typename _MemFunPtr>
288 struct _Reference_wrapper_base_memfun<_MemFunPtr, true>
289 : _Mem_fn_traits<_MemFunPtr>::__maybe_type
291 using result_type =
typename _Mem_fn_traits<_MemFunPtr>::__result_type;
293 #pragma GCC diagnostic pop
302 template<
typename _Tp>
304 #if __cplusplus <= 201703L
307 :
public _Reference_wrapper_base_memfun<typename remove_cv<_Tp>::type>
315 static void _S_fun(_Tp&&) =
delete;
317 template<
typename _Up,
typename _Up2 = __remove_cvref_t<_Up>>
327 template<
typename _Up,
typename = __not_same<_Up>,
typename
328 = decltype(reference_wrapper::_S_fun(std::declval<_Up>()))>
331 noexcept(noexcept(reference_wrapper::_S_fun(std::declval<_Up>())))
332 : _M_data(reference_wrapper::_S_fun(std::forward<_Up>(__uref)))
341 operator _Tp&()
const noexcept
342 {
return this->get(); }
349 template<
typename... _Args>
351 typename result_of<_Tp&(_Args&&...)>::type
352 operator()(_Args&&... __args)
const
354 #if __cplusplus > 201703L
355 if constexpr (is_object_v<type>)
356 static_assert(
sizeof(type),
"type must be complete");
362 #if __cpp_deduction_guides
363 template<
typename _Tp>
370 template<
typename _Tp>
377 template<
typename _Tp>
383 template<
typename _Tp>
384 void ref(
const _Tp&&) =
delete;
386 template<
typename _Tp>
387 void cref(
const _Tp&&) =
delete;
390 template<
typename _Tp>
397 template<
typename _Tp>
401 {
return { __t.get() }; }
405 _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 _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
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.