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 invoke_result_t<_Callable, _Args...>
77 invoke(_Callable&& __fn, _Args&&... __args)
78 noexcept(is_nothrow_invocable_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 #if __cplusplus > 201402L 144 #undef _GLIBCXX_MEM_FN_TRAITS 145 #undef _GLIBCXX_MEM_FN_TRAITS2 147 template<
typename _MemFunPtr,
148 bool __is_mem_fn = is_member_function_pointer<_MemFunPtr>::value>
150 :
public _Mem_fn_traits<_MemFunPtr>::__maybe_type
152 using _Traits = _Mem_fn_traits<_MemFunPtr>;
154 using _Arity =
typename _Traits::__arity;
155 using _Varargs =
typename _Traits::__vararg;
157 template<
typename _Func,
typename... _BoundArgs>
158 friend struct _Bind_check_arity;
164 using result_type =
typename _Traits::__result_type;
167 _Mem_fn_base(_MemFunPtr __pmf) noexcept : _M_pmf(__pmf) { }
169 template<
typename... _Args>
171 operator()(_Args&&... __args)
const 174 -> decltype(
std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
175 {
return std::__invoke(_M_pmf, std::forward<_Args>(__args)...); }
179 template<
typename _MemObjPtr>
180 class _Mem_fn_base<_MemObjPtr, false>
182 using _Arity = integral_constant<size_t, 0>;
185 template<
typename _Func,
typename... _BoundArgs>
186 friend struct _Bind_check_arity;
192 _Mem_fn_base(_MemObjPtr __pm) noexcept : _M_pm(__pm) { }
194 template<
typename _Tp>
196 operator()(_Tp&& __obj)
const 197 noexcept(noexcept(
std::__invoke(_M_pm, std::forward<_Tp>(__obj))))
202 template<
typename _MemberPo
inter>
205 template<
typename _Res,
typename _Class>
206 struct _Mem_fn<_Res _Class::*>
207 : _Mem_fn_base<_Res _Class::*>
209 using _Mem_fn_base<_Res _Class::*>::_Mem_fn_base;
219 template<
typename _Tp,
typename _Class>
220 inline _Mem_fn<_Tp _Class::*>
223 return _Mem_fn<_Tp _Class::*>(__pm);
234 template<
typename _Tp>
245 template<
typename _Tp>
250 #if __cplusplus > 201402L 251 template <
typename _Tp>
inline constexpr
bool is_bind_expression_v
253 template <
typename _Tp>
inline constexpr
int is_placeholder_v
262 _GLIBCXX_END_NAMESPACE_VERSION
268 namespace placeholders
270 _GLIBCXX_BEGIN_NAMESPACE_VERSION
304 _GLIBCXX_END_NAMESPACE_VERSION
307 _GLIBCXX_BEGIN_NAMESPACE_VERSION
326 template<std::
size_t __i,
typename _Tuple>
327 using _Safe_tuple_element_t
328 =
typename enable_if<(__i < tuple_size<_Tuple>::value),
342 template<
typename _Arg,
352 template<
typename _Tp>
360 template<
typename _CVRef,
typename _Tuple>
362 operator()(_CVRef& __arg, _Tuple&)
const volatile 363 {
return __arg.get(); }
372 template<
typename _Arg>
373 class _Mu<_Arg, true, false>
376 template<
typename _CVArg,
typename... _Args>
378 operator()(_CVArg& __arg,
380 -> decltype(__arg(declval<_Args>()...))
383 typedef typename _Build_index_tuple<
sizeof...(_Args)>::__type
385 return this->__call(__arg, __tuple, _Indexes());
391 template<
typename _CVArg,
typename... _Args, std::size_t... _Indexes>
394 const _Index_tuple<_Indexes...>&)
const volatile 395 -> decltype(__arg(declval<_Args>()...))
397 return __arg(std::get<_Indexes>(std::move(__tuple))...);
406 template<
typename _Arg>
407 class _Mu<_Arg, false, true>
410 template<
typename _Tuple>
411 _Safe_tuple_element_t<(is_placeholder<_Arg>::value - 1), _Tuple>&&
412 operator()(
const volatile _Arg&, _Tuple& __tuple)
const volatile 415 ::std::get<(is_placeholder<_Arg>::value - 1)>(std::move(__tuple));
424 template<
typename _Arg>
425 class _Mu<_Arg, false, false>
428 template<
typename _CVArg,
typename _Tuple>
430 operator()(_CVArg&& __arg, _Tuple&)
const volatile 431 {
return std::forward<_CVArg>(__arg); }
435 template<std::size_t _Ind,
typename... _Tp>
438 -> __tuple_element_t<_Ind,
tuple<_Tp...>>
volatile&
439 {
return std::get<_Ind>(
const_cast<tuple<_Tp...
>&>(__tuple)); }
442 template<std::size_t _Ind,
typename... _Tp>
445 -> __tuple_element_t<_Ind,
tuple<_Tp...>>
const volatile&
446 {
return std::get<_Ind>(
const_cast<const tuple<_Tp...
>&>(__tuple)); }
449 template<
typename _Signature>
452 template<
typename _Functor,
typename... _Bound_args>
453 class _Bind<_Functor(_Bound_args...)>
456 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
460 tuple<_Bound_args...> _M_bound_args;
463 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
473 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
483 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
486 _Index_tuple<_Indexes...>)
volatile 494 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
497 _Index_tuple<_Indexes...>)
const volatile 504 template<
typename _BoundArg,
typename _CallArgs>
505 using _Mu_type = decltype(
506 _Mu<
typename remove_cv<_BoundArg>::type>()(
507 std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );
509 template<
typename _Fn,
typename _CallArgs,
typename... _BArgs>
511 =
typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
513 template<
typename _CallArgs>
514 using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
516 template<
typename _CallArgs>
517 using __dependent =
typename 518 enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
520 template<
typename _CallArgs,
template<
class>
class __cv_quals>
521 using _Res_type_cv = _Res_type_impl<
522 typename __cv_quals<__dependent<_CallArgs>>::type,
524 typename __cv_quals<_Bound_args>::type...>;
527 template<
typename... _Args>
528 explicit _Bind(
const _Functor& __f, _Args&&... __args)
529 : _M_f(__f), _M_bound_args(
std::
forward<_Args>(__args)...)
532 template<
typename... _Args>
533 explicit _Bind(_Functor&& __f, _Args&&... __args)
534 : _M_f(
std::move(__f)), _M_bound_args(
std::
forward<_Args>(__args)...)
540 : _M_f(
std::move(__b._M_f)), _M_bound_args(
std::move(__b._M_bound_args))
544 template<
typename... _Args,
545 typename _Result = _Res_type<
tuple<_Args...>>>
547 operator()(_Args&&... __args)
549 return this->__call<_Result>(
550 std::forward_as_tuple(std::forward<_Args>(__args)...),
555 template<
typename... _Args,
556 typename _Result = _Res_type_cv<
tuple<_Args...>, add_const>>
558 operator()(_Args&&... __args)
const 560 return this->__call_c<_Result>(
561 std::forward_as_tuple(std::forward<_Args>(__args)...),
565 #if __cplusplus > 201402L 566 # define _GLIBCXX_DEPR_BIND \ 567 [[deprecated("std::bind does not support volatile in C++17")]] 569 # define _GLIBCXX_DEPR_BIND 572 template<
typename... _Args,
573 typename _Result = _Res_type_cv<
tuple<_Args...>, add_volatile>>
576 operator()(_Args&&... __args)
volatile 578 return this->__call_v<_Result>(
579 std::forward_as_tuple(std::forward<_Args>(__args)...),
584 template<
typename... _Args,
585 typename _Result = _Res_type_cv<
tuple<_Args...>, add_cv>>
588 operator()(_Args&&... __args)
const volatile 590 return this->__call_c_v<_Result>(
591 std::forward_as_tuple(std::forward<_Args>(__args)...),
597 template<
typename _Result,
typename _Signature>
600 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
603 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
607 tuple<_Bound_args...> _M_bound_args;
610 template<
typename _Res>
611 using __enable_if_void
612 =
typename enable_if<is_void<_Res>{}>::type;
614 template<
typename _Res>
615 using __disable_if_void
616 =
typename enable_if<!is_void<_Res>{}, _Result>::type;
619 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
620 __disable_if_void<_Res>
624 (std::get<_Indexes>(_M_bound_args), __args)...);
628 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
629 __enable_if_void<_Res>
633 (std::get<_Indexes>(_M_bound_args), __args)...);
637 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
638 __disable_if_void<_Res>
642 (std::get<_Indexes>(_M_bound_args), __args)...);
646 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
647 __enable_if_void<_Res>
651 (std::get<_Indexes>(_M_bound_args), __args)...);
655 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
656 __disable_if_void<_Res>
660 (__volget<_Indexes>(_M_bound_args), __args)...);
664 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
665 __enable_if_void<_Res>
669 (__volget<_Indexes>(_M_bound_args), __args)...);
673 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
674 __disable_if_void<_Res>
676 _Index_tuple<_Indexes...>)
const volatile 679 (__volget<_Indexes>(_M_bound_args), __args)...);
683 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
684 __enable_if_void<_Res>
686 _Index_tuple<_Indexes...>)
const volatile 689 (__volget<_Indexes>(_M_bound_args), __args)...);
693 typedef _Result result_type;
695 template<
typename... _Args>
696 explicit _Bind_result(
const _Functor& __f, _Args&&... __args)
697 : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
700 template<
typename... _Args>
701 explicit _Bind_result(_Functor&& __f, _Args&&... __args)
702 : _M_f(std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
705 _Bind_result(
const _Bind_result&) =
default;
707 _Bind_result(_Bind_result&& __b)
708 : _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args))
712 template<
typename... _Args>
714 operator()(_Args&&... __args)
716 return this->__call<_Result>(
717 std::forward_as_tuple(std::forward<_Args>(__args)...),
722 template<
typename... _Args>
724 operator()(_Args&&... __args)
const 726 return this->__call<_Result>(
727 std::forward_as_tuple(std::forward<_Args>(__args)...),
732 template<
typename... _Args>
735 operator()(_Args&&... __args)
volatile 737 return this->__call<_Result>(
738 std::forward_as_tuple(std::forward<_Args>(__args)...),
743 template<
typename... _Args>
746 operator()(_Args&&... __args)
const volatile 748 return this->__call<_Result>(
749 std::forward_as_tuple(std::forward<_Args>(__args)...),
753 #undef _GLIBCXX_DEPR_BIND 759 template<
typename _Signature>
767 template<
typename _Signature>
775 template<
typename _Signature>
783 template<
typename _Signature>
791 template<
typename _Result,
typename _Signature>
799 template<
typename _Result,
typename _Signature>
807 template<
typename _Result,
typename _Signature>
815 template<
typename _Result,
typename _Signature>
819 template<
typename _Func,
typename... _BoundArgs>
820 struct _Bind_check_arity { };
822 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
823 struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
825 static_assert(
sizeof...(_BoundArgs) ==
sizeof...(_Args),
826 "Wrong number of arguments for function");
829 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
830 struct _Bind_check_arity<_Ret (*)(_Args......), _BoundArgs...>
832 static_assert(
sizeof...(_BoundArgs) >=
sizeof...(_Args),
833 "Wrong number of arguments for function");
836 template<
typename _Tp,
typename _Class,
typename... _BoundArgs>
837 struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
839 using _Arity =
typename _Mem_fn<_Tp _Class::*>::_Arity;
840 using _Varargs =
typename _Mem_fn<_Tp _Class::*>::_Varargs;
841 static_assert(_Varargs::value
842 ?
sizeof...(_BoundArgs) >= _Arity::value + 1
843 :
sizeof...(_BoundArgs) == _Arity::value + 1,
844 "Wrong number of arguments for pointer-to-member");
850 template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
851 using __is_socketlike = __or_<is_integral<_Tp2>,
is_enum<_Tp2>>;
853 template<
bool _SocketLike,
typename _Func,
typename... _BoundArgs>
855 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
857 typedef typename decay<_Func>::type __func_type;
864 template<
typename _Func,
typename... _BoundArgs>
865 struct _Bind_helper<true, _Func, _BoundArgs...>
872 template<
typename _Func,
typename... _BoundArgs>
874 _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
875 bind(_Func&& __f, _BoundArgs&&... __args)
877 typedef _Bind_helper<
false, _Func, _BoundArgs...> __helper_type;
878 return typename __helper_type::type(std::forward<_Func>(__f),
879 std::forward<_BoundArgs>(__args)...);
882 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
883 struct _Bindres_helper
884 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
886 typedef typename decay<_Func>::type __functor_type;
888 __functor_type(
typename decay<_BoundArgs>::type...)>
896 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
898 typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
899 bind(_Func&& __f, _BoundArgs&&... __args)
901 typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
902 return typename __helper_type::type(std::forward<_Func>(__f),
903 std::forward<_BoundArgs>(__args)...);
906 #if __cplusplus >= 201402L 908 template<
typename _Fn>
911 template<
typename _Fn2,
typename... _Args>
912 using __inv_res_t =
typename __invoke_result<_Fn2, _Args...>::type;
914 template<
typename _Tp>
915 static decltype(!std::declval<_Tp>())
916 _S_not() noexcept(noexcept(!std::declval<_Tp>()));
919 template<
typename _Fn2>
921 : _M_fn(std::forward<_Fn2>(__fn)) { }
930 #define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \ 931 template<typename... _Args> \ 932 decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \ 933 operator()(_Args&&... __args) _QUALS \ 934 noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \ 935 && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \ 937 return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \ 938 std::forward<_Args>(__args)...); \ 940 _GLIBCXX_NOT_FN_CALL_OP( & )
941 _GLIBCXX_NOT_FN_CALL_OP(
const & )
942 _GLIBCXX_NOT_FN_CALL_OP( && )
943 _GLIBCXX_NOT_FN_CALL_OP(
const && )
944 #undef _GLIBCXX_NOT_FN_CALL 950 #if __cplusplus > 201402L 951 #define __cpp_lib_not_fn 201603 953 template<
typename _Fn>
956 noexcept(std::is_nothrow_constructible<std::decay_t<_Fn>, _Fn&&>::value)
962 #define __cpp_lib_boyer_moore_searcher 201603 964 template<
typename _ForwardIterator1,
typename _BinaryPredicate = equal_to<>>
965 class default_searcher
968 default_searcher(_ForwardIterator1 __pat_first,
969 _ForwardIterator1 __pat_last,
970 _BinaryPredicate __pred = _BinaryPredicate())
971 : _M_m(__pat_first, __pat_last, std::move(__pred))
974 template<
typename _ForwardIterator2>
976 operator()(_ForwardIterator2 __first, _ForwardIterator2 __last)
const 978 _ForwardIterator2 __first_ret =
979 std::search(__first, __last, std::get<0>(_M_m), std::get<1>(_M_m),
982 if (__ret.first != __last)
992 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred>
993 struct __boyer_moore_map_base
995 template<
typename _RAIter>
996 __boyer_moore_map_base(_RAIter __pat,
size_t __patlen,
997 _Hash&& __hf, _Pred&& __pred)
998 : _M_bad_char{ __patlen, std::move(__hf), std::move(__pred) }
1001 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1002 _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
1005 using __diff_type = _Tp;
1008 _M_lookup(_Key __key, __diff_type __not_found)
const 1010 auto __iter = _M_bad_char.find(__key);
1011 if (__iter == _M_bad_char.end())
1013 return __iter->second;
1017 _M_pred()
const {
return _M_bad_char.key_eq(); }
1019 _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
1022 template<
typename _Tp,
size_t _Len,
typename _Pred>
1023 struct __boyer_moore_array_base
1025 template<
typename _RAIter,
typename _Unused>
1026 __boyer_moore_array_base(_RAIter __pat,
size_t __patlen,
1027 _Unused&&, _Pred&& __pred)
1028 : _M_bad_char{ _GLIBCXX_STD_C::array<_Tp, _Len>{}, std::move(__pred) }
1030 std::get<0>(_M_bad_char).fill(__patlen);
1032 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1034 auto __ch = __pat[__i];
1035 using _UCh = make_unsigned_t<decltype(__ch)>;
1036 auto __uch =
static_cast<_UCh
>(__ch);
1037 std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
1041 using __diff_type = _Tp;
1043 template<
typename _Key>
1045 _M_lookup(_Key __key, __diff_type __not_found)
const 1047 auto __ukey =
static_cast<make_unsigned_t<_Key>
>(__key);
1050 return std::get<0>(_M_bad_char)[__ukey];
1054 _M_pred()
const {
return std::get<1>(_M_bad_char); }
1059 template<
typename _Pred>
1063 struct __is_std_equal_to<equal_to<void>> :
true_type { };
1067 template<
typename _RAIter,
typename _Hash,
typename _Pred,
1068 typename _Val =
typename iterator_traits<_RAIter>::value_type,
1069 typename _Diff =
typename iterator_traits<_RAIter>::difference_type>
1070 using __boyer_moore_base_t
1071 = conditional_t<sizeof(_Val) == 1 && is_integral<_Val>::value
1072 && __is_std_equal_to<_Pred>::value,
1073 __boyer_moore_array_base<_Diff, 256, _Pred>,
1074 __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
1076 template<
typename _RAIter,
typename _Hash
1079 class boyer_moore_searcher
1080 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1082 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1083 using typename _Base::__diff_type;
1086 boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1087 _Hash __hf = _Hash(),
1088 _BinaryPredicate __pred = _BinaryPredicate());
1090 template<
typename _RandomAccessIterator2>
1092 operator()(_RandomAccessIterator2 __first,
1093 _RandomAccessIterator2 __last)
const;
1097 _M_is_prefix(_RAIter __word, __diff_type __len,
1100 const auto& __pred = this->_M_pred();
1101 __diff_type __suffixlen = __len - __pos;
1102 for (__diff_type __i = 0; __i < __suffixlen; ++__i)
1103 if (!__pred(__word[__i], __word[__pos + __i]))
1109 _M_suffix_length(_RAIter __word, __diff_type __len,
1112 const auto& __pred = this->_M_pred();
1113 __diff_type __i = 0;
1114 while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
1122 template<
typename _Tp>
1124 _M_bad_char_shift(_Tp __c)
const 1125 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1129 _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
1132 template<
typename _RAIter,
typename _Hash
1135 class boyer_moore_horspool_searcher
1136 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1138 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1139 using typename _Base::__diff_type;
1142 boyer_moore_horspool_searcher(_RAIter __pat,
1144 _Hash __hf = _Hash(),
1145 _BinaryPredicate __pred
1146 = _BinaryPredicate())
1147 : _Base(__pat, __pat_end - __pat, std::move(__hf), std::move(__pred)),
1148 _M_pat(__pat), _M_pat_end(__pat_end)
1151 template<
typename _RandomAccessIterator2>
1153 operator()(_RandomAccessIterator2 __first,
1154 _RandomAccessIterator2 __last)
const 1156 const auto& __pred = this->_M_pred();
1157 auto __patlen = _M_pat_end - _M_pat;
1160 auto __len = __last - __first;
1161 while (__len >= __patlen)
1163 for (
auto __scan = __patlen - 1;
1164 __pred(__first[__scan], _M_pat[__scan]); --__scan)
1167 auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
1175 template<
typename _Tp>
1177 _M_bad_char_shift(_Tp __c)
const 1178 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1184 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1185 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1186 boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
1187 _Hash __hf, _BinaryPredicate __pred)
1188 : _Base(__pat, __pat_end - __pat, std::move(__hf), std::move(__pred)),
1189 _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
1191 auto __patlen = __pat_end - __pat;
1194 __diff_type __last_prefix = __patlen - 1;
1195 for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
1197 if (_M_is_prefix(__pat, __patlen, __p + 1))
1198 __last_prefix = __p + 1;
1199 _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
1201 for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
1203 auto __slen = _M_suffix_length(__pat, __patlen, __p);
1204 auto __pos = __patlen - 1 - __slen;
1205 if (!__pred(__pat[__p - __slen], __pat[__pos]))
1206 _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
1210 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1211 template<
typename _RandomAccessIterator2>
1213 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1214 operator()(_RandomAccessIterator2 __first,
1215 _RandomAccessIterator2 __last)
const 1217 auto __patlen = _M_pat_end - _M_pat;
1220 const auto& __pred = this->_M_pred();
1221 __diff_type __i = __patlen - 1;
1222 auto __stringlen = __last - __first;
1223 while (__i < __stringlen)
1225 __diff_type __j = __patlen - 1;
1226 while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
1233 const auto __match = __first + __i + 1;
1236 __i +=
std::max(_M_bad_char_shift(__first[__i]),
1237 _M_good_suffix[__j]);
1245 _GLIBCXX_END_NAMESPACE_VERSION
1250 #endif // _GLIBCXX_FUNCTIONAL
The type of placeholder objects defined by libstdc++.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
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.
Struct holding two objects of arbitrary type.
Type of the function object returned from bind<R>().
One of the comparison functors.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Determines if the given type _Tp is a placeholder in a bind() expression and, if so, which placeholder it is.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
ISO C++ entities toplevel namespace is std.
Primary class template for reference_wrapper.
_GLIBCXX17_CONSTEXPR iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
Primary class template, tuple.
Determines if the given type _Tp is a function object that should be treated as a subexpression when ...
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
Primary class template hash.
Type of the function object returned from bind().
_GLIBCXX17_CONSTEXPR void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
_Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type bind(_Func &&__f, _BoundArgs &&... __args)
Function template for std::bind.
_ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __predicate)
Search a sequence for a matching sub-sequence using a predicate.
_GLIBCXX14_CONSTEXPR const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
_Mem_fn< _Tp _Class::* > mem_fn(_Tp _Class::*__pm) noexcept
Returns a function object that forwards to the member pointer pm.