43 #ifndef _GLIBCXX_FUNCTIONAL 44 #define _GLIBCXX_FUNCTIONAL 1 46 #pragma GCC system_header 51 #if __cplusplus >= 201103L 58 #include <bits/std_function.h> 59 #if __cplusplus > 201402L 60 # include <unordered_map> 67 namespace std _GLIBCXX_VISIBILITY(default)
69 _GLIBCXX_BEGIN_NAMESPACE_VERSION
71 #if __cplusplus > 201402L 72 # define __cpp_lib_invoke 201411 75 template<
typename _Callable,
typename... _Args>
76 inline result_of_t<_Callable&&(_Args&&...)>
77 invoke(_Callable&& __fn, _Args&&... __args)
78 noexcept(is_nothrow_callable_v<_Callable&&(_Args&&...)>)
81 std::forward<_Args>(__args)...);
85 template<
typename... _Types>
86 struct _Pack : integral_constant<size_t, sizeof...(_Types)>
89 template<
typename _From,
typename _To,
bool = _From::value == _To::value>
93 template<
typename... _From,
typename... _To>
94 struct _AllConvertible<_Pack<_From...>, _Pack<_To...>, true>
95 : __and_<is_convertible<_From, _To>...>
98 template<
typename _Tp1,
typename _Tp2>
99 using _NotSame = __not_<is_same<typename std::decay<_Tp1>::type,
100 typename std::decay<_Tp2>::type>>;
102 template<
typename _Signature>
103 struct _Mem_fn_traits;
105 template<
typename _Res,
typename _Class,
typename... _ArgTypes>
106 struct _Mem_fn_traits_base
108 using __result_type = _Res;
110 = _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...>;
111 using __arity = integral_constant<size_t,
sizeof...(_ArgTypes)>;
114 #define _GLIBCXX_MEM_FN_TRAITS2(_CV, _REF, _LVAL, _RVAL) \ 115 template<typename _Res, typename _Class, typename... _ArgTypes> \ 116 struct _Mem_fn_traits<_Res (_Class::*)(_ArgTypes...) _CV _REF> \ 117 : _Mem_fn_traits_base<_Res, _CV _Class, _ArgTypes...> \ 119 using __vararg = false_type; \ 121 template<typename _Res, typename _Class, typename... _ArgTypes> \ 122 struct _Mem_fn_traits<_Res (_Class::*)(_ArgTypes... ...) _CV _REF> \ 123 : _Mem_fn_traits_base<_Res, _CV _Class, _ArgTypes...> \ 125 using __vararg = true_type; \ 128 #define _GLIBCXX_MEM_FN_TRAITS(_REF, _LVAL, _RVAL) \ 129 _GLIBCXX_MEM_FN_TRAITS2( , _REF, _LVAL, _RVAL) \ 130 _GLIBCXX_MEM_FN_TRAITS2(const , _REF, _LVAL, _RVAL) \ 131 _GLIBCXX_MEM_FN_TRAITS2(volatile , _REF, _LVAL, _RVAL) \ 132 _GLIBCXX_MEM_FN_TRAITS2(const volatile, _REF, _LVAL, _RVAL) 138 #undef _GLIBCXX_MEM_FN_TRAITS 139 #undef _GLIBCXX_MEM_FN_TRAITS2 141 template<
typename _MemFunPtr,
142 bool __is_mem_fn = is_member_function_pointer<_MemFunPtr>::value>
144 :
public _Mem_fn_traits<_MemFunPtr>::__maybe_type
146 using _Traits = _Mem_fn_traits<_MemFunPtr>;
148 using _Arity =
typename _Traits::__arity;
149 using _Varargs =
typename _Traits::__vararg;
151 template<
typename _Func,
typename... _BoundArgs>
152 friend struct _Bind_check_arity;
158 using result_type =
typename _Traits::__result_type;
161 _Mem_fn_base(_MemFunPtr __pmf) noexcept : _M_pmf(__pmf) { }
163 template<
typename... _Args>
165 operator()(_Args&&... __args)
const 168 -> decltype(
std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
169 {
return std::__invoke(_M_pmf, std::forward<_Args>(__args)...); }
173 template<
typename _MemObjPtr>
174 class _Mem_fn_base<_MemObjPtr, false>
176 using _Arity = integral_constant<size_t, 0>;
179 template<
typename _Func,
typename... _BoundArgs>
180 friend struct _Bind_check_arity;
186 _Mem_fn_base(_MemObjPtr __pm) noexcept : _M_pm(__pm) { }
188 template<
typename _Tp>
190 operator()(_Tp&& __obj)
const 191 noexcept(noexcept(
std::__invoke(_M_pm, std::forward<_Tp>(__obj))))
196 template<
typename _MemberPo
inter>
199 template<
typename _Res,
typename _Class>
200 struct _Mem_fn<_Res _Class::*>
201 : _Mem_fn_base<_Res _Class::*>
203 using _Mem_fn_base<_Res _Class::*>::_Mem_fn_base;
213 template<
typename _Tp,
typename _Class>
214 inline _Mem_fn<_Tp _Class::*>
217 return _Mem_fn<_Tp _Class::*>(__pm);
228 template<
typename _Tp>
239 template<
typename _Tp>
244 #if __cplusplus > 201402L 245 template <
typename _Tp> constexpr
bool is_bind_expression_v
247 template <
typename _Tp> constexpr
int is_placeholder_v
256 _GLIBCXX_END_NAMESPACE_VERSION
262 namespace placeholders
264 _GLIBCXX_BEGIN_NAMESPACE_VERSION
298 _GLIBCXX_END_NAMESPACE_VERSION
301 _GLIBCXX_BEGIN_NAMESPACE_VERSION
320 template<std::
size_t __i,
typename _Tuple>
321 using _Safe_tuple_element_t
322 =
typename enable_if<(__i < tuple_size<_Tuple>::value),
336 template<
typename _Arg,
346 template<
typename _Tp>
354 template<
typename _CVRef,
typename _Tuple>
356 operator()(_CVRef& __arg, _Tuple&)
const volatile 357 {
return __arg.get(); }
366 template<
typename _Arg>
367 class _Mu<_Arg, true, false>
370 template<
typename _CVArg,
typename... _Args>
372 operator()(_CVArg& __arg,
374 -> decltype(__arg(declval<_Args>()...))
377 typedef typename _Build_index_tuple<
sizeof...(_Args)>::__type
379 return this->__call(__arg, __tuple, _Indexes());
385 template<
typename _CVArg,
typename... _Args, std::size_t... _Indexes>
388 const _Index_tuple<_Indexes...>&)
const volatile 389 -> decltype(__arg(declval<_Args>()...))
391 return __arg(std::get<_Indexes>(std::move(__tuple))...);
400 template<
typename _Arg>
401 class _Mu<_Arg, false, true>
404 template<
typename _Tuple>
405 _Safe_tuple_element_t<(is_placeholder<_Arg>::value - 1), _Tuple>&&
406 operator()(
const volatile _Arg&, _Tuple& __tuple)
const volatile 409 ::std::get<(is_placeholder<_Arg>::value - 1)>(std::move(__tuple));
418 template<
typename _Arg>
419 class _Mu<_Arg, false, false>
422 template<
typename _CVArg,
typename _Tuple>
424 operator()(_CVArg&& __arg, _Tuple&)
const volatile 425 {
return std::forward<_CVArg>(__arg); }
429 template<std::size_t _Ind,
typename... _Tp>
432 -> __tuple_element_t<_Ind,
tuple<_Tp...>>
volatile&
433 {
return std::get<_Ind>(
const_cast<tuple<_Tp...
>&>(__tuple)); }
436 template<std::size_t _Ind,
typename... _Tp>
439 -> __tuple_element_t<_Ind,
tuple<_Tp...>>
const volatile&
440 {
return std::get<_Ind>(
const_cast<const tuple<_Tp...
>&>(__tuple)); }
443 template<
typename _Signature>
446 template<
typename _Functor,
typename... _Bound_args>
447 class _Bind<_Functor(_Bound_args...)>
450 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
454 tuple<_Bound_args...> _M_bound_args;
457 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
467 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
477 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
480 _Index_tuple<_Indexes...>)
volatile 488 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
491 _Index_tuple<_Indexes...>)
const volatile 498 template<
typename _BoundArg,
typename _CallArgs>
499 using _Mu_type = decltype(
500 _Mu<
typename remove_cv<_BoundArg>::type>()(
501 std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );
503 template<
typename _Fn,
typename _CallArgs,
typename... _BArgs>
505 =
typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>...) >::type;
507 template<
typename _CallArgs>
508 using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
510 template<
typename _CallArgs>
511 using __dependent =
typename 512 enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
514 template<
typename _CallArgs,
template<
class>
class __cv_quals>
515 using _Res_type_cv = _Res_type_impl<
516 typename __cv_quals<__dependent<_CallArgs>>::type,
518 typename __cv_quals<_Bound_args>::type...>;
521 template<
typename... _Args>
522 explicit _Bind(
const _Functor& __f, _Args&&... __args)
523 : _M_f(__f), _M_bound_args(
std::
forward<_Args>(__args)...)
526 template<
typename... _Args>
527 explicit _Bind(_Functor&& __f, _Args&&... __args)
528 : _M_f(
std::move(__f)), _M_bound_args(
std::
forward<_Args>(__args)...)
534 : _M_f(
std::move(__b._M_f)), _M_bound_args(
std::move(__b._M_bound_args))
538 template<
typename... _Args,
539 typename _Result = _Res_type<
tuple<_Args...>>>
541 operator()(_Args&&... __args)
543 return this->__call<_Result>(
544 std::forward_as_tuple(std::forward<_Args>(__args)...),
549 template<
typename... _Args,
550 typename _Result = _Res_type_cv<
tuple<_Args...>, add_const>>
552 operator()(_Args&&... __args)
const 554 return this->__call_c<_Result>(
555 std::forward_as_tuple(std::forward<_Args>(__args)...),
559 #if __cplusplus > 201402L 560 # define _GLIBCXX_DEPR_BIND \ 561 [[deprecated("std::bind does not support volatile in C++17")]] 563 # define _GLIBCXX_DEPR_BIND 566 template<
typename... _Args,
567 typename _Result = _Res_type_cv<
tuple<_Args...>, add_volatile>>
570 operator()(_Args&&... __args)
volatile 572 return this->__call_v<_Result>(
573 std::forward_as_tuple(std::forward<_Args>(__args)...),
578 template<
typename... _Args,
579 typename _Result = _Res_type_cv<
tuple<_Args...>, add_cv>>
582 operator()(_Args&&... __args)
const volatile 584 return this->__call_c_v<_Result>(
585 std::forward_as_tuple(std::forward<_Args>(__args)...),
591 template<
typename _Result,
typename _Signature>
594 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
597 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
601 tuple<_Bound_args...> _M_bound_args;
604 template<
typename _Res>
605 using __enable_if_void
606 =
typename enable_if<is_void<_Res>{}>::type;
608 template<
typename _Res>
609 using __disable_if_void
610 =
typename enable_if<!is_void<_Res>{}, _Result>::type;
613 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
614 __disable_if_void<_Res>
618 (std::get<_Indexes>(_M_bound_args), __args)...);
622 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
623 __enable_if_void<_Res>
627 (std::get<_Indexes>(_M_bound_args), __args)...);
631 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
632 __disable_if_void<_Res>
636 (std::get<_Indexes>(_M_bound_args), __args)...);
640 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
641 __enable_if_void<_Res>
645 (std::get<_Indexes>(_M_bound_args), __args)...);
649 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
650 __disable_if_void<_Res>
654 (__volget<_Indexes>(_M_bound_args), __args)...);
658 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
659 __enable_if_void<_Res>
663 (__volget<_Indexes>(_M_bound_args), __args)...);
667 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
668 __disable_if_void<_Res>
670 _Index_tuple<_Indexes...>)
const volatile 673 (__volget<_Indexes>(_M_bound_args), __args)...);
677 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
678 __enable_if_void<_Res>
680 _Index_tuple<_Indexes...>)
const volatile 683 (__volget<_Indexes>(_M_bound_args), __args)...);
687 typedef _Result result_type;
689 template<
typename... _Args>
690 explicit _Bind_result(
const _Functor& __f, _Args&&... __args)
691 : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
694 template<
typename... _Args>
695 explicit _Bind_result(_Functor&& __f, _Args&&... __args)
696 : _M_f(std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
699 _Bind_result(
const _Bind_result&) =
default;
701 _Bind_result(_Bind_result&& __b)
702 : _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args))
706 template<
typename... _Args>
708 operator()(_Args&&... __args)
710 return this->__call<_Result>(
711 std::forward_as_tuple(std::forward<_Args>(__args)...),
716 template<
typename... _Args>
718 operator()(_Args&&... __args)
const 720 return this->__call<_Result>(
721 std::forward_as_tuple(std::forward<_Args>(__args)...),
726 template<
typename... _Args>
729 operator()(_Args&&... __args)
volatile 731 return this->__call<_Result>(
732 std::forward_as_tuple(std::forward<_Args>(__args)...),
737 template<
typename... _Args>
740 operator()(_Args&&... __args)
const volatile 742 return this->__call<_Result>(
743 std::forward_as_tuple(std::forward<_Args>(__args)...),
747 #undef _GLIBCXX_DEPR_BIND 753 template<
typename _Signature>
761 template<
typename _Signature>
769 template<
typename _Signature>
777 template<
typename _Signature>
785 template<
typename _Result,
typename _Signature>
793 template<
typename _Result,
typename _Signature>
801 template<
typename _Result,
typename _Signature>
809 template<
typename _Result,
typename _Signature>
813 template<
typename _Func,
typename... _BoundArgs>
814 struct _Bind_check_arity { };
816 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
817 struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
819 static_assert(
sizeof...(_BoundArgs) ==
sizeof...(_Args),
820 "Wrong number of arguments for function");
823 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
824 struct _Bind_check_arity<_Ret (*)(_Args......), _BoundArgs...>
826 static_assert(
sizeof...(_BoundArgs) >=
sizeof...(_Args),
827 "Wrong number of arguments for function");
830 template<
typename _Tp,
typename _Class,
typename... _BoundArgs>
831 struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
833 using _Arity =
typename _Mem_fn<_Tp _Class::*>::_Arity;
834 using _Varargs =
typename _Mem_fn<_Tp _Class::*>::_Varargs;
835 static_assert(_Varargs::value
836 ?
sizeof...(_BoundArgs) >= _Arity::value + 1
837 :
sizeof...(_BoundArgs) == _Arity::value + 1,
838 "Wrong number of arguments for pointer-to-member");
844 template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
845 using __is_socketlike = __or_<is_integral<_Tp2>,
is_enum<_Tp2>>;
847 template<
bool _SocketLike,
typename _Func,
typename... _BoundArgs>
849 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
851 typedef typename decay<_Func>::type __func_type;
858 template<
typename _Func,
typename... _BoundArgs>
859 struct _Bind_helper<true, _Func, _BoundArgs...>
866 template<
typename _Func,
typename... _BoundArgs>
868 _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
869 bind(_Func&& __f, _BoundArgs&&... __args)
871 typedef _Bind_helper<
false, _Func, _BoundArgs...> __helper_type;
872 return typename __helper_type::type(std::forward<_Func>(__f),
873 std::forward<_BoundArgs>(__args)...);
876 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
877 struct _Bindres_helper
878 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
880 typedef typename decay<_Func>::type __functor_type;
882 __functor_type(
typename decay<_BoundArgs>::type...)>
890 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
892 typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
893 bind(_Func&& __f, _BoundArgs&&... __args)
895 typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
896 return typename __helper_type::type(std::forward<_Func>(__f),
897 std::forward<_BoundArgs>(__args)...);
900 #if __cplusplus >= 201402L 902 template<
typename _Fn>
905 template<
typename _Tp>
909 template<
typename _Fn2,
typename... _Args>
910 using __noexcept_cond = __and_<
911 __is_nothrow_callable<_Fn2(_Args&&...)>,
916 template<
typename _Fn2>
918 : _M_fn(std::forward<_Fn2>(__fn)) { }
924 template<
typename... _Args>
926 operator()(_Args&&... __args) &
927 noexcept(__noexcept_cond<_Fn&, _Args&&...>::value)
928 -> decltype(!std::declval<result_of_t<_Fn&(_Args&&...)>>())
929 {
return !
std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
931 template<
typename... _Args>
933 operator()(_Args&&... __args)
const &
934 noexcept(__noexcept_cond<const _Fn&, _Args&&...>::value)
935 -> decltype(!std::declval<result_of_t<
const _Fn&(_Args&&...)>>())
936 {
return !
std::__invoke(_M_fn, std::forward<_Args>(__args)...); }
938 template<
typename... _Args>
940 operator()(_Args&&... __args) &&
941 noexcept(__noexcept_cond<_Fn&&, _Args&&...>::value)
942 -> decltype(!std::declval<result_of_t<_Fn&&(_Args&&...)>>())
945 std::forward<_Args>(__args)...);
948 template<
typename... _Args>
950 operator()(_Args&&... __args)
const &&
951 noexcept(__noexcept_cond<const _Fn&&, _Args&&...>::value)
952 -> decltype(!std::declval<result_of_t<
const _Fn&&(_Args&&...)>>())
955 std::forward<_Args>(__args)...);
962 #if __cplusplus > 201402L 963 #define __cpp_lib_not_fn 201603 965 template<
typename _Fn>
968 noexcept(std::is_nothrow_constructible<std::decay_t<_Fn>, _Fn&&>::value)
974 #define __cpp_lib_boyer_moore_searcher 201603 976 template<
typename _ForwardIterator1,
typename _BinaryPredicate = equal_to<>>
977 class default_searcher
980 default_searcher(_ForwardIterator1 __pat_first,
981 _ForwardIterator1 __pat_last,
982 _BinaryPredicate __pred = _BinaryPredicate())
983 : _M_m(__pat_first, __pat_last, std::move(__pred))
986 template<
typename _ForwardIterator2>
988 operator()(_ForwardIterator2 __first, _ForwardIterator2 __last)
const 990 _ForwardIterator2 __first_ret =
992 std::get<0>(_M_m), std::get<1>(_M_m),
994 _ForwardIterator2 __second_ret = __first_ret == __last ?
995 __last : std::next(__first_ret,
std::distance(std::get<0>(_M_m),
1004 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred>
1005 struct __boyer_moore_map_base
1007 template<
typename _RAIter>
1008 __boyer_moore_map_base(_RAIter __pat,
size_t __patlen,
1009 _Hash&& __hf, _Pred&& __pred)
1010 : _M_bad_char{ __patlen, std::move(__hf), std::move(__pred) }
1013 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1014 _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
1017 using __diff_type = _Tp;
1020 _M_lookup(_Key __key, __diff_type __not_found)
const 1022 auto __iter = _M_bad_char.find(__key);
1023 if (__iter == _M_bad_char.end())
1025 return __iter->second;
1029 _M_pred()
const {
return _M_bad_char.key_eq(); }
1031 _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
1034 template<
typename _Tp,
size_t _Len,
typename _Pred>
1035 struct __boyer_moore_array_base
1037 template<
typename _RAIter,
typename _Unused>
1038 __boyer_moore_array_base(_RAIter __pat,
size_t __patlen,
1039 _Unused&&, _Pred&& __pred)
1040 : _M_bad_char{ _GLIBCXX_STD_C::array<_Tp, _Len>{}, std::move(__pred) }
1042 std::get<0>(_M_bad_char).fill(__patlen);
1044 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1046 auto __ch = __pat[__i];
1047 using _UCh = std::make_unsigned_t<decltype(__ch)>;
1048 auto __uch =
static_cast<_UCh
>(__ch);
1049 std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
1053 using __diff_type = _Tp;
1055 template<
typename _Key>
1057 _M_lookup(_Key __key, __diff_type __not_found)
const 1059 auto __ukey =
static_cast<std::make_unsigned_t<_Key>
>(__key);
1062 return std::get<0>(_M_bad_char)[__ukey];
1066 _M_pred()
const {
return std::get<1>(_M_bad_char); }
1071 template<
typename _Pred>
1079 template<
typename _RAIter,
typename _Hash,
typename _Pred,
1080 typename _Val =
typename iterator_traits<_RAIter>::value_type,
1081 typename _Diff =
typename iterator_traits<_RAIter>::difference_type>
1082 using __boyer_moore_base_t
1083 = std::conditional_t<sizeof(_Val) == 1 && is_integral<_Val>::value
1084 && __is_std_equal_to<_Pred>::value,
1085 __boyer_moore_array_base<_Diff, 256, _Pred>,
1086 __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
1088 template<
typename _RAIter,
typename _Hash
1091 class boyer_moore_searcher
1092 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1094 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1095 using typename _Base::__diff_type;
1098 boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1099 _Hash __hf = _Hash(),
1100 _BinaryPredicate __pred = _BinaryPredicate());
1102 template<
typename _RandomAccessIterator2>
1104 operator()(_RandomAccessIterator2 __first,
1105 _RandomAccessIterator2 __last)
const;
1109 _M_is_prefix(_RAIter __word, __diff_type __len,
1112 const auto& __pred = this->_M_pred();
1113 __diff_type __suffixlen = __len - __pos;
1114 for (__diff_type __i = 0; __i < __suffixlen; ++__i)
1115 if (!__pred(__word[__i], __word[__pos + __i]))
1121 _M_suffix_length(_RAIter __word, __diff_type __len,
1124 const auto& __pred = this->_M_pred();
1125 __diff_type __i = 0;
1126 while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
1134 template<
typename _Tp>
1136 _M_bad_char_shift(_Tp __c)
const 1137 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1141 _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
1144 template<
typename _RAIter,
typename _Hash
1147 class boyer_moore_horspool_searcher
1148 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1150 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1151 using typename _Base::__diff_type;
1154 boyer_moore_horspool_searcher(_RAIter __pat,
1156 _Hash __hf = _Hash(),
1157 _BinaryPredicate __pred
1158 = _BinaryPredicate())
1159 : _Base(__pat, __pat_end - __pat, std::move(__hf), std::move(__pred)),
1160 _M_pat(__pat), _M_pat_end(__pat_end)
1163 template<
typename _RandomAccessIterator2>
1165 operator()(_RandomAccessIterator2 __first,
1166 _RandomAccessIterator2 __last)
const 1168 const auto& __pred = this->_M_pred();
1169 auto __patlen = _M_pat_end - _M_pat;
1172 auto __len = __last - __first;
1173 while (__len >= __patlen)
1175 for (
auto __scan = __patlen - 1;
1176 __pred(__first[__scan], _M_pat[__scan]); --__scan)
1179 std::next(__first, __patlen));
1180 auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
1188 template<
typename _Tp>
1190 _M_bad_char_shift(_Tp __c)
const 1191 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1198 template<
typename _ForwardIterator,
1200 inline default_searcher<_ForwardIterator, _BinaryPredicate>
1201 make_default_searcher(_ForwardIterator __pat_first,
1202 _ForwardIterator __pat_last,
1203 _BinaryPredicate __pred = _BinaryPredicate())
1204 {
return { __pat_first, __pat_last, __pred }; }
1207 template<
typename _RAIter,
typename _Hash
1210 inline boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>
1211 make_boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1212 _Hash __hf = _Hash(),
1213 _BinaryPredicate __pred = _BinaryPredicate())
1214 {
return { __pat_first, __pat_last, std::move(__hf), std::move(__pred) }; }
1217 template<
typename _RAIter,
typename _Hash
1220 inline boyer_moore_horspool_searcher<_RAIter, _Hash, _BinaryPredicate>
1221 make_boyer_moore_horspool_searcher(_RAIter __pat_first, _RAIter __pat_last,
1222 _Hash __hf = _Hash(),
1223 _BinaryPredicate __pred
1224 = _BinaryPredicate())
1225 {
return { __pat_first, __pat_last, std::move(__hf), std::move(__pred) }; }
1227 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1228 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1229 boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
1230 _Hash __hf, _BinaryPredicate __pred)
1231 : _Base(__pat, __pat_end - __pat, std::move(__hf), std::move(__pred)),
1232 _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
1234 auto __patlen = __pat_end - __pat;
1237 __diff_type __last_prefix = __patlen - 1;
1238 for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
1240 if (_M_is_prefix(__pat, __patlen, __p + 1))
1241 __last_prefix = __p + 1;
1242 _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
1244 for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
1246 auto __slen = _M_suffix_length(__pat, __patlen, __p);
1247 auto __pos = __patlen - 1 - __slen;
1248 if (!__pred(__pat[__p - __slen], __pat[__pos]))
1249 _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
1253 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1254 template<
typename _RandomAccessIterator2>
1256 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1257 operator()(_RandomAccessIterator2 __first,
1258 _RandomAccessIterator2 __last)
const 1260 auto __patlen = _M_pat_end - _M_pat;
1263 const auto& __pred = this->_M_pred();
1264 __diff_type __i = __patlen - 1;
1265 auto __stringlen = __last - __first;
1266 while (__i < __stringlen)
1268 __diff_type __j = __patlen - 1;
1269 while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
1277 __i +=
std::max(_M_bad_char_shift(__first[__i]),
1278 _M_good_suffix[__j]);
1286 _GLIBCXX_END_NAMESPACE_VERSION
1291 #endif // _GLIBCXX_FUNCTIONAL
The type of placeholder objects defined by libstdc++.
Primary class template, tuple.
_Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type bind(_Func &&__f, _BoundArgs &&... __args)
Function template for std::bind.
Struct holding two objects of arbitrary type.
Primary class template hash.
Determines if the given type _Tp is a placeholder in a bind() expression and, if so, which placeholder it is.
Type of the function object returned from bind<R>().
ISO C++ entities toplevel namespace is std.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
Primary class template for reference_wrapper.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
_Mem_fn< _Tp _Class::* > mem_fn(_Tp _Class::*__pm) noexcept
Returns a function object that forwards to the member pointer pm.
_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __predicate)
Search a sequence for a matching sub-sequence using a predicate.
One of the comparison functors.
Determines if the given type _Tp is a function object that should be treated as a subexpression when ...
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr result_of< _Callable &&(_Args &&...)>::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_callable< _Callable &&(_Args &&...)>::value)
Invoke a callable object.
Type of the function object returned from bind().