43 #ifndef _GLIBCXX_FUNCTIONAL
44 #define _GLIBCXX_FUNCTIONAL 1
46 #pragma GCC system_header
51 #if __cplusplus >= 201103L
60 #if __cplusplus > 201402L
66 #if __cplusplus > 201703L
70 #if __cplusplus > 202002L
76 namespace std _GLIBCXX_VISIBILITY(default)
78 _GLIBCXX_BEGIN_NAMESPACE_VERSION
86 #if __cplusplus >= 201103L
88 #if __cplusplus >= 201703L
89 # define __cpp_lib_invoke 201411L
90 # if __cplusplus > 201703L
91 # define __cpp_lib_constexpr_functional 201907L
105 template<
typename _Callable,
typename... _Args>
107 invoke(_Callable&& __fn, _Args&&... __args)
108 noexcept(is_nothrow_invocable_v<_Callable, _Args...>)
110 return std::__invoke(std::forward<_Callable>(__fn),
111 std::forward<_Args>(__args)...);
114 #if __cplusplus > 202002L
115 # define __cpp_lib_invoke_r 202106L
124 template<
typename _Res,
typename _Callable,
typename... _Args>
125 requires is_invocable_r_v<_Res, _Callable, _Args...>
127 invoke_r(_Callable&& __fn, _Args&&... __args)
128 noexcept(is_nothrow_invocable_r_v<_Res, _Callable, _Args...>)
130 return std::__invoke_r<_Res>(std::forward<_Callable>(__fn),
131 std::forward<_Args>(__args)...);
138 template<
typename _MemFunPtr,
139 bool __is_mem_fn = is_member_function_pointer<_MemFunPtr>::value>
141 :
public _Mem_fn_traits<_MemFunPtr>::__maybe_type
143 using _Traits = _Mem_fn_traits<_MemFunPtr>;
145 using _Arity =
typename _Traits::__arity;
146 using _Varargs =
typename _Traits::__vararg;
148 template<
typename _Func,
typename... _BoundArgs>
149 friend struct _Bind_check_arity;
155 using result_type =
typename _Traits::__result_type;
158 _Mem_fn_base(_MemFunPtr __pmf) noexcept : _M_pmf(__pmf) { }
160 template<
typename... _Args>
163 operator()(_Args&&... __args) const
165 std::__invoke(_M_pmf, std::
forward<_Args>(__args)...)))
166 -> decltype(std::__invoke(_M_pmf, std::
forward<_Args>(__args)...))
167 {
return std::__invoke(_M_pmf, std::forward<_Args>(__args)...); }
171 template<
typename _MemObjPtr>
172 class _Mem_fn_base<_MemObjPtr, false>
174 using _Arity = integral_constant<size_t, 0>;
177 template<
typename _Func,
typename... _BoundArgs>
178 friend struct _Bind_check_arity;
184 _Mem_fn_base(_MemObjPtr __pm) noexcept : _M_pm(__pm) { }
186 template<
typename _Tp>
189 operator()(_Tp&& __obj) const
190 noexcept(noexcept(std::__invoke(_M_pm, std::
forward<_Tp>(__obj))))
191 -> decltype(std::__invoke(_M_pm, std::
forward<_Tp>(__obj)))
192 {
return std::__invoke(_M_pm, std::forward<_Tp>(__obj)); }
195 template<
typename _MemberPo
inter>
198 template<
typename _Res,
typename _Class>
199 struct _Mem_fn<_Res _Class::*>
200 : _Mem_fn_base<_Res _Class::*>
202 using _Mem_fn_base<_Res _Class::*>::_Mem_fn_base;
231 template<
typename _Tp,
typename _Class>
233 inline _Mem_fn<_Tp _Class::*>
236 return _Mem_fn<_Tp _Class::*>(__pm);
250 template<
typename _Tp>
262 template<
typename _Tp>
267 #if __cplusplus > 201402L
268 template <
typename _Tp>
inline constexpr
bool is_bind_expression_v
270 template <
typename _Tp>
inline constexpr
int is_placeholder_v
279 namespace placeholders
335 template<std::
size_t __i,
typename _Tuple>
336 using _Safe_tuple_element_t
337 =
typename enable_if<(__i < tuple_size<_Tuple>::value),
338 tuple_element<__i, _Tuple>>::type::type;
351 template<
typename _Arg,
352 bool _IsBindExp = is_bind_expression<_Arg>::value,
353 bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
361 template<
typename _Tp>
362 class _Mu<reference_wrapper<_Tp>, false, false>
369 template<
typename _CVRef,
typename _Tuple>
372 operator()(_CVRef& __arg, _Tuple&)
const volatile
373 {
return __arg.get(); }
382 template<
typename _Arg>
383 class _Mu<_Arg, true, false>
386 template<
typename _CVArg,
typename... _Args>
389 operator()(_CVArg& __arg,
390 tuple<_Args...>& __tuple)
const volatile
391 -> decltype(__arg(declval<_Args>()...))
394 typedef typename _Build_index_tuple<
sizeof...(_Args)>::__type
396 return this->__call(__arg, __tuple, _Indexes());
402 template<
typename _CVArg,
typename... _Args, std::size_t... _Indexes>
405 __call(_CVArg& __arg, tuple<_Args...>& __tuple,
406 const _Index_tuple<_Indexes...>&) const volatile
407 -> decltype(__arg(
declval<_Args>()...))
409 return __arg(std::get<_Indexes>(
std::move(__tuple))...);
418 template<
typename _Arg>
419 class _Mu<_Arg, false, true>
422 template<
typename _Tuple>
424 _Safe_tuple_element_t<(is_placeholder<_Arg>::value - 1), _Tuple>&&
425 operator()(
const volatile _Arg&, _Tuple& __tuple)
const volatile
428 ::std::get<(is_placeholder<_Arg>::value - 1)>(
std::move(__tuple));
437 template<
typename _Arg>
438 class _Mu<_Arg, false, false>
441 template<
typename _CVArg,
typename _Tuple>
444 operator()(_CVArg&& __arg, _Tuple&)
const volatile
445 {
return std::forward<_CVArg>(__arg); }
449 template<std::size_t _Ind,
typename... _Tp>
451 __volget(
volatile tuple<_Tp...>& __tuple)
452 -> __tuple_element_t<_Ind, tuple<_Tp...>>
volatile&
453 {
return std::get<_Ind>(
const_cast<tuple<_Tp...
>&>(__tuple)); }
456 template<std::size_t _Ind,
typename... _Tp>
458 __volget(
const volatile tuple<_Tp...>& __tuple)
459 -> __tuple_element_t<_Ind, tuple<_Tp...>>
const volatile&
460 {
return std::get<_Ind>(
const_cast<const tuple<_Tp...
>&>(__tuple)); }
465 template<
typename _Signature>
468 template<
typename _Functor,
typename... _Bound_args>
469 class _Bind<_Functor(_Bound_args...)>
470 :
public _Weak_result_type<_Functor>
472 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
476 tuple<_Bound_args...> _M_bound_args;
479 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
484 return std::__invoke(_M_f,
485 _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
490 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
495 return std::__invoke(_M_f,
496 _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
501 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
503 __call_v(tuple<_Args...>&& __args,
504 _Index_tuple<_Indexes...>)
volatile
506 return std::__invoke(_M_f,
507 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
512 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
514 __call_c_v(tuple<_Args...>&& __args,
515 _Index_tuple<_Indexes...>)
const volatile
517 return std::__invoke(_M_f,
518 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
522 template<
typename _BoundArg,
typename _CallArgs>
523 using _Mu_type = decltype(
524 _Mu<
typename remove_cv<_BoundArg>::type>()(
525 std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );
527 template<
typename _Fn,
typename _CallArgs,
typename... _BArgs>
529 =
typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
531 template<
typename _CallArgs>
532 using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
534 template<
typename _CallArgs>
535 using __dependent =
typename
536 enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
538 template<
typename _CallArgs,
template<
class>
class __cv_quals>
539 using _Res_type_cv = _Res_type_impl<
540 typename __cv_quals<__dependent<_CallArgs>>::type,
542 typename __cv_quals<_Bound_args>::type...>;
545 template<
typename... _Args>
546 explicit _GLIBCXX20_CONSTEXPR
547 _Bind(
const _Functor& __f, _Args&&... __args)
548 : _M_f(__f), _M_bound_args(std::
forward<_Args>(__args)...)
551 template<
typename... _Args>
552 explicit _GLIBCXX20_CONSTEXPR
553 _Bind(_Functor&& __f, _Args&&... __args)
554 : _M_f(std::
move(__f)), _M_bound_args(std::
forward<_Args>(__args)...)
557 _Bind(
const _Bind&) =
default;
558 _Bind(_Bind&&) =
default;
561 template<
typename... _Args,
562 typename _Result = _Res_type<tuple<_Args...>>>
565 operator()(_Args&&... __args)
567 return this->__call<_Result>(
573 template<
typename... _Args,
574 typename _Result = _Res_type_cv<tuple<_Args...>, add_const>>
577 operator()(_Args&&... __args)
const
579 return this->__call_c<_Result>(
584 #if __cplusplus > 201402L
585 # define _GLIBCXX_DEPR_BIND \
586 [[deprecated("std::bind does not support volatile in C++17")]]
588 # define _GLIBCXX_DEPR_BIND
591 template<
typename... _Args,
592 typename _Result = _Res_type_cv<tuple<_Args...>, add_volatile>>
595 operator()(_Args&&... __args)
volatile
597 return this->__call_v<_Result>(
603 template<
typename... _Args,
604 typename _Result = _Res_type_cv<tuple<_Args...>, add_cv>>
607 operator()(_Args&&... __args)
const volatile
609 return this->__call_c_v<_Result>(
616 template<
typename _Result,
typename _Signature>
619 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
622 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
626 tuple<_Bound_args...> _M_bound_args;
629 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
634 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
635 (std::get<_Indexes>(_M_bound_args), __args)...);
639 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
644 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
645 (std::get<_Indexes>(_M_bound_args), __args)...);
649 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
654 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
655 (__volget<_Indexes>(_M_bound_args), __args)...);
659 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
663 _Index_tuple<_Indexes...>)
const volatile
665 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
666 (__volget<_Indexes>(_M_bound_args), __args)...);
670 typedef _Result result_type;
672 template<
typename... _Args>
673 explicit _GLIBCXX20_CONSTEXPR
675 : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
678 template<
typename... _Args>
679 explicit _GLIBCXX20_CONSTEXPR
680 _Bind_result(_Functor&& __f, _Args&&... __args)
681 : _M_f(
std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
684 _Bind_result(
const _Bind_result&) =
default;
685 _Bind_result(_Bind_result&&) =
default;
688 template<
typename... _Args>
691 operator()(_Args&&... __args)
693 return this->__call<_Result>(
699 template<
typename... _Args>
702 operator()(_Args&&... __args)
const
704 return this->__call<_Result>(
710 template<
typename... _Args>
713 operator()(_Args&&... __args)
volatile
715 return this->__call<_Result>(
721 template<
typename... _Args>
724 operator()(_Args&&... __args)
const volatile
726 return this->__call<_Result>(
731 #undef _GLIBCXX_DEPR_BIND
737 template<
typename _Signature>
745 template<
typename _Signature>
753 template<
typename _Signature>
761 template<
typename _Signature>
769 template<
typename _Result,
typename _Signature>
777 template<
typename _Result,
typename _Signature>
785 template<
typename _Result,
typename _Signature>
793 template<
typename _Result,
typename _Signature>
797 template<
typename _Func,
typename... _BoundArgs>
798 struct _Bind_check_arity { };
800 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
801 struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
803 static_assert(
sizeof...(_BoundArgs) ==
sizeof...(_Args),
804 "Wrong number of arguments for function");
807 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
808 struct _Bind_check_arity<_Ret (*)(_Args......), _BoundArgs...>
810 static_assert(
sizeof...(_BoundArgs) >=
sizeof...(_Args),
811 "Wrong number of arguments for function");
814 template<
typename _Tp,
typename _Class,
typename... _BoundArgs>
815 struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
817 using _Arity =
typename _Mem_fn<_Tp _Class::*>::_Arity;
818 using _Varargs =
typename _Mem_fn<_Tp _Class::*>::_Varargs;
819 static_assert(_Varargs::value
820 ?
sizeof...(_BoundArgs) >= _Arity::value + 1
821 :
sizeof...(_BoundArgs) == _Arity::value + 1,
822 "Wrong number of arguments for pointer-to-member");
828 template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
829 using __is_socketlike = __or_<is_integral<_Tp2>, is_enum<_Tp2>>;
831 template<
bool _SocketLike,
typename _Func,
typename... _BoundArgs>
833 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
835 typedef typename decay<_Func>::type __func_type;
836 typedef _Bind<__func_type(typename decay<_BoundArgs>::type...)> type;
842 template<
typename _Func,
typename... _BoundArgs>
843 struct _Bind_helper<true, _Func, _BoundArgs...>
851 template<
typename _Func,
typename... _BoundArgs>
852 inline _GLIBCXX20_CONSTEXPR
typename
853 _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
854 bind(_Func&& __f, _BoundArgs&&... __args)
856 typedef _Bind_helper<
false, _Func, _BoundArgs...> __helper_type;
857 return typename __helper_type::type(std::forward<_Func>(__f),
858 std::forward<_BoundArgs>(__args)...);
861 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
862 struct _Bindres_helper
863 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
865 typedef typename decay<_Func>::type __functor_type;
866 typedef _Bind_result<_Result,
867 __functor_type(
typename decay<_BoundArgs>::type...)>
876 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
877 inline _GLIBCXX20_CONSTEXPR
878 typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
879 bind(_Func&& __f, _BoundArgs&&... __args)
881 typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
882 return typename __helper_type::type(std::forward<_Func>(__f),
883 std::forward<_BoundArgs>(__args)...);
886 #if __cplusplus > 201703L
887 #define __cpp_lib_bind_front 201907L
889 template<
typename _Fd,
typename... _BoundArgs>
892 static_assert(is_move_constructible_v<_Fd>);
893 static_assert((is_move_constructible_v<_BoundArgs> && ...));
897 template<
typename _Fn,
typename... _Args>
899 _Bind_front(
int, _Fn&& __fn, _Args&&... __args)
900 noexcept(__and_<is_nothrow_constructible<_Fd, _Fn>,
901 is_nothrow_constructible<_BoundArgs, _Args>...>::value)
902 : _M_fd(std::
forward<_Fn>(__fn)),
903 _M_bound_args(std::
forward<_Args>(__args)...)
904 { static_assert(
sizeof...(_Args) ==
sizeof...(_BoundArgs)); }
906 _Bind_front(
const _Bind_front&) =
default;
907 _Bind_front(_Bind_front&&) =
default;
908 _Bind_front& operator=(
const _Bind_front&) =
default;
909 _Bind_front& operator=(_Bind_front&&) =
default;
910 ~_Bind_front() =
default;
912 template<
typename... _CallArgs>
915 operator()(_CallArgs&&... __call_args) &
916 noexcept(is_nothrow_invocable_v<_Fd&, _BoundArgs&..., _CallArgs...>)
918 return _S_call(*
this, _BoundIndices(),
919 std::forward<_CallArgs>(__call_args)...);
922 template<
typename... _CallArgs>
925 operator()(_CallArgs&&... __call_args) const &
926 noexcept(is_nothrow_invocable_v<const _Fd&, const _BoundArgs&...,
929 return _S_call(*
this, _BoundIndices(),
930 std::forward<_CallArgs>(__call_args)...);
933 template<
typename... _CallArgs>
936 operator()(_CallArgs&&... __call_args) &&
937 noexcept(is_nothrow_invocable_v<_Fd, _BoundArgs..., _CallArgs...>)
939 return _S_call(
std::move(*
this), _BoundIndices(),
940 std::forward<_CallArgs>(__call_args)...);
943 template<
typename... _CallArgs>
946 operator()(_CallArgs&&... __call_args) const &&
947 noexcept(is_nothrow_invocable_v<const _Fd, const _BoundArgs...,
950 return _S_call(
std::move(*
this), _BoundIndices(),
951 std::forward<_CallArgs>(__call_args)...);
957 template<
typename _Tp,
size_t... _Ind,
typename... _CallArgs>
960 _S_call(_Tp&& __g,
index_sequence<_Ind...>, _CallArgs&&... __call_args)
962 return std::invoke(std::forward<_Tp>(__g)._M_fd,
963 std::get<_Ind>(std::forward<_Tp>(__g)._M_bound_args)...,
964 std::forward<_CallArgs>(__call_args)...);
971 template<
typename _Fn,
typename... _Args>
973 = _Bind_front<decay_t<_Fn>, decay_t<_Args>...>;
984 template<
typename _Fn,
typename... _Args>
985 constexpr _Bind_front_t<_Fn, _Args...>
986 bind_front(_Fn&& __fn, _Args&&... __args)
987 noexcept(is_nothrow_constructible_v<_Bind_front_t<_Fn, _Args...>,
990 return _Bind_front_t<_Fn, _Args...>(0, std::forward<_Fn>(__fn),
991 std::forward<_Args>(__args)...);
995 #if __cplusplus >= 201402L
997 template<
typename _Fn>
1000 template<
typename _Fn2,
typename... _Args>
1001 using __inv_res_t =
typename __invoke_result<_Fn2, _Args...>::type;
1003 template<
typename _Tp>
1004 static decltype(!std::declval<_Tp>())
1005 _S_not() noexcept(noexcept(!std::declval<_Tp>()));
1008 template<
typename _Fn2>
1011 : _M_fn(std::forward<_Fn2>(__fn)) { }
1013 _Not_fn(
const _Not_fn& __fn) =
default;
1014 _Not_fn(_Not_fn&& __fn) =
default;
1015 ~_Not_fn() =
default;
1020 #define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \
1021 template<typename... _Args> \
1022 _GLIBCXX20_CONSTEXPR \
1023 decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \
1024 operator()(_Args&&... __args) _QUALS \
1025 noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \
1026 && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \
1028 return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \
1029 std::forward<_Args>(__args)...); \
1031 _GLIBCXX_NOT_FN_CALL_OP( & )
1032 _GLIBCXX_NOT_FN_CALL_OP(
const & )
1033 _GLIBCXX_NOT_FN_CALL_OP( && )
1034 _GLIBCXX_NOT_FN_CALL_OP(
const && )
1035 #undef _GLIBCXX_NOT_FN_CALL_OP
1041 template<
typename _Tp,
typename _Pred>
1044 template<
typename _Tp>
1045 struct __is_byte_like<_Tp, equal_to<_Tp>>
1046 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
1048 template<
typename _Tp>
1049 struct __is_byte_like<_Tp, equal_to<void>>
1050 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
1052 #if __cplusplus >= 201703L
1054 enum class byte : unsigned char;
1057 struct __is_byte_like<byte, equal_to<byte>>
1061 struct __is_byte_like<
byte, equal_to<void>>
1065 #define __cpp_lib_not_fn 201603L
1078 template<
typename _Fn>
1079 _GLIBCXX20_CONSTEXPR
1088 #define __cpp_lib_boyer_moore_searcher 201603L
1090 template<
typename _ForwardIterator1,
typename _BinaryPredicate = equal_to<>>
1091 class default_searcher
1094 _GLIBCXX20_CONSTEXPR
1095 default_searcher(_ForwardIterator1 __pat_first,
1096 _ForwardIterator1 __pat_last,
1097 _BinaryPredicate __pred = _BinaryPredicate())
1098 : _M_m(__pat_first, __pat_last,
std::move(__pred))
1101 template<
typename _ForwardIterator2>
1102 _GLIBCXX20_CONSTEXPR
1104 operator()(_ForwardIterator2 __first, _ForwardIterator2 __last)
const
1106 _ForwardIterator2 __first_ret =
1107 std::search(__first, __last, std::get<0>(_M_m), std::get<1>(_M_m),
1109 auto __ret = std::make_pair(__first_ret, __first_ret);
1110 if (__ret.first != __last)
1112 std::get<1>(_M_m)));
1120 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred>
1121 struct __boyer_moore_map_base
1123 template<
typename _RAIter>
1124 __boyer_moore_map_base(_RAIter __pat,
size_t __patlen,
1125 _Hash&& __hf, _Pred&& __pred)
1129 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1130 _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
1133 using __diff_type = _Tp;
1136 _M_lookup(_Key __key, __diff_type __not_found)
const
1138 auto __iter = _M_bad_char.find(__key);
1139 if (__iter == _M_bad_char.end())
1141 return __iter->second;
1145 _M_pred()
const {
return _M_bad_char.key_eq(); }
1147 _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
1150 template<
typename _Tp,
size_t _Len,
typename _Pred>
1151 struct __boyer_moore_array_base
1153 template<
typename _RAIter,
typename _Unused>
1154 __boyer_moore_array_base(_RAIter __pat,
size_t __patlen,
1155 _Unused&&, _Pred&& __pred)
1158 std::get<0>(_M_bad_char).fill(__patlen);
1160 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1162 auto __ch = __pat[__i];
1164 auto __uch =
static_cast<_UCh
>(__ch);
1165 std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
1169 using __diff_type = _Tp;
1171 template<
typename _Key>
1173 _M_lookup(_Key __key, __diff_type __not_found)
const
1178 return std::get<0>(_M_bad_char)[__ukey];
1182 _M_pred()
const {
return std::get<1>(_M_bad_char); }
1189 template<
typename _RAIter,
typename _Hash,
typename _Pred,
1192 using __boyer_moore_base_t
1193 = __conditional_t<__is_byte_like<_Val, _Pred>::value,
1194 __boyer_moore_array_base<_Diff, 256, _Pred>,
1195 __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
1197 template<
typename _RAIter,
typename _Hash
1200 class boyer_moore_searcher
1201 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1203 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1204 using typename _Base::__diff_type;
1207 boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1208 _Hash __hf = _Hash(),
1209 _BinaryPredicate __pred = _BinaryPredicate());
1211 template<
typename _RandomAccessIterator2>
1213 operator()(_RandomAccessIterator2 __first,
1214 _RandomAccessIterator2 __last)
const;
1218 _M_is_prefix(_RAIter __word, __diff_type __len,
1221 const auto& __pred = this->_M_pred();
1222 __diff_type __suffixlen = __len - __pos;
1223 for (__diff_type __i = 0; __i < __suffixlen; ++__i)
1224 if (!__pred(__word[__i], __word[__pos + __i]))
1230 _M_suffix_length(_RAIter __word, __diff_type __len,
1233 const auto& __pred = this->_M_pred();
1234 __diff_type __i = 0;
1235 while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
1243 template<
typename _Tp>
1245 _M_bad_char_shift(_Tp __c)
const
1246 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1250 _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
1253 template<
typename _RAIter,
typename _Hash
1256 class boyer_moore_horspool_searcher
1257 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1259 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1260 using typename _Base::__diff_type;
1263 boyer_moore_horspool_searcher(_RAIter __pat,
1265 _Hash __hf = _Hash(),
1266 _BinaryPredicate __pred
1267 = _BinaryPredicate())
1269 _M_pat(__pat), _M_pat_end(__pat_end)
1272 template<
typename _RandomAccessIterator2>
1274 operator()(_RandomAccessIterator2 __first,
1275 _RandomAccessIterator2 __last)
const
1277 const auto& __pred = this->_M_pred();
1278 auto __patlen = _M_pat_end - _M_pat;
1280 return std::make_pair(__first, __first);
1281 auto __len = __last - __first;
1282 while (__len >= __patlen)
1284 for (
auto __scan = __patlen - 1;
1285 __pred(__first[__scan], _M_pat[__scan]); --__scan)
1287 return std::make_pair(__first, __first + __patlen);
1288 auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
1292 return std::make_pair(__last, __last);
1296 template<
typename _Tp>
1298 _M_bad_char_shift(_Tp __c)
const
1299 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1305 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1306 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1307 boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
1308 _Hash __hf, _BinaryPredicate __pred)
1310 _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
1312 auto __patlen = __pat_end - __pat;
1315 __diff_type __last_prefix = __patlen - 1;
1316 for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
1318 if (_M_is_prefix(__pat, __patlen, __p + 1))
1319 __last_prefix = __p + 1;
1320 _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
1322 for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
1324 auto __slen = _M_suffix_length(__pat, __patlen, __p);
1325 auto __pos = __patlen - 1 - __slen;
1326 if (!__pred(__pat[__p - __slen], __pat[__pos]))
1327 _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
1331 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1332 template<
typename _RandomAccessIterator2>
1334 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1335 operator()(_RandomAccessIterator2 __first,
1336 _RandomAccessIterator2 __last)
const
1338 auto __patlen = _M_pat_end - _M_pat;
1340 return std::make_pair(__first, __first);
1341 const auto& __pred = this->_M_pred();
1342 __diff_type __i = __patlen - 1;
1343 auto __stringlen = __last - __first;
1344 while (__i < __stringlen)
1346 __diff_type __j = __patlen - 1;
1347 while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
1354 const auto __match = __first + __i + 1;
1355 return std::make_pair(__match, __match + __patlen);
1357 __i +=
std::max(_M_bad_char_shift(__first[__i]),
1358 _M_good_suffix[__j]);
1360 return std::make_pair(__last, __last);
1367 _GLIBCXX_END_NAMESPACE_VERSION
1370 #endif // _GLIBCXX_FUNCTIONAL
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
A standard container for storing a fixed size sequence of elements.
Primary class template, tuple.
Traits class for iterators.
constexpr _ForwardIterator search(_ForwardIterator __first, _ForwardIterator __last, const _Searcher &__searcher)
Search a sequence using a Searcher object.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr _Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs...>::type bind(_Func &&__f, _BoundArgs &&...__args)
Function template for std::bind.
Determines if the given type _Tp is a placeholder in a bind() expression and, if so, which placeholder it is.
constexpr tuple< _Elements &&...> forward_as_tuple(_Elements &&...__args) noexcept
std::forward_as_tuple
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Trait that identifies a bind expression.
The type of placeholder objects defined by libstdc++.
Type of the function object returned from bind<R>().
One of the comparison functors.
typename invoke_result< _Fn, _Args...>::type invoke_result_t
std::invoke_result_t
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
integer_sequence< size_t, _Idx...> index_sequence
Alias template index_sequence.
Type of the function object returned from bind().
typename decay< _Tp >::type decay_t
Alias template for decay.
Struct holding two objects of arbitrary type.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr _Mem_fn< _Tp _Class::* > mem_fn(_Tp _Class::*__pm) noexcept
Returns a function object that forwards to the member pointer pointer pm.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
make_index_sequence< sizeof...(_Types)> index_sequence_for
Alias template index_sequence_for.
auto declval() noexcept-> decltype(__declval< _Tp >(0))
Primary class template hash.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.