43 #ifndef _GLIBCXX_FUNCTIONAL 44 #define _GLIBCXX_FUNCTIONAL 1 46 #pragma GCC system_header 51 #if __cplusplus >= 201103L 60 #if __cplusplus > 201402L 67 #if __cplusplus > 201703L 74 namespace std _GLIBCXX_VISIBILITY(default)
76 _GLIBCXX_BEGIN_NAMESPACE_VERSION
83 #if __cplusplus >= 201103L 85 #if __cplusplus >= 201703L 86 # define __cpp_lib_invoke 201411L 87 # if __cplusplus > 201703L 88 # define __cpp_lib_constexpr_functional 201907L 92 template<
typename _Callable,
typename... _Args>
94 invoke(_Callable&& __fn, _Args&&... __args)
95 noexcept(is_nothrow_invocable_v<_Callable, _Args...>)
98 std::forward<_Args>(__args)...);
102 template<
typename _MemFunPtr,
103 bool __is_mem_fn = is_member_function_pointer<_MemFunPtr>::value>
105 :
public _Mem_fn_traits<_MemFunPtr>::__maybe_type
107 using _Traits = _Mem_fn_traits<_MemFunPtr>;
109 using _Arity =
typename _Traits::__arity;
110 using _Varargs =
typename _Traits::__vararg;
112 template<
typename _Func,
typename... _BoundArgs>
113 friend struct _Bind_check_arity;
119 using result_type =
typename _Traits::__result_type;
122 _Mem_fn_base(_MemFunPtr __pmf) noexcept : _M_pmf(__pmf) { }
124 template<
typename... _Args>
127 operator()(_Args&&... __args)
const 130 -> decltype(
std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
131 {
return std::__invoke(_M_pmf, std::forward<_Args>(__args)...); }
135 template<
typename _MemObjPtr>
136 class _Mem_fn_base<_MemObjPtr, false>
138 using _Arity = integral_constant<size_t, 0>;
141 template<
typename _Func,
typename... _BoundArgs>
142 friend struct _Bind_check_arity;
148 _Mem_fn_base(_MemObjPtr __pm) noexcept : _M_pm(__pm) { }
150 template<
typename _Tp>
153 operator()(_Tp&& __obj)
const 154 noexcept(noexcept(
std::__invoke(_M_pm, std::forward<_Tp>(__obj))))
159 template<
typename _MemberPo
inter>
162 template<
typename _Res,
typename _Class>
163 struct _Mem_fn<_Res _Class::*>
164 : _Mem_fn_base<_Res _Class::*>
166 using _Mem_fn_base<_Res _Class::*>::_Mem_fn_base;
176 template<
typename _Tp,
typename _Class>
178 inline _Mem_fn<_Tp _Class::*>
181 return _Mem_fn<_Tp _Class::*>(__pm);
192 template<
typename _Tp>
203 template<
typename _Tp>
208 #if __cplusplus > 201402L 209 template <
typename _Tp>
inline constexpr
bool is_bind_expression_v
211 template <
typename _Tp>
inline constexpr
int is_placeholder_v
219 namespace placeholders
273 template<std::
size_t __i,
typename _Tuple>
274 using _Safe_tuple_element_t
275 =
typename enable_if<(__i < tuple_size<_Tuple>::value),
276 tuple_element<__i, _Tuple>>::type::type;
289 template<
typename _Arg,
290 bool _IsBindExp = is_bind_expression<_Arg>::value,
291 bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
299 template<
typename _Tp>
307 template<
typename _CVRef,
typename _Tuple>
310 operator()(_CVRef& __arg, _Tuple&)
const volatile 311 {
return __arg.get(); }
320 template<
typename _Arg>
321 class _Mu<_Arg, true, false>
324 template<
typename _CVArg,
typename... _Args>
327 operator()(_CVArg& __arg,
329 -> decltype(__arg(declval<_Args>()...))
332 typedef typename _Build_index_tuple<
sizeof...(_Args)>::__type
334 return this->__call(__arg, __tuple, _Indexes());
340 template<
typename _CVArg,
typename... _Args, std::size_t... _Indexes>
344 const _Index_tuple<_Indexes...>&)
const volatile 345 -> decltype(__arg(declval<_Args>()...))
347 return __arg(std::get<_Indexes>(
std::move(__tuple))...);
356 template<
typename _Arg>
357 class _Mu<_Arg, false, true>
360 template<
typename _Tuple>
362 _Safe_tuple_element_t<(is_placeholder<_Arg>::value - 1), _Tuple>&&
363 operator()(
const volatile _Arg&, _Tuple& __tuple)
const volatile 366 ::std::get<(is_placeholder<_Arg>::value - 1)>(
std::move(__tuple));
375 template<
typename _Arg>
376 class _Mu<_Arg, false, false>
379 template<
typename _CVArg,
typename _Tuple>
382 operator()(_CVArg&& __arg, _Tuple&)
const volatile 383 {
return std::forward<_CVArg>(__arg); }
387 template<std::size_t _Ind,
typename... _Tp>
390 -> __tuple_element_t<_Ind,
tuple<_Tp...>>
volatile&
391 {
return std::get<_Ind>(
const_cast<tuple<_Tp...
>&>(__tuple)); }
394 template<std::size_t _Ind,
typename... _Tp>
396 __volget(
const volatile tuple<_Tp...>& __tuple)
397 -> __tuple_element_t<_Ind, tuple<_Tp...>>
const volatile&
398 {
return std::get<_Ind>(
const_cast<const tuple<_Tp...
>&>(__tuple)); }
401 template<
typename _Signature>
404 template<
typename _Functor,
typename... _Bound_args>
405 class _Bind<_Functor(_Bound_args...)>
406 :
public _Weak_result_type<_Functor>
408 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
412 tuple<_Bound_args...> _M_bound_args;
415 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
426 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
437 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
439 __call_v(tuple<_Args...>&& __args,
440 _Index_tuple<_Indexes...>)
volatile 443 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
448 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
450 __call_c_v(tuple<_Args...>&& __args,
451 _Index_tuple<_Indexes...>)
const volatile 454 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
458 template<
typename _BoundArg,
typename _CallArgs>
459 using _Mu_type = decltype(
460 _Mu<
typename remove_cv<_BoundArg>::type>()(
461 std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );
463 template<
typename _Fn,
typename _CallArgs,
typename... _BArgs>
465 =
typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
467 template<
typename _CallArgs>
468 using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
470 template<
typename _CallArgs>
471 using __dependent =
typename 472 enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
474 template<
typename _CallArgs,
template<
class>
class __cv_quals>
475 using _Res_type_cv = _Res_type_impl<
476 typename __cv_quals<__dependent<_CallArgs>>::type,
478 typename __cv_quals<_Bound_args>::type...>;
481 template<
typename... _Args>
482 explicit _GLIBCXX20_CONSTEXPR
483 _Bind(
const _Functor& __f, _Args&&... __args)
484 : _M_f(__f), _M_bound_args(
std::
forward<_Args>(__args)...)
487 template<
typename... _Args>
488 explicit _GLIBCXX20_CONSTEXPR
489 _Bind(_Functor&& __f, _Args&&... __args)
493 _Bind(
const _Bind&) =
default;
494 _Bind(_Bind&&) =
default;
497 template<
typename... _Args,
498 typename _Result = _Res_type<tuple<_Args...>>>
501 operator()(_Args&&... __args)
503 return this->__call<_Result>(
509 template<
typename... _Args,
510 typename _Result = _Res_type_cv<tuple<_Args...>, add_const>>
513 operator()(_Args&&... __args)
const 515 return this->__call_c<_Result>(
520 #if __cplusplus > 201402L 521 # define _GLIBCXX_DEPR_BIND \ 522 [[deprecated("std::bind does not support volatile in C++17")]] 524 # define _GLIBCXX_DEPR_BIND 527 template<
typename... _Args,
528 typename _Result = _Res_type_cv<tuple<_Args...>, add_volatile>>
531 operator()(_Args&&... __args)
volatile 533 return this->__call_v<_Result>(
539 template<
typename... _Args,
540 typename _Result = _Res_type_cv<tuple<_Args...>, add_cv>>
543 operator()(_Args&&... __args)
const volatile 545 return this->__call_c_v<_Result>(
552 template<
typename _Result,
typename _Signature>
555 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
558 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
562 tuple<_Bound_args...> _M_bound_args;
565 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
571 (std::get<_Indexes>(_M_bound_args), __args)...);
575 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
581 (std::get<_Indexes>(_M_bound_args), __args)...);
585 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
591 (__volget<_Indexes>(_M_bound_args), __args)...);
595 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
599 _Index_tuple<_Indexes...>)
const volatile 602 (__volget<_Indexes>(_M_bound_args), __args)...);
606 typedef _Result result_type;
608 template<
typename... _Args>
609 explicit _GLIBCXX20_CONSTEXPR
611 : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
614 template<
typename... _Args>
615 explicit _GLIBCXX20_CONSTEXPR
617 : _M_f(
std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
624 template<
typename... _Args>
627 operator()(_Args&&... __args)
629 return this->__call<_Result>(
635 template<
typename... _Args>
638 operator()(_Args&&... __args)
const 640 return this->__call<_Result>(
646 template<
typename... _Args>
649 operator()(_Args&&... __args)
volatile 651 return this->__call<_Result>(
657 template<
typename... _Args>
660 operator()(_Args&&... __args)
const volatile 662 return this->__call<_Result>(
667 #undef _GLIBCXX_DEPR_BIND 673 template<
typename _Signature>
681 template<
typename _Signature>
689 template<
typename _Signature>
697 template<
typename _Signature>
705 template<
typename _Result,
typename _Signature>
713 template<
typename _Result,
typename _Signature>
721 template<
typename _Result,
typename _Signature>
729 template<
typename _Result,
typename _Signature>
733 template<
typename _Func,
typename... _BoundArgs>
734 struct _Bind_check_arity { };
736 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
737 struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
739 static_assert(
sizeof...(_BoundArgs) ==
sizeof...(_Args),
740 "Wrong number of arguments for function");
743 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
744 struct _Bind_check_arity<_Ret (*)(_Args......), _BoundArgs...>
746 static_assert(
sizeof...(_BoundArgs) >=
sizeof...(_Args),
747 "Wrong number of arguments for function");
750 template<
typename _Tp,
typename _Class,
typename... _BoundArgs>
751 struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
753 using _Arity =
typename _Mem_fn<_Tp _Class::*>::_Arity;
754 using _Varargs =
typename _Mem_fn<_Tp _Class::*>::_Varargs;
755 static_assert(_Varargs::value
756 ?
sizeof...(_BoundArgs) >= _Arity::value + 1
757 :
sizeof...(_BoundArgs) == _Arity::value + 1,
758 "Wrong number of arguments for pointer-to-member");
764 template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
765 using __is_socketlike = __or_<is_integral<_Tp2>, is_enum<_Tp2>>;
767 template<
bool _SocketLike,
typename _Func,
typename... _BoundArgs>
769 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
771 typedef typename decay<_Func>::type __func_type;
772 typedef _Bind<__func_type(typename decay<_BoundArgs>::type...)> type;
778 template<
typename _Func,
typename... _BoundArgs>
779 struct _Bind_helper<true, _Func, _BoundArgs...>
786 template<
typename _Func,
typename... _BoundArgs>
787 inline _GLIBCXX20_CONSTEXPR
typename 788 _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
789 bind(_Func&& __f, _BoundArgs&&... __args)
791 typedef _Bind_helper<
false, _Func, _BoundArgs...> __helper_type;
792 return typename __helper_type::type(std::forward<_Func>(__f),
793 std::forward<_BoundArgs>(__args)...);
796 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
797 struct _Bindres_helper
798 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
800 typedef typename decay<_Func>::type __functor_type;
801 typedef _Bind_result<_Result,
802 __functor_type(
typename decay<_BoundArgs>::type...)>
810 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
811 inline _GLIBCXX20_CONSTEXPR
812 typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
813 bind(_Func&& __f, _BoundArgs&&... __args)
815 typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
816 return typename __helper_type::type(std::forward<_Func>(__f),
817 std::forward<_BoundArgs>(__args)...);
820 #if __cplusplus > 201703L 821 #define __cpp_lib_bind_front 201907L 823 template<
typename _Fd,
typename... _BoundArgs>
826 static_assert(is_move_constructible_v<_Fd>);
827 static_assert((is_move_constructible_v<_BoundArgs> && ...));
831 template<
typename _Fn,
typename... _Args>
833 _Bind_front(
int, _Fn&& __fn, _Args&&... __args)
834 noexcept(__and_<is_nothrow_constructible<_Fd, _Fn>,
835 is_nothrow_constructible<_BoundArgs, _Args>...>::value)
838 { static_assert(
sizeof...(_Args) ==
sizeof...(_BoundArgs)); }
840 _Bind_front(
const _Bind_front&) =
default;
841 _Bind_front(_Bind_front&&) =
default;
842 _Bind_front& operator=(
const _Bind_front&) =
default;
843 _Bind_front& operator=(_Bind_front&&) =
default;
844 ~_Bind_front() =
default;
846 template<
typename... _CallArgs>
849 operator()(_CallArgs&&... __call_args) &
850 noexcept(is_nothrow_invocable_v<_Fd&, _BoundArgs&..., _CallArgs...>)
852 return _S_call(*
this, _BoundIndices(),
853 std::forward<_CallArgs>(__call_args)...);
856 template<
typename... _CallArgs>
859 operator()(_CallArgs&&... __call_args)
const &
860 noexcept(is_nothrow_invocable_v<
const _Fd&,
const _BoundArgs&...,
863 return _S_call(*
this, _BoundIndices(),
864 std::forward<_CallArgs>(__call_args)...);
867 template<
typename... _CallArgs>
870 operator()(_CallArgs&&... __call_args) &&
871 noexcept(is_nothrow_invocable_v<_Fd, _BoundArgs..., _CallArgs...>)
873 return _S_call(
std::move(*
this), _BoundIndices(),
874 std::forward<_CallArgs>(__call_args)...);
877 template<
typename... _CallArgs>
880 operator()(_CallArgs&&... __call_args)
const &&
881 noexcept(is_nothrow_invocable_v<
const _Fd,
const _BoundArgs...,
884 return _S_call(
std::move(*
this), _BoundIndices(),
885 std::forward<_CallArgs>(__call_args)...);
891 template<
typename _Tp,
size_t... _Ind,
typename... _CallArgs>
894 _S_call(_Tp&& __g,
index_sequence<_Ind...>, _CallArgs&&... __call_args)
897 std::get<_Ind>(std::forward<_Tp>(__g)._M_bound_args)...,
898 std::forward<_CallArgs>(__call_args)...);
905 template<
typename _Fn,
typename... _Args>
907 = _Bind_front<decay_t<_Fn>, decay_t<_Args>...>;
909 template<
typename _Fn,
typename... _Args>
910 constexpr _Bind_front_t<_Fn, _Args...>
911 bind_front(_Fn&& __fn, _Args&&... __args)
912 noexcept(is_nothrow_constructible_v<_Bind_front_t<_Fn, _Args...>,
915 return _Bind_front_t<_Fn, _Args...>(0, std::forward<_Fn>(__fn),
916 std::forward<_Args>(__args)...);
920 #if __cplusplus >= 201402L 922 template<
typename _Fn>
925 template<
typename _Fn2,
typename... _Args>
926 using __inv_res_t =
typename __invoke_result<_Fn2, _Args...>::type;
928 template<
typename _Tp>
929 static decltype(!std::declval<_Tp>())
930 _S_not() noexcept(noexcept(!std::declval<_Tp>()));
933 template<
typename _Fn2>
936 : _M_fn(std::forward<_Fn2>(__fn)) { }
945 #define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \ 946 template<typename... _Args> \ 947 _GLIBCXX20_CONSTEXPR \ 948 decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \ 949 operator()(_Args&&... __args) _QUALS \ 950 noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \ 951 && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \ 953 return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \ 954 std::forward<_Args>(__args)...); \ 956 _GLIBCXX_NOT_FN_CALL_OP( & )
957 _GLIBCXX_NOT_FN_CALL_OP(
const & )
958 _GLIBCXX_NOT_FN_CALL_OP( && )
959 _GLIBCXX_NOT_FN_CALL_OP(
const && )
960 #undef _GLIBCXX_NOT_FN_CALL_OP 966 template<
typename _Tp,
typename _Pred>
969 template<
typename _Tp>
970 struct __is_byte_like<_Tp, equal_to<_Tp>>
971 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
973 template<
typename _Tp>
974 struct __is_byte_like<_Tp, equal_to<void>>
975 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
977 #if __cplusplus >= 201703L 979 enum class byte : unsigned char;
982 struct __is_byte_like<byte, equal_to<byte>>
986 struct __is_byte_like<
byte, equal_to<void>>
989 #define __cpp_lib_not_fn 201603 991 template<
typename _Fn>
1001 #define __cpp_lib_boyer_moore_searcher 201603 1003 template<
typename _ForwardIterator1,
typename _BinaryPredicate = equal_to<>>
1004 class default_searcher
1007 _GLIBCXX20_CONSTEXPR
1008 default_searcher(_ForwardIterator1 __pat_first,
1009 _ForwardIterator1 __pat_last,
1010 _BinaryPredicate __pred = _BinaryPredicate())
1011 : _M_m(__pat_first, __pat_last,
std::
move(__pred))
1014 template<
typename _ForwardIterator2>
1015 _GLIBCXX20_CONSTEXPR
1016 pair<_ForwardIterator2, _ForwardIterator2>
1017 operator()(_ForwardIterator2 __first, _ForwardIterator2 __last)
const 1019 _ForwardIterator2 __first_ret =
1020 std::search(__first, __last, std::get<0>(_M_m), std::get<1>(_M_m),
1022 auto __ret = std::make_pair(__first_ret, __first_ret);
1023 if (__ret.first != __last)
1025 std::get<1>(_M_m)));
1030 tuple<_ForwardIterator1, _ForwardIterator1, _BinaryPredicate> _M_m;
1033 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred>
1034 struct __boyer_moore_map_base
1036 template<
typename _RAIter>
1037 __boyer_moore_map_base(_RAIter __pat,
size_t __patlen,
1038 _Hash&& __hf, _Pred&& __pred)
1042 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1043 _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
1046 using __diff_type = _Tp;
1049 _M_lookup(_Key __key, __diff_type __not_found)
const 1051 auto __iter = _M_bad_char.find(__key);
1052 if (__iter == _M_bad_char.end())
1054 return __iter->second;
1058 _M_pred()
const {
return _M_bad_char.key_eq(); }
1060 _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
1063 template<
typename _Tp,
size_t _Len,
typename _Pred>
1064 struct __boyer_moore_array_base
1066 template<
typename _RAIter,
typename _Unused>
1067 __boyer_moore_array_base(_RAIter __pat,
size_t __patlen,
1068 _Unused&&, _Pred&& __pred)
1069 : _M_bad_char{ array<_Tp, _Len>{},
std::move(__pred) }
1071 std::get<0>(_M_bad_char).fill(__patlen);
1073 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1075 auto __ch = __pat[__i];
1076 using _UCh = make_unsigned_t<decltype(__ch)>;
1077 auto __uch =
static_cast<_UCh
>(__ch);
1078 std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
1082 using __diff_type = _Tp;
1084 template<
typename _Key>
1086 _M_lookup(_Key __key, __diff_type __not_found)
const 1088 auto __ukey =
static_cast<make_unsigned_t<_Key>
>(__key);
1091 return std::get<0>(_M_bad_char)[__ukey];
1095 _M_pred()
const {
return std::get<1>(_M_bad_char); }
1097 tuple<array<_Tp, _Len>, _Pred> _M_bad_char;
1102 template<
typename _RAIter,
typename _Hash,
typename _Pred,
1103 typename _Val =
typename iterator_traits<_RAIter>::value_type,
1104 typename _Diff =
typename iterator_traits<_RAIter>::difference_type>
1105 using __boyer_moore_base_t
1106 = conditional_t<__is_byte_like<_Val, _Pred>::value,
1107 __boyer_moore_array_base<_Diff, 256, _Pred>,
1108 __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
1110 template<
typename _RAIter,
typename _Hash
1111 = hash<typename iterator_traits<_RAIter>::value_type>,
1112 typename _BinaryPredicate = equal_to<>>
1113 class boyer_moore_searcher
1114 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1116 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1117 using typename _Base::__diff_type;
1120 boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1121 _Hash __hf = _Hash(),
1122 _BinaryPredicate __pred = _BinaryPredicate());
1124 template<
typename _RandomAccessIterator2>
1125 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1126 operator()(_RandomAccessIterator2 __first,
1127 _RandomAccessIterator2 __last)
const;
1131 _M_is_prefix(_RAIter __word, __diff_type __len,
1134 const auto& __pred = this->_M_pred();
1135 __diff_type __suffixlen = __len - __pos;
1136 for (__diff_type __i = 0; __i < __suffixlen; ++__i)
1137 if (!__pred(__word[__i], __word[__pos + __i]))
1143 _M_suffix_length(_RAIter __word, __diff_type __len,
1146 const auto& __pred = this->_M_pred();
1147 __diff_type __i = 0;
1148 while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
1156 template<
typename _Tp>
1158 _M_bad_char_shift(_Tp __c)
const 1159 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1163 _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
1166 template<
typename _RAIter,
typename _Hash
1167 = hash<typename iterator_traits<_RAIter>::value_type>,
1168 typename _BinaryPredicate = equal_to<>>
1169 class boyer_moore_horspool_searcher
1170 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1172 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1173 using typename _Base::__diff_type;
1176 boyer_moore_horspool_searcher(_RAIter __pat,
1178 _Hash __hf = _Hash(),
1179 _BinaryPredicate __pred
1180 = _BinaryPredicate())
1181 : _Base(__pat, __pat_end - __pat,
std::
move(__hf),
std::
move(__pred)),
1182 _M_pat(__pat), _M_pat_end(__pat_end)
1185 template<
typename _RandomAccessIterator2>
1186 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1187 operator()(_RandomAccessIterator2 __first,
1188 _RandomAccessIterator2 __last)
const 1190 const auto& __pred = this->_M_pred();
1191 auto __patlen = _M_pat_end - _M_pat;
1193 return std::make_pair(__first, __first);
1194 auto __len = __last - __first;
1195 while (__len >= __patlen)
1197 for (
auto __scan = __patlen - 1;
1198 __pred(__first[__scan], _M_pat[__scan]); --__scan)
1200 return std::make_pair(__first, __first + __patlen);
1201 auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
1205 return std::make_pair(__last, __last);
1209 template<
typename _Tp>
1211 _M_bad_char_shift(_Tp __c)
const 1212 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1218 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1219 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1220 boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
1221 _Hash __hf, _BinaryPredicate __pred)
1222 : _Base(__pat, __pat_end - __pat,
std::
move(__hf),
std::
move(__pred)),
1223 _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
1225 auto __patlen = __pat_end - __pat;
1228 __diff_type __last_prefix = __patlen - 1;
1229 for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
1231 if (_M_is_prefix(__pat, __patlen, __p + 1))
1232 __last_prefix = __p + 1;
1233 _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
1235 for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
1237 auto __slen = _M_suffix_length(__pat, __patlen, __p);
1238 auto __pos = __patlen - 1 - __slen;
1239 if (!__pred(__pat[__p - __slen], __pat[__pos]))
1240 _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
1244 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1245 template<
typename _RandomAccessIterator2>
1246 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1247 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1248 operator()(_RandomAccessIterator2 __first,
1249 _RandomAccessIterator2 __last)
const 1251 auto __patlen = _M_pat_end - _M_pat;
1253 return std::make_pair(__first, __first);
1254 const auto& __pred = this->_M_pred();
1255 __diff_type __i = __patlen - 1;
1256 auto __stringlen = __last - __first;
1257 while (__i < __stringlen)
1259 __diff_type __j = __patlen - 1;
1260 while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
1267 const auto __match = __first + __i + 1;
1268 return std::make_pair(__match, __match + __patlen);
1270 __i +=
std::max(_M_bad_char_shift(__first[__i]),
1271 _M_good_suffix[__j]);
1273 return std::make_pair(__last, __last);
1280 _GLIBCXX_END_NAMESPACE_VERSION
1283 #endif // _GLIBCXX_FUNCTIONAL
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Determines if the given type _Tp is a function object that should be treated as a subexpression when ...
integer_sequence< size_t, _Idx... > index_sequence
Alias template index_sequence.
Primary class template, tuple.
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
std::forward_as_tuple
constexpr _ForwardIterator search(_ForwardIterator __first, _ForwardIterator __last, const _Searcher &__searcher)
Search a sequence using a Searcher object.
typename decay< _Tp >::type decay_t
Alias template for decay.
Primary class template for reference_wrapper.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
constexpr _Mem_fn< _Tp _Class::* > mem_fn(_Tp _Class::*__pm) noexcept
Returns a function object that forwards to the member pointer pm.
The type of placeholder objects defined by libstdc++.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
make_index_sequence< sizeof...(_Types)> index_sequence_for
Alias template index_sequence_for.
Determines if the given type _Tp is a placeholder in a bind() expression and, if so, which placeholder it is.
constexpr _Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type bind(_Func &&__f, _BoundArgs &&... __args)
Function template for std::bind.
Type of the function object returned from bind().
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr invoke_result_t< _Callable, _Args... > invoke(_Callable &&__fn, _Args &&... __args) noexcept(is_nothrow_invocable_v< _Callable, _Args... >)
Invoke a callable object.
constexpr auto not_fn(_Fn &&__fn) noexcept(std::is_nothrow_constructible< std::decay_t< _Fn >, _Fn &&>::value)
[func.not_fn] Function template not_fn
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
Type of the function object returned from bind<R>().
typename invoke_result< _Fn, _Args... >::type invoke_result_t
std::invoke_result_t
ISO C++ entities toplevel namespace is std.