44 #ifndef _GLIBCXX_FUNCTIONAL
45 #define _GLIBCXX_FUNCTIONAL 1
47 #pragma GCC system_header
52 #ifdef __GXX_EXPERIMENTAL_CXX0X__
61 namespace std _GLIBCXX_VISIBILITY(default)
63 _GLIBCXX_BEGIN_NAMESPACE_VERSION
68 template<
bool _Has_result_type, typename _Functor>
72 template<
typename _Functor>
74 {
typedef typename _Functor::result_type result_type; };
80 template<
typename _Functor>
86 template<
typename _Res,
typename... _ArgTypes>
88 {
typedef _Res result_type; };
90 template<
typename _Res,
typename... _ArgTypes>
92 {
typedef _Res result_type; };
94 template<
typename _Res,
typename... _ArgTypes>
95 struct _Weak_result_type_impl<_Res(_ArgTypes...) const>
96 {
typedef _Res result_type; };
98 template<
typename _Res,
typename... _ArgTypes>
99 struct _Weak_result_type_impl<_Res(_ArgTypes......) const>
100 {
typedef _Res result_type; };
102 template<
typename _Res,
typename... _ArgTypes>
103 struct _Weak_result_type_impl<_Res(_ArgTypes...) volatile>
104 {
typedef _Res result_type; };
106 template<
typename _Res,
typename... _ArgTypes>
107 struct _Weak_result_type_impl<_Res(_ArgTypes......) volatile>
108 {
typedef _Res result_type; };
110 template<
typename _Res,
typename... _ArgTypes>
111 struct _Weak_result_type_impl<_Res(_ArgTypes...) const volatile>
112 {
typedef _Res result_type; };
114 template<
typename _Res,
typename... _ArgTypes>
115 struct _Weak_result_type_impl<_Res(_ArgTypes......) const volatile>
116 {
typedef _Res result_type; };
119 template<
typename _Res,
typename... _ArgTypes>
121 {
typedef _Res result_type; };
123 template<
typename _Res,
typename... _ArgTypes>
125 {
typedef _Res result_type; };
128 template<
typename _Res,
typename... _ArgTypes>
130 {
typedef _Res result_type; };
132 template<
typename _Res,
typename... _ArgTypes>
134 {
typedef _Res result_type; };
137 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
139 {
typedef _Res result_type; };
141 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
143 {
typedef _Res result_type; };
146 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
148 {
typedef _Res result_type; };
150 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
152 {
typedef _Res result_type; };
155 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
157 {
typedef _Res result_type; };
159 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
161 {
typedef _Res result_type; };
164 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
167 {
typedef _Res result_type; };
169 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
172 {
typedef _Res result_type; };
178 template<
typename _Functor>
184 template<
typename _Tp>
188 template<
typename _T1,
typename _Res>
193 static __two __test(...);
196 static const bool value =
sizeof(__test((_Tp*)0)) == 1;
200 template<
typename _Tp>
204 template<
typename _T1,
typename _T2,
typename _Res>
209 static __two __test(...);
212 static const bool value =
sizeof(__test((_Tp*)0)) == 1;
219 template<
typename _Functor,
typename... _Args>
225 typename result_of<_Functor(_Args&&...)>::type
229 return __f(std::forward<_Args>(__args)...);
232 template<
typename _Functor,
typename... _Args>
235 (is_member_pointer<_Functor>::value
236 && !is_function<_Functor>::value
237 && !is_function<typename remove_pointer<_Functor>::type>::value),
238 typename result_of<_Functor(_Args&&...)>::type
240 __invoke(_Functor& __f, _Args&&... __args)
242 return mem_fn(__f)(std::forward<_Args>(__args)...);
246 template<
typename _Functor,
typename... _Args>
249 (is_pointer<_Functor>::value
250 && is_function<typename remove_pointer<_Functor>::type>::value),
251 typename result_of<_Functor(_Args&&...)>::type
253 __invoke(_Functor __f, _Args&&... __args)
255 return __f(std::forward<_Args>(__args)...);
263 template<
bool _Unary,
bool _Binary,
typename _Tp>
267 template<
typename _Tp>
273 template<
typename _Tp>
277 typedef typename _Tp::argument_type argument_type;
281 template<
typename _Tp>
282 struct _Reference_wrapper_base_impl<false, true, _Tp>
283 : _Weak_result_type<_Tp>
285 typedef typename _Tp::first_argument_type first_argument_type;
286 typedef typename _Tp::second_argument_type second_argument_type;
290 template<
typename _Tp>
291 struct _Reference_wrapper_base_impl<true, true, _Tp>
292 : _Weak_result_type<_Tp>
294 typedef typename _Tp::argument_type argument_type;
295 typedef typename _Tp::first_argument_type first_argument_type;
296 typedef typename _Tp::second_argument_type second_argument_type;
309 template<typename _Tp>
312 __has_argument_type<_Tp>::value,
313 __has_first_argument_type<_Tp>::value
314 && __has_second_argument_type<_Tp>::value,
319 template<
typename _Res,
typename _T1>
324 template<
typename _Res,
typename _T1>
325 struct _Reference_wrapper_base<_Res(_T1) const>
326 : unary_function<_T1, _Res>
329 template<
typename _Res,
typename _T1>
330 struct _Reference_wrapper_base<_Res(_T1) volatile>
331 : unary_function<_T1, _Res>
334 template<
typename _Res,
typename _T1>
335 struct _Reference_wrapper_base<_Res(_T1) const volatile>
336 : unary_function<_T1, _Res>
340 template<
typename _Res,
typename _T1,
typename _T2>
341 struct _Reference_wrapper_base<_Res(_T1, _T2)>
342 : binary_function<_T1, _T2, _Res>
345 template<
typename _Res,
typename _T1,
typename _T2>
346 struct _Reference_wrapper_base<_Res(_T1, _T2) const>
347 : binary_function<_T1, _T2, _Res>
350 template<
typename _Res,
typename _T1,
typename _T2>
351 struct _Reference_wrapper_base<_Res(_T1, _T2) volatile>
352 : binary_function<_T1, _T2, _Res>
355 template<
typename _Res,
typename _T1,
typename _T2>
356 struct _Reference_wrapper_base<_Res(_T1, _T2) const volatile>
357 : binary_function<_T1, _T2, _Res>
361 template<
typename _Res,
typename _T1>
362 struct _Reference_wrapper_base<_Res(*)(_T1)>
363 : unary_function<_T1, _Res>
367 template<
typename _Res,
typename _T1,
typename _T2>
368 struct _Reference_wrapper_base<_Res(*)(_T1, _T2)>
369 : binary_function<_T1, _T2, _Res>
373 template<
typename _Res,
typename _T1>
374 struct _Reference_wrapper_base<_Res (_T1::*)()>
375 : unary_function<_T1*, _Res>
379 template<
typename _Res,
typename _T1,
typename _T2>
380 struct _Reference_wrapper_base<_Res (_T1::*)(_T2)>
381 : binary_function<_T1*, _T2, _Res>
385 template<
typename _Res,
typename _T1>
386 struct _Reference_wrapper_base<_Res (_T1::*)() const>
387 : unary_function<const _T1*, _Res>
391 template<
typename _Res,
typename _T1,
typename _T2>
392 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const>
393 : binary_function<const _T1*, _T2, _Res>
397 template<
typename _Res,
typename _T1>
398 struct _Reference_wrapper_base<_Res (_T1::*)() volatile>
399 : unary_function<volatile _T1*, _Res>
403 template<
typename _Res,
typename _T1,
typename _T2>
404 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile>
405 : binary_function<volatile _T1*, _T2, _Res>
409 template<
typename _Res,
typename _T1>
410 struct _Reference_wrapper_base<_Res (_T1::*)() const volatile>
411 : unary_function<const volatile _T1*, _Res>
415 template<
typename _Res,
typename _T1,
typename _T2>
416 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile>
417 : binary_function<const volatile _T1*, _T2, _Res>
425 template<
typename _Tp>
435 : _M_data(std::__addressof(__indata))
441 _M_data(__inref._M_data)
447 _M_data = __inref._M_data;
451 operator _Tp&()
const
452 {
return this->
get(); }
458 template<
typename... _Args>
459 typename result_of<_Tp&(_Args&&...)>::type
460 operator()(_Args&&... __args)
const
462 return __invoke(
get(), std::forward<_Args>(__args)...);
468 template<
typename _Tp>
474 template<
typename _Tp>
475 inline reference_wrapper<const _Tp>
479 template<
typename _Tp>
480 void ref(
const _Tp&&) =
delete;
482 template<
typename _Tp>
483 void cref(
const _Tp&&) =
delete;
486 template<
typename _Tp>
487 inline reference_wrapper<_Tp>
489 {
return ref(__t.get()); }
492 template<
typename _Tp>
493 inline reference_wrapper<const _Tp>
495 {
return cref(__t.get()); }
499 template<
typename _MemberPo
inter>
507 template<
typename _Res,
typename... _ArgTypes>
511 template<
typename _Res,
typename _T1>
516 template<
typename _Res,
typename _T1,
typename _T2>
521 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
522 class _Mem_fn<_Res (_Class::*)(_ArgTypes...)>
525 typedef _Res (_Class::*_Functor)(_ArgTypes...);
527 template<
typename _Tp>
529 _M_call(_Tp& __object,
const volatile _Class *,
530 _ArgTypes... __args)
const
531 {
return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
533 template<
typename _Tp>
535 _M_call(_Tp& __ptr,
const volatile void *, _ArgTypes... __args)
const
536 {
return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
539 typedef _Res result_type;
541 explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
545 operator()(_Class& __object, _ArgTypes... __args)
const
546 {
return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
550 operator()(_Class* __object, _ArgTypes... __args)
const
551 {
return (__object->*__pmf)(std::forward<_ArgTypes>(__args)...); }
554 template<
typename _Tp>
556 operator()(_Tp& __object, _ArgTypes... __args)
const
558 return _M_call(__object, &__object,
559 std::forward<_ArgTypes>(__args)...);
567 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
568 class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const>
572 typedef _Res (_Class::*_Functor)(_ArgTypes...)
const;
574 template<
typename _Tp>
576 _M_call(_Tp& __object,
const volatile _Class *,
577 _ArgTypes... __args)
const
578 {
return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
580 template<
typename _Tp>
582 _M_call(_Tp& __ptr,
const volatile void *, _ArgTypes... __args)
const
583 {
return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
586 typedef _Res result_type;
588 explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
592 operator()(
const _Class& __object, _ArgTypes... __args)
const
593 {
return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
597 operator()(
const _Class* __object, _ArgTypes... __args)
const
598 {
return (__object->*__pmf)(std::forward<_ArgTypes>(__args)...); }
601 template<
typename _Tp>
602 _Res operator()(_Tp& __object, _ArgTypes... __args)
const
604 return _M_call(__object, &__object,
605 std::forward<_ArgTypes>(__args)...);
613 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
614 class _Mem_fn<_Res (_Class::*)(_ArgTypes...) volatile>
618 typedef _Res (_Class::*_Functor)(_ArgTypes...)
volatile;
620 template<
typename _Tp>
622 _M_call(_Tp& __object,
const volatile _Class *,
623 _ArgTypes... __args)
const
624 {
return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
626 template<
typename _Tp>
628 _M_call(_Tp& __ptr,
const volatile void *, _ArgTypes... __args)
const
629 {
return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
632 typedef _Res result_type;
634 explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
638 operator()(
volatile _Class& __object, _ArgTypes... __args)
const
639 {
return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
643 operator()(
volatile _Class* __object, _ArgTypes... __args)
const
644 {
return (__object->*__pmf)(std::forward<_ArgTypes>(__args)...); }
647 template<
typename _Tp>
649 operator()(_Tp& __object, _ArgTypes... __args)
const
651 return _M_call(__object, &__object,
652 std::forward<_ArgTypes>(__args)...);
660 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
661 class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const volatile>
665 typedef _Res (_Class::*_Functor)(_ArgTypes...)
const volatile;
667 template<
typename _Tp>
669 _M_call(_Tp& __object,
const volatile _Class *,
670 _ArgTypes... __args)
const
671 {
return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
673 template<
typename _Tp>
675 _M_call(_Tp& __ptr,
const volatile void *, _ArgTypes... __args)
const
676 {
return ((*__ptr).*__pmf)(std::forward<_ArgTypes>(__args)...); }
679 typedef _Res result_type;
681 explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
685 operator()(
const volatile _Class& __object, _ArgTypes... __args)
const
686 {
return (__object.*__pmf)(std::forward<_ArgTypes>(__args)...); }
690 operator()(
const volatile _Class* __object, _ArgTypes... __args)
const
691 {
return (__object->*__pmf)(std::forward<_ArgTypes>(__args)...); }
694 template<
typename _Tp>
695 _Res operator()(_Tp& __object, _ArgTypes... __args)
const
697 return _M_call(__object, &__object,
698 std::forward<_ArgTypes>(__args)...);
706 template<
typename _Tp,
bool>
707 struct _Mem_fn_const_or_non
709 typedef const _Tp& type;
712 template<
typename _Tp>
713 struct _Mem_fn_const_or_non<_Tp, false>
718 template<
typename _Res,
typename _Class>
719 class _Mem_fn<_Res _Class::*>
723 template<
typename _Tp>
725 _M_call(_Tp& __object, _Class *)
const
726 {
return __object.*__pm; }
728 template<
typename _Tp,
typename _Up>
730 _M_call(_Tp& __object, _Up *
const *)
const
731 {
return (*__object).*__pm; }
733 template<
typename _Tp,
typename _Up>
735 _M_call(_Tp& __object,
const _Up *
const *)
const
736 {
return (*__object).*__pm; }
738 template<
typename _Tp>
740 _M_call(_Tp& __object,
const _Class *)
const
741 {
return __object.*__pm; }
743 template<
typename _Tp>
745 _M_call(_Tp& __ptr,
const volatile void*)
const
746 {
return (*__ptr).*__pm; }
748 template<
typename _Tp>
static _Tp& __get_ref();
750 template<
typename _Tp>
751 static __sfinae_types::__one __check_const(_Tp&, _Class*);
752 template<
typename _Tp,
typename _Up>
753 static __sfinae_types::__one __check_const(_Tp&, _Up *
const *);
754 template<
typename _Tp,
typename _Up>
755 static __sfinae_types::__two __check_const(_Tp&,
const _Up *
const *);
756 template<
typename _Tp>
757 static __sfinae_types::__two __check_const(_Tp&,
const _Class*);
758 template<
typename _Tp>
759 static __sfinae_types::__two __check_const(_Tp&,
const volatile void*);
762 template<
typename _Tp>
764 : _Mem_fn_const_or_non<_Res,
765 (sizeof(__sfinae_types::__two)
766 == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))>
769 template<
typename _Signature>
772 template<
typename _CVMem,
typename _Tp>
773 struct result<_CVMem(_Tp)>
774 :
public _Result_type<_Tp> { };
776 template<
typename _CVMem,
typename _Tp>
777 struct result<_CVMem(_Tp&)>
778 :
public _Result_type<_Tp> { };
781 _Mem_fn(_Res _Class::*__pm) : __pm(__pm) { }
785 operator()(_Class& __object)
const
786 {
return __object.*__pm; }
789 operator()(
const _Class& __object)
const
790 {
return __object.*__pm; }
794 operator()(_Class* __object)
const
795 {
return __object->*__pm; }
798 operator()(
const _Class* __object)
const
799 {
return __object->*__pm; }
802 template<
typename _Tp>
803 typename _Result_type<_Tp>::type
804 operator()(_Tp& __unknown)
const
805 {
return _M_call(__unknown, &__unknown); }
816 template<
typename _Tp,
typename _Class>
817 inline _Mem_fn<_Tp _Class::*>
820 return _Mem_fn<_Tp _Class::*>(__pm);
829 template<
typename _Tp>
838 template<
typename _Tp>
846 _GLIBCXX_END_NAMESPACE_VERSION
856 namespace placeholders
858 _GLIBCXX_BEGIN_NAMESPACE_VERSION
888 _GLIBCXX_END_NAMESPACE_VERSION
891 _GLIBCXX_BEGIN_NAMESPACE_VERSION
907 struct _No_tuple_element;
914 template<
int __i,
typename _Tuple,
bool _IsSafe>
923 template<
int __i,
typename _Tuple>
926 typedef _No_tuple_element type;
933 template<
int __i,
typename _Tuple>
936 (__i >= 0 && __i < tuple_size<_Tuple>::value)>
950 template<
typename _Arg,
959 template<
typename _Tp>
963 typedef _Tp& result_type;
969 template<
typename _CVRef,
typename _Tuple>
971 operator()(_CVRef& __arg, _Tuple&)
const volatile
972 {
return __arg.get(); }
980 template<
typename _Arg>
981 class _Mu<_Arg, true, false>
984 template<
typename _CVArg,
typename... _Args>
986 operator()(_CVArg& __arg,
988 -> decltype(__arg(declval<_Args>()...))
993 return this->__call(__arg, __tuple, _Indexes());
999 template<
typename _CVArg,
typename... _Args,
int... _Indexes>
1003 -> decltype(__arg(declval<_Args>()...))
1005 return __arg(std::forward<_Args>(get<_Indexes>(__tuple))...);
1014 template<
typename _Arg>
1018 template<
typename _Signature>
class result;
1020 template<
typename _CVMu,
typename _CVArg,
typename _Tuple>
1021 class result<_CVMu(_CVArg, _Tuple)>
1031 typedef typename add_rvalue_reference<__base_type>::type type;
1034 template<
typename _Tuple>
1035 typename result<_Mu(_Arg, _Tuple)>::type
1036 operator()(
const volatile _Arg&, _Tuple& __tuple)
const volatile
1038 return std::forward<typename result<_Mu(_Arg, _Tuple)>::type>(
1039 ::std::get<(is_placeholder<_Arg>::value - 1)>(__tuple));
1048 template<
typename _Arg>
1052 template<
typename _Signature>
struct result;
1054 template<
typename _CVMu,
typename _CVArg,
typename _Tuple>
1055 struct result<_CVMu(_CVArg, _Tuple)>
1057 typedef typename add_lvalue_reference<_CVArg>::type type;
1061 template<
typename _CVArg,
typename _Tuple>
1063 operator()(_CVArg&& __arg, _Tuple&)
const volatile
1064 {
return std::forward<_CVArg>(__arg); }
1072 template<
typename _Tp>
1078 __do_wrap(
const _Tp& __x)
1082 __do_wrap(_Tp&& __x)
1083 {
return static_cast<_Tp&&
>(__x); }
1091 template<
typename _Tp,
typename _Class>
1094 typedef _Mem_fn<_Tp _Class::*> type;
1097 __do_wrap(_Tp _Class::* __pm)
1098 {
return type(__pm); }
1112 template<
size_t _Ind,
typename... _Tp>
1114 __volget(
volatile tuple<_Tp...>& __tuple)
1115 ->
typename tuple_element<_Ind, tuple<_Tp...>>::type
volatile&
1116 {
return std::get<_Ind>(
const_cast<tuple<_Tp...
>&>(__tuple)); }
1119 template<
size_t _Ind,
typename... _Tp>
1121 __volget(
const volatile tuple<_Tp...>& __tuple)
1122 ->
typename tuple_element<_Ind, tuple<_Tp...>>::type
const volatile&
1123 {
return std::get<_Ind>(
const_cast<const tuple<_Tp...
>&>(__tuple)); }
1126 template<
typename _Signature>
1129 template<
typename _Functor,
typename... _Bound_args>
1130 class _Bind<_Functor(_Bound_args...)>
1133 typedef _Bind __self_type;
1138 tuple<_Bound_args...> _M_bound_args;
1141 template<
typename _Result,
typename... _Args,
int... _Indexes>
1146 (get<_Indexes>(_M_bound_args), __args)...);
1150 template<
typename _Result,
typename... _Args,
int... _Indexes>
1155 (get<_Indexes>(_M_bound_args), __args)...);
1159 template<
typename _Result,
typename... _Args,
int... _Indexes>
1161 __call_v(tuple<_Args...>&& __args,
1162 _Index_tuple<_Indexes...>)
volatile
1164 return _M_f(_Mu<_Bound_args>()
1165 (__volget<_Indexes>(_M_bound_args), __args)...);
1169 template<
typename _Result,
typename... _Args,
int... _Indexes>
1171 __call_c_v(tuple<_Args...>&& __args,
1172 _Index_tuple<_Indexes...>)
const volatile
1174 return _M_f(_Mu<_Bound_args>()
1175 (__volget<_Indexes>(_M_bound_args), __args)...);
1179 template<
typename... _Args>
1180 explicit _Bind(
const _Functor& __f, _Args&&... __args)
1181 : _M_f(__f), _M_bound_args(std::
forward<_Args>(__args)...)
1184 template<
typename... _Args>
1185 explicit _Bind(_Functor&& __f, _Args&&... __args)
1186 : _M_f(std::move(__f)), _M_bound_args(std::
forward<_Args>(__args)...)
1189 _Bind(
const _Bind&) =
default;
1192 : _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args))
1196 template<
typename... _Args,
typename _Result
1197 = decltype( std::declval<_Functor>()(
1198 _Mu<_Bound_args>()( std::declval<_Bound_args&>(),
1199 std::declval<tuple<_Args...>&>() )... ) )>
1201 operator()(_Args&&... __args)
1203 return this->__call<_Result>(
1204 std::forward_as_tuple(std::forward<_Args>(__args)...),
1209 template<
typename... _Args,
typename _Result
1210 = decltype( std::declval<
typename enable_if<(
sizeof...(_Args) >= 0),
1211 typename add_const<_Functor>::type>::type>()(
1212 _Mu<_Bound_args>()( std::declval<const _Bound_args&>(),
1213 std::declval<tuple<_Args...>&>() )... ) )>
1215 operator()(_Args&&... __args)
const
1217 return this->__call_c<_Result>(
1218 std::forward_as_tuple(std::forward<_Args>(__args)...),
1223 template<
typename... _Args,
typename _Result
1224 = decltype( std::declval<
typename enable_if<(
sizeof...(_Args) >= 0),
1225 typename add_volatile<_Functor>::type>::type>()(
1226 _Mu<_Bound_args>()( std::declval<volatile _Bound_args&>(),
1227 std::declval<tuple<_Args...>&>() )... ) )>
1229 operator()(_Args&&... __args)
volatile
1231 return this->__call_v<_Result>(
1232 std::forward_as_tuple(std::forward<_Args>(__args)...),
1237 template<
typename... _Args,
typename _Result
1238 = decltype( std::declval<
typename enable_if<(
sizeof...(_Args) >= 0),
1239 typename add_cv<_Functor>::type>::type>()(
1240 _Mu<_Bound_args>()( std::declval<const volatile _Bound_args&>(),
1241 std::declval<tuple<_Args...>&>() )... ) )>
1243 operator()(_Args&&... __args)
const volatile
1245 return this->__call_c_v<_Result>(
1246 std::forward_as_tuple(std::forward<_Args>(__args)...),
1252 template<
typename _Result,
typename _Signature>
1255 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
1263 tuple<_Bound_args...> _M_bound_args;
1266 template<
typename _Res>
1267 struct __enable_if_void :
enable_if<is_void<_Res>::value, int> { };
1268 template<
typename _Res>
1269 struct __disable_if_void :
enable_if<!is_void<_Res>::value, int> { };
1272 template<
typename _Res,
typename... _Args,
int... _Indexes>
1274 __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1275 typename __disable_if_void<_Res>::type = 0)
1277 return _M_f(_Mu<_Bound_args>()
1278 (get<_Indexes>(_M_bound_args), __args)...);
1282 template<
typename _Res,
typename... _Args,
int... _Indexes>
1284 __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1285 typename __enable_if_void<_Res>::type = 0)
1287 _M_f(_Mu<_Bound_args>()
1288 (get<_Indexes>(_M_bound_args), __args)...);
1292 template<
typename _Res,
typename... _Args,
int... _Indexes>
1294 __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1295 typename __disable_if_void<_Res>::type = 0)
const
1297 return _M_f(_Mu<_Bound_args>()
1298 (get<_Indexes>(_M_bound_args), __args)...);
1302 template<
typename _Res,
typename... _Args,
int... _Indexes>
1304 __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1305 typename __enable_if_void<_Res>::type = 0)
const
1307 _M_f(_Mu<_Bound_args>()
1308 (get<_Indexes>(_M_bound_args), __args)...);
1312 template<
typename _Res,
typename... _Args,
int... _Indexes>
1314 __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1315 typename __disable_if_void<_Res>::type = 0)
volatile
1317 return _M_f(_Mu<_Bound_args>()
1318 (__volget<_Indexes>(_M_bound_args), __args)...);
1322 template<
typename _Res,
typename... _Args,
int... _Indexes>
1324 __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1325 typename __enable_if_void<_Res>::type = 0)
volatile
1327 _M_f(_Mu<_Bound_args>()
1328 (__volget<_Indexes>(_M_bound_args), __args)...);
1332 template<
typename _Res,
typename... _Args,
int... _Indexes>
1334 __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
1335 typename __disable_if_void<_Res>::type = 0)
const volatile
1337 return _M_f(_Mu<_Bound_args>()
1338 (__volget<_Indexes>(_M_bound_args), __args)...);
1342 template<
typename _Res,
typename... _Args,
int... _Indexes>
1344 __call(tuple<_Args...>&& __args,
1345 _Index_tuple<_Indexes...>,
1346 typename __enable_if_void<_Res>::type = 0)
const volatile
1348 _M_f(_Mu<_Bound_args>()
1349 (__volget<_Indexes>(_M_bound_args), __args)...);
1353 typedef _Result result_type;
1355 template<
typename... _Args>
1356 explicit _Bind_result(
const _Functor& __f, _Args&&... __args)
1357 : _M_f(__f), _M_bound_args(std::
forward<_Args>(__args)...)
1360 template<
typename... _Args>
1361 explicit _Bind_result(_Functor&& __f, _Args&&... __args)
1362 : _M_f(std::move(__f)), _M_bound_args(std::
forward<_Args>(__args)...)
1365 _Bind_result(
const _Bind_result&) =
default;
1367 _Bind_result(_Bind_result&& __b)
1368 : _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args))
1372 template<
typename... _Args>
1374 operator()(_Args&&... __args)
1376 return this->__call<_Result>(
1377 std::forward_as_tuple(std::forward<_Args>(__args)...),
1382 template<
typename... _Args>
1384 operator()(_Args&&... __args)
const
1386 return this->__call<_Result>(
1387 std::forward_as_tuple(std::forward<_Args>(__args)...),
1392 template<
typename... _Args>
1394 operator()(_Args&&... __args)
volatile
1396 return this->__call<_Result>(
1397 std::forward_as_tuple(std::forward<_Args>(__args)...),
1402 template<
typename... _Args>
1404 operator()(_Args&&... __args)
const volatile
1406 return this->__call<_Result>(
1407 std::forward_as_tuple(std::forward<_Args>(__args)...),
1416 template<
typename _Signature>
1424 template<
typename _Result,
typename _Signature>
1428 template<
typename _Functor,
typename... _ArgTypes>
1433 typedef typename __maybe_type::type __functor_type;
1441 template<
typename _Functor,
typename... _ArgTypes>
1443 typename _Bind_helper<_Functor, _ArgTypes...>::type
1444 bind(_Functor&& __f, _ArgTypes&&... __args)
1446 typedef _Bind_helper<_Functor, _ArgTypes...> __helper_type;
1447 typedef typename __helper_type::__maybe_type __maybe_type;
1448 typedef typename __helper_type::type __result_type;
1449 return __result_type(__maybe_type::__do_wrap(std::forward<_Functor>(__f)),
1450 std::forward<_ArgTypes>(__args)...);
1453 template<
typename _Result,
typename _Functor,
typename... _ArgTypes>
1454 struct _Bindres_helper
1456 typedef _Maybe_wrap_member_pointer<typename decay<_Functor>::type>
1458 typedef typename __maybe_type::type __functor_type;
1459 typedef _Bind_result<_Result,
1460 __functor_type(
typename decay<_ArgTypes>::type...)>
1468 template<
typename _Result,
typename _Functor,
typename... _ArgTypes>
1470 typename _Bindres_helper<_Result, _Functor, _ArgTypes...>::type
1471 bind(_Functor&& __f, _ArgTypes&&... __args)
1473 typedef _Bindres_helper<_Result, _Functor, _ArgTypes...> __helper_type;
1474 typedef typename __helper_type::__maybe_type __maybe_type;
1475 typedef typename __helper_type::type __result_type;
1476 return __result_type(__maybe_type::__do_wrap(std::forward<_Functor>(__f)),
1477 std::forward<_ArgTypes>(__args)...);
1496 template<
typename _Tp>
1499 || is_member_pointer<_Tp>::value)>
1502 class _Undefined_class;
1507 const void* _M_const_object;
1508 void (*_M_function_pointer)();
1509 void (_Undefined_class::*_M_member_pointer)();
1514 void* _M_access() {
return &_M_pod_data[0]; }
1515 const void* _M_access()
const {
return &_M_pod_data[0]; }
1517 template<
typename _Tp>
1520 {
return *
static_cast<_Tp*
>(_M_access()); }
1522 template<
typename _Tp>
1525 {
return *
static_cast<const _Tp*
>(_M_access()); }
1527 _Nocopy_types _M_unused;
1528 char _M_pod_data[
sizeof(_Nocopy_types)];
1531 enum _Manager_operation
1541 template<
typename _Tp>
1542 struct _Simple_type_wrapper
1544 _Simple_type_wrapper(_Tp __value) : __value(__value) { }
1549 template<
typename _Tp>
1550 struct __is_location_invariant<_Simple_type_wrapper<_Tp> >
1551 : __is_location_invariant<_Tp>
1556 template<
typename _Functor>
1558 __callable_functor(_Functor& __f)
1561 template<
typename _Member,
typename _Class>
1562 inline _Mem_fn<_Member _Class::*>
1563 __callable_functor(_Member _Class::* &__p)
1566 template<
typename _Member,
typename _Class>
1567 inline _Mem_fn<_Member _Class::*>
1568 __callable_functor(_Member _Class::*
const &__p)
1571 template<
typename _Signature>
1578 static const std::size_t _M_max_size =
sizeof(_Nocopy_types);
1579 static const std::size_t _M_max_align = __alignof__(_Nocopy_types);
1581 template<
typename _Functor>
1585 static const bool __stored_locally =
1587 &&
sizeof(_Functor) <= _M_max_size
1588 && __alignof__(_Functor) <= _M_max_align
1589 && (_M_max_align % __alignof__(_Functor) == 0));
1595 _M_get_pointer(
const _Any_data& __source)
1597 const _Functor* __ptr =
1598 __stored_locally? std::__addressof(__source._M_access<_Functor>())
1599 : __source._M_access<_Functor*>();
1600 return const_cast<_Functor*
>(__ptr);
1606 _M_clone(_Any_data& __dest,
const _Any_data& __source,
true_type)
1608 new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
1614 _M_clone(_Any_data& __dest,
const _Any_data& __source,
false_type)
1616 __dest._M_access<_Functor*>() =
1617 new _Functor(*__source._M_access<_Functor*>());
1623 _M_destroy(_Any_data& __victim,
true_type)
1625 __victim._M_access<_Functor>().~_Functor();
1632 delete __victim._M_access<_Functor*>();
1637 _M_manager(_Any_data& __dest,
const _Any_data& __source,
1638 _Manager_operation __op)
1643 case __get_type_info:
1644 __dest._M_access<
const type_info*>() = &
typeid(_Functor);
1647 case __get_functor_ptr:
1648 __dest._M_access<_Functor*>() = _M_get_pointer(__source);
1651 case __clone_functor:
1652 _M_clone(__dest, __source, _Local_storage());
1655 case __destroy_functor:
1656 _M_destroy(__dest, _Local_storage());
1663 _M_init_functor(_Any_data& __functor, _Functor&& __f)
1664 { _M_init_functor(__functor, std::move(__f), _Local_storage()); }
1666 template<
typename _Signature>
1668 _M_not_empty_function(
const function<_Signature>& __f)
1669 {
return static_cast<bool>(__f); }
1671 template<
typename _Tp>
1673 _M_not_empty_function(
const _Tp*& __fp)
1676 template<
typename _Class,
typename _Tp>
1678 _M_not_empty_function(_Tp _Class::*
const& __mp)
1681 template<
typename _Tp>
1683 _M_not_empty_function(
const _Tp&)
1688 _M_init_functor(_Any_data& __functor, _Functor&& __f,
true_type)
1689 {
new (__functor._M_access()) _Functor(std::move(__f)); }
1692 _M_init_functor(_Any_data& __functor, _Functor&& __f,
false_type)
1693 { __functor._M_access<_Functor*>() =
new _Functor(std::move(__f)); }
1696 template<
typename _Functor>
1697 class _Ref_manager :
public _Base_manager<_Functor*>
1699 typedef _Function_base::_Base_manager<_Functor*> _Base;
1703 _M_manager(_Any_data& __dest,
const _Any_data& __source,
1704 _Manager_operation __op)
1709 case __get_type_info:
1710 __dest._M_access<
const type_info*>() = &
typeid(_Functor);
1713 case __get_functor_ptr:
1714 __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source);
1719 _Base::_M_manager(__dest, __source, __op);
1728 _Base::_M_init_functor(__functor, &__f.get());
1737 _M_manager(_M_functor, _M_functor, __destroy_functor);
1741 bool _M_empty()
const {
return !_M_manager; }
1743 typedef bool (*_Manager_type)(_Any_data&,
const _Any_data&,
1744 _Manager_operation);
1746 _Any_data _M_functor;
1747 _Manager_type _M_manager;
1750 template<
typename _Signature,
typename _Functor>
1751 class _Function_handler;
1753 template<
typename _Res,
typename _Functor,
typename... _ArgTypes>
1754 class _Function_handler<_Res(_ArgTypes...), _Functor>
1755 :
public _Function_base::_Base_manager<_Functor>
1757 typedef _Function_base::_Base_manager<_Functor> _Base;
1761 _M_invoke(
const _Any_data& __functor, _ArgTypes... __args)
1763 return (*_Base::_M_get_pointer(__functor))(
1764 std::forward<_ArgTypes>(__args)...);
1768 template<
typename _Functor,
typename... _ArgTypes>
1769 class _Function_handler<void(_ArgTypes...), _Functor>
1770 :
public _Function_base::_Base_manager<_Functor>
1772 typedef _Function_base::_Base_manager<_Functor> _Base;
1776 _M_invoke(
const _Any_data& __functor, _ArgTypes... __args)
1778 (*_Base::_M_get_pointer(__functor))(
1779 std::forward<_ArgTypes>(__args)...);
1783 template<
typename _Res,
typename _Functor,
typename... _ArgTypes>
1784 class _Function_handler<_Res(_ArgTypes...), reference_wrapper<_Functor> >
1785 :
public _Function_base::_Ref_manager<_Functor>
1787 typedef _Function_base::_Ref_manager<_Functor> _Base;
1791 _M_invoke(
const _Any_data& __functor, _ArgTypes... __args)
1793 return __callable_functor(**_Base::_M_get_pointer(__functor))(
1794 std::forward<_ArgTypes>(__args)...);
1798 template<
typename _Functor,
typename... _ArgTypes>
1799 class _Function_handler<void(_ArgTypes...), reference_wrapper<_Functor> >
1800 :
public _Function_base::_Ref_manager<_Functor>
1802 typedef _Function_base::_Ref_manager<_Functor> _Base;
1806 _M_invoke(
const _Any_data& __functor, _ArgTypes... __args)
1808 __callable_functor(**_Base::_M_get_pointer(__functor))(
1809 std::forward<_ArgTypes>(__args)...);
1813 template<
typename _Class,
typename _Member,
typename _Res,
1814 typename... _ArgTypes>
1815 class _Function_handler<_Res(_ArgTypes...), _Member _Class::*>
1816 :
public _Function_handler<void(_ArgTypes...), _Member _Class::*>
1818 typedef _Function_handler<void(_ArgTypes...), _Member _Class::*>
1823 _M_invoke(
const _Any_data& __functor, _ArgTypes... __args)
1825 return mem_fn(_Base::_M_get_pointer(__functor)->__value)(
1826 std::forward<_ArgTypes>(__args)...);
1830 template<
typename _Class,
typename _Member,
typename... _ArgTypes>
1831 class _Function_handler<void(_ArgTypes...), _Member _Class::*>
1832 :
public _Function_base::_Base_manager<
1833 _Simple_type_wrapper< _Member _Class::* > >
1835 typedef _Member _Class::* _Functor;
1836 typedef _Simple_type_wrapper<_Functor> _Wrapper;
1837 typedef _Function_base::_Base_manager<_Wrapper> _Base;
1841 _M_manager(_Any_data& __dest,
const _Any_data& __source,
1842 _Manager_operation __op)
1847 case __get_type_info:
1848 __dest._M_access<
const type_info*>() = &
typeid(_Functor);
1851 case __get_functor_ptr:
1852 __dest._M_access<_Functor*>() =
1853 &_Base::_M_get_pointer(__source)->__value;
1857 _Base::_M_manager(__dest, __source, __op);
1863 _M_invoke(
const _Any_data& __functor, _ArgTypes... __args)
1865 mem_fn(_Base::_M_get_pointer(__functor)->__value)(
1866 std::forward<_ArgTypes>(__args)...);
1876 template<
typename _Res,
typename... _ArgTypes>
1877 class function<_Res(_ArgTypes...)>
1881 typedef _Res _Signature_type(_ArgTypes...);
1883 struct _Useless { };
1886 typedef _Res result_type;
1910 function(
const function& __x);
1942 template<
typename _Functor>
1943 function(_Functor __f,
1963 function(__x).swap(*
this);
1981 function(std::move(__x)).swap(*
this);
1997 _M_manager(_M_functor, _M_functor, __destroy_functor);
2020 template<
typename _Functor>
2024 function(std::forward<_Functor>(__f)).swap(*
this);
2029 template<
typename _Functor>
2033 function(__f).swap(*
this);
2048 std::swap(_M_functor, __x._M_functor);
2049 std::swap(_M_manager, __x._M_manager);
2050 std::swap(_M_invoker, __x._M_invoker);
2074 explicit operator bool()
const
2075 {
return !_M_empty(); }
2087 _Res operator()(_ArgTypes... __args)
const;
2111 template<
typename _Functor> _Functor* target();
2114 template<
typename _Functor>
const _Functor* target()
const;
2118 typedef _Res (*_Invoker_type)(
const _Any_data&, _ArgTypes...);
2119 _Invoker_type _M_invoker;
2123 template<
typename _Res,
typename... _ArgTypes>
2124 function<_Res(_ArgTypes...)>::
2125 function(
const function& __x)
2128 if (static_cast<bool>(__x))
2130 _M_invoker = __x._M_invoker;
2131 _M_manager = __x._M_manager;
2132 __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
2136 template<
typename _Res,
typename... _ArgTypes>
2137 template<
typename _Functor>
2138 function<_Res(_ArgTypes...)>::
2139 function(_Functor __f,
2144 typedef _Function_handler<_Signature_type, _Functor> _My_handler;
2146 if (_My_handler::_M_not_empty_function(__f))
2148 _M_invoker = &_My_handler::_M_invoke;
2149 _M_manager = &_My_handler::_M_manager;
2150 _My_handler::_M_init_functor(_M_functor, std::move(__f));
2154 template<
typename _Res,
typename... _ArgTypes>
2156 function<_Res(_ArgTypes...)>::
2157 operator()(_ArgTypes... __args)
const
2160 __throw_bad_function_call();
2161 return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
2165 template<
typename _Res,
typename... _ArgTypes>
2167 function<_Res(_ArgTypes...)>::
2172 _Any_data __typeinfo_result;
2173 _M_manager(__typeinfo_result, _M_functor, __get_type_info);
2174 return *__typeinfo_result._M_access<
const type_info*>();
2177 return typeid(void);
2180 template<
typename _Res,
typename... _ArgTypes>
2181 template<
typename _Functor>
2183 function<_Res(_ArgTypes...)>::
2186 if (
typeid(_Functor) == target_type() && _M_manager)
2189 if (_M_manager(__ptr, _M_functor, __get_functor_ptr)
2193 return __ptr._M_access<_Functor*>();
2199 template<
typename _Res,
typename... _ArgTypes>
2200 template<
typename _Functor>
2202 function<_Res(_ArgTypes...)>::
2205 if (
typeid(_Functor) == target_type() && _M_manager)
2208 _M_manager(__ptr, _M_functor, __get_functor_ptr);
2209 return __ptr._M_access<
const _Functor*>();
2225 template<
typename _Res,
typename... _Args>
2227 operator==(
const function<_Res(_Args...)>& __f, nullptr_t)
2228 {
return !
static_cast<bool>(__f); }
2231 template<
typename _Res,
typename... _Args>
2233 operator==(nullptr_t,
const function<_Res(_Args...)>& __f)
2234 {
return !
static_cast<bool>(__f); }
2243 template<
typename _Res,
typename... _Args>
2245 operator!=(
const function<_Res(_Args...)>& __f, nullptr_t)
2246 {
return static_cast<bool>(__f); }
2249 template<
typename _Res,
typename... _Args>
2251 operator!=(nullptr_t,
const function<_Res(_Args...)>& __f)
2252 {
return static_cast<bool>(__f); }
2261 template<
typename _Res,
typename... _Args>
2263 swap(
function<_Res(_Args...)>& __x,
function<_Res(_Args...)>& __y)
2266 _GLIBCXX_END_NAMESPACE_VERSION
2269 #endif // __GXX_EXPERIMENTAL_CXX0X__
2271 #endif // _GLIBCXX_FUNCTIONAL
Type of the function object returned from bind<R>().
#define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE)
_Bind_helper< _Functor, _ArgTypes...>::type bind(_Functor &&__f, _ArgTypes &&...__args)
Function template for std::bind.
Base class of all polymorphic function object wrappers.
Primary class template for reference_wrapper.
Determines if the given type _Tp is a function object should be treated as a subexpression when evalu...
function & operator=(nullptr_t)
Function assignment to zero.
enable_if< (!is_member_pointer< _Functor >::value &&!is_function< _Functor >::value &&!is_function< typename remove_pointer< _Functor >::type >::value), typename result_of< _Functor(_Args &&...)>::type >::type __invoke(_Functor &__f, _Args &&...__args)
Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
Type of the function object returned from bind().
reference_wrapper< _Tp > ref(_Tp &__t)
Denotes a reference should be taken to a variable.
enable_if<!is_integral< _Functor >::value, function & >::type operator=(_Functor &&__f)
Function assignment to a new target.
Exception class thrown when class template function's operator() is called with an empty target...
_Mem_fn< _Tp _Class::* > mem_fn(_Tp _Class::*__pm)
Returns a function object that forwards to the member pointer pm.
Determines if the type _Tp derives from unary_function.
void swap(function &__x)
Swap the targets of two function objects.
function & operator=(function &&__x)
Function move-assignment operator.
enable_if<!is_integral< _Functor >::value, function & >::type operator=(reference_wrapper< _Functor > __f)
Determines if the type _Tp derives from binary_function.
If we have found a result_type, extract it.
function & operator=(const function &__x)
Function assignment operator.
reference_wrapper< const _Tp > cref(const _Tp &__t)
Denotes a const reference should be taken to a variable.
Base class for all library exceptions.
Determines if the given type _Tp is a placeholder in a bind() expression and, if so, which placeholder it is. [TR1 3.6.2].
_Tp && forward(typename std::remove_reference< _Tp >::type &__t)
forward (as per N3143)
The type of placeholder objects defined by libstdc++.