30 #ifndef _GLIBCXX_REFWRAP_H 31 #define _GLIBCXX_REFWRAP_H 1 33 #pragma GCC system_header 35 #if __cplusplus < 201103L 43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 template<
typename _Res,
typename... _ArgTypes>
56 template<
typename _Res,
typename _T1>
61 template<
typename _Res,
typename _T1,
typename _T2>
65 template<
typename _Signature>
66 struct _Mem_fn_traits;
68 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
69 struct _Mem_fn_traits_base
71 using __result_type = _Res;
77 #define _GLIBCXX_MEM_FN_TRAITS2(_CV, _REF, _LVAL, _RVAL) \ 78 template<typename _Res, typename _Class, typename... _ArgTypes> \ 79 struct _Mem_fn_traits<_Res (_Class::*)(_ArgTypes...) _CV _REF> \ 80 : _Mem_fn_traits_base<_Res, _CV _Class, _ArgTypes...> \ 82 using __vararg = false_type; \ 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 = true_type; \ 91 #define _GLIBCXX_MEM_FN_TRAITS(_REF, _LVAL, _RVAL) \ 92 _GLIBCXX_MEM_FN_TRAITS2( , _REF, _LVAL, _RVAL) \ 93 _GLIBCXX_MEM_FN_TRAITS2(const , _REF, _LVAL, _RVAL) \ 94 _GLIBCXX_MEM_FN_TRAITS2(volatile , _REF, _LVAL, _RVAL) \ 95 _GLIBCXX_MEM_FN_TRAITS2(const volatile, _REF, _LVAL, _RVAL) 101 #if __cplusplus > 201402L 107 #undef _GLIBCXX_MEM_FN_TRAITS 108 #undef _GLIBCXX_MEM_FN_TRAITS2 111 template<
typename _Functor,
typename = __
void_t<>>
115 template<
typename _Functor>
117 __void_t<typename _Functor::result_type>>
118 {
typedef typename _Functor::result_type result_type; };
124 template<
typename _Functor>
130 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
132 {
typedef _Res result_type; };
135 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
137 {
typedef _Res result_type; };
140 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
142 {
typedef _Res result_type; };
145 template<
typename _Res,
typename... _ArgTypes _GLIBCXX_NOEXCEPT_PARM>
148 {
typedef _Res result_type; };
151 template<
typename _Functor,
153 struct _Weak_result_type_memfun
158 template<
typename _MemFunPtr>
159 struct _Weak_result_type_memfun<_MemFunPtr, true>
161 using result_type =
typename _Mem_fn_traits<_MemFunPtr>::__result_type;
165 template<
typename _Func,
typename _Class>
166 struct _Weak_result_type_memfun<_Func _Class::*, false>
173 template<
typename _Functor>
175 : _Weak_result_type_memfun<typename remove_cv<_Functor>::type>
178 #if __cplusplus <= 201703L 180 template<
typename _Tp,
typename = __
void_t<>>
181 struct _Refwrap_base_arg1
185 template<
typename _Tp>
186 struct _Refwrap_base_arg1<_Tp,
187 __void_t<typename _Tp::argument_type>>
189 typedef typename _Tp::argument_type argument_type;
193 template<
typename _Tp,
typename = __
void_t<>>
194 struct _Refwrap_base_arg2
198 template<
typename _Tp>
199 struct _Refwrap_base_arg2<_Tp,
200 __void_t<typename _Tp::first_argument_type,
201 typename _Tp::second_argument_type>>
203 typedef typename _Tp::first_argument_type first_argument_type;
204 typedef typename _Tp::second_argument_type second_argument_type;
213 template<
typename _Tp>
219 template<
typename _Res,
typename _T1 _GLIBCXX_NOEXCEPT_PARM>
224 template<
typename _Res,
typename _T1>
225 struct _Reference_wrapper_base<_Res(_T1) const>
226 : unary_function<_T1, _Res>
229 template<
typename _Res,
typename _T1>
230 struct _Reference_wrapper_base<_Res(_T1) volatile>
231 : unary_function<_T1, _Res>
234 template<
typename _Res,
typename _T1>
235 struct _Reference_wrapper_base<_Res(_T1) const volatile>
236 : unary_function<_T1, _Res>
240 template<
typename _Res,
typename _T1,
typename _T2 _GLIBCXX_NOEXCEPT_PARM>
241 struct _Reference_wrapper_base<_Res(_T1, _T2) _GLIBCXX_NOEXCEPT_QUAL>
242 : binary_function<_T1, _T2, _Res>
245 template<
typename _Res,
typename _T1,
typename _T2>
246 struct _Reference_wrapper_base<_Res(_T1, _T2) const>
247 : binary_function<_T1, _T2, _Res>
250 template<
typename _Res,
typename _T1,
typename _T2>
251 struct _Reference_wrapper_base<_Res(_T1, _T2) volatile>
252 : binary_function<_T1, _T2, _Res>
255 template<
typename _Res,
typename _T1,
typename _T2>
256 struct _Reference_wrapper_base<_Res(_T1, _T2) const volatile>
257 : binary_function<_T1, _T2, _Res>
261 template<
typename _Res,
typename _T1 _GLIBCXX_NOEXCEPT_PARM>
262 struct _Reference_wrapper_base<_Res(*)(_T1) _GLIBCXX_NOEXCEPT_QUAL>
263 : unary_function<_T1, _Res>
267 template<
typename _Res,
typename _T1,
typename _T2 _GLIBCXX_NOEXCEPT_PARM>
268 struct _Reference_wrapper_base<_Res(*)(_T1, _T2) _GLIBCXX_NOEXCEPT_QUAL>
269 : binary_function<_T1, _T2, _Res>
272 template<typename _Tp, bool = is_member_function_pointer<_Tp>::value>
273 struct _Reference_wrapper_base_memfun
274 : _Reference_wrapper_base<_Tp>
277 template<
typename _MemFunPtr>
278 struct _Reference_wrapper_base_memfun<_MemFunPtr, true>
279 : _Mem_fn_traits<_MemFunPtr>::__maybe_type
281 using result_type =
typename _Mem_fn_traits<_MemFunPtr>::__result_type;
290 template<
typename _Tp>
291 class reference_wrapper
292 #if __cplusplus <= 201703L
295 :
public _Reference_wrapper_base_memfun<typename remove_cv<_Tp>::type>
301 static void _S_fun(_Tp&&) =
delete;
303 template<
typename _Up,
typename _Up2 = __remove_cvref_t<_Up>>
305 =
typename enable_if<!is_same<reference_wrapper, _Up2>::value>::type;
313 template<
typename _Up,
typename = __not_same<_Up>,
typename 314 = decltype(reference_wrapper::_S_fun(std::declval<_Up>()))>
315 reference_wrapper(_Up&& __uref)
316 noexcept(noexcept(reference_wrapper::_S_fun(std::declval<_Up>())))
317 : _M_data(reference_wrapper::_S_fun(
std::
forward<_Up>(__uref)))
320 reference_wrapper(
const reference_wrapper&) =
default;
323 operator=(
const reference_wrapper&) =
default;
325 operator _Tp&()
const noexcept
326 {
return this->
get(); }
332 template<
typename... _Args>
333 typename result_of<_Tp&(_Args&&...)>::type
334 operator()(_Args&&... __args)
const 336 #if __cplusplus > 201703L 337 if constexpr (is_object_v<type>)
338 static_assert(
sizeof(type),
"type must be complete");
344 #if __cpp_deduction_guides 345 template<
typename _Tp>
346 reference_wrapper(_Tp&) -> reference_wrapper<_Tp>;
350 template<
typename _Tp>
351 inline reference_wrapper<_Tp>
356 template<
typename _Tp>
357 inline reference_wrapper<const _Tp>
361 template<
typename _Tp>
362 void ref(
const _Tp&&) =
delete;
364 template<
typename _Tp>
365 void cref(
const _Tp&&) =
delete;
368 template<
typename _Tp>
369 inline reference_wrapper<_Tp>
374 template<
typename _Tp>
375 inline reference_wrapper<const _Tp>
377 {
return { __t.get() }; }
381 _GLIBCXX_END_NAMESPACE_VERSION
386 #endif // _GLIBCXX_REFWRAP_H integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
If we have found a result_type, extract it.
ISO C++ entities toplevel namespace is std.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Primary class template for reference_wrapper.
is_member_function_pointer
reference_wrapper< const _Tp > cref(const _Tp &__t) noexcept
Denotes a const reference should be taken to a variable.
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.
reference_wrapper< _Tp > ref(_Tp &__t) noexcept
Denotes a reference should be taken to a variable.