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
76namespace 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...>)
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
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))))
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)); }
464#if __cplusplus == 201703L && _GLIBCXX_USE_DEPRECATED
465# define _GLIBCXX_VOLATILE_BIND
468# define _GLIBCXX_DEPR_BIND \
469 [[deprecated("std::bind does not support volatile in C++17")]]
470#elif __cplusplus < 201703L
471# define _GLIBCXX_VOLATILE_BIND
472# define _GLIBCXX_DEPR_BIND
476 template<
typename _Signature>
479 template<
typename _Functor,
typename... _Bound_args>
480 class _Bind<_Functor(_Bound_args...)>
481 :
public _Weak_result_type<_Functor>
483 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
487 tuple<_Bound_args...> _M_bound_args;
490 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
496 _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
501 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
507 _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
511#ifdef _GLIBCXX_VOLATILE_BIND
513 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
515 __call_v(tuple<_Args...>&& __args,
516 _Index_tuple<_Indexes...>)
volatile
519 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
524 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
526 __call_c_v(tuple<_Args...>&& __args,
527 _Index_tuple<_Indexes...>)
const volatile
530 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
535 template<
typename _BoundArg,
typename _CallArgs>
536 using _Mu_type =
decltype(
537 _Mu<typename remove_cv<_BoundArg>::type>()(
538 std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );
540 template<
typename _Fn,
typename _CallArgs,
typename... _BArgs>
542 =
typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
544 template<
typename _CallArgs>
545 using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
547 template<
typename _CallArgs>
548 using __dependent =
typename
549 enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
551 template<
typename _CallArgs,
template<
class>
class __cv_quals>
552 using _Res_type_cv = _Res_type_impl<
553 typename __cv_quals<__dependent<_CallArgs>>::type,
555 typename __cv_quals<_Bound_args>::type...>;
558 template<
typename... _Args>
559 explicit _GLIBCXX20_CONSTEXPR
560 _Bind(
const _Functor& __f, _Args&&... __args)
561 : _M_f(__f), _M_bound_args(
std::
forward<_Args>(__args)...)
564 template<
typename... _Args>
565 explicit _GLIBCXX20_CONSTEXPR
566 _Bind(_Functor&& __f, _Args&&... __args)
570 _Bind(
const _Bind&) =
default;
571 _Bind(_Bind&&) =
default;
574 template<
typename... _Args,
575 typename _Result = _Res_type<tuple<_Args...>>>
578 operator()(_Args&&... __args)
580 return this->__call<_Result>(
586 template<
typename... _Args,
587 typename _Result = _Res_type_cv<tuple<_Args...>, add_const>>
590 operator()(_Args&&... __args)
const
592 return this->__call_c<_Result>(
597#ifdef _GLIBCXX_VOLATILE_BIND
599 template<
typename... _Args,
600 typename _Result = _Res_type_cv<tuple<_Args...>, add_volatile>>
603 operator()(_Args&&... __args)
volatile
605 return this->__call_v<_Result>(
611 template<
typename... _Args,
612 typename _Result = _Res_type_cv<tuple<_Args...>, add_cv>>
615 operator()(_Args&&... __args)
const volatile
617 return this->__call_c_v<_Result>(
625 template<
typename _Result,
typename _Signature>
628 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
631 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
635 tuple<_Bound_args...> _M_bound_args;
638 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
643 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
644 (std::get<_Indexes>(_M_bound_args), __args)...);
648 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
653 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
654 (std::get<_Indexes>(_M_bound_args), __args)...);
657#ifdef _GLIBCXX_VOLATILE_BIND
659 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
663 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
664 (__volget<_Indexes>(_M_bound_args), __args)...);
668 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
671 _Index_tuple<_Indexes...>)
const volatile
673 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
674 (__volget<_Indexes>(_M_bound_args), __args)...);
679 typedef _Result result_type;
681 template<
typename... _Args>
682 explicit _GLIBCXX20_CONSTEXPR
684 : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
687 template<
typename... _Args>
688 explicit _GLIBCXX20_CONSTEXPR
690 : _M_f(
std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
697 template<
typename... _Args>
700 operator()(_Args&&... __args)
702 return this->__call<_Result>(
708 template<
typename... _Args>
711 operator()(_Args&&... __args)
const
713 return this->__call<_Result>(
718#ifdef _GLIBCXX_VOLATILE_BIND
720 template<
typename... _Args>
723 operator()(_Args&&... __args)
volatile
725 return this->__call<_Result>(
731 template<
typename... _Args>
734 operator()(_Args&&... __args)
const volatile
736 return this->__call<_Result>(
741 template<
typename... _Args>
742 void operator()(_Args&&...)
const volatile =
delete;
746#undef _GLIBCXX_VOLATILE_BIND
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;
852 typedef _Bind<__func_type(
typename decay<_BoundArgs>::type...)> type;
858 template<
typename _Func,
typename... _BoundArgs>
859 struct _Bind_helper<true, _Func, _BoundArgs...>
867 template<
typename _Func,
typename... _BoundArgs>
868 inline _GLIBCXX20_CONSTEXPR
typename
869 _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
870 bind(_Func&& __f, _BoundArgs&&... __args)
872 typedef _Bind_helper<
false, _Func, _BoundArgs...> __helper_type;
873 return typename __helper_type::type(std::forward<_Func>(__f),
874 std::forward<_BoundArgs>(__args)...);
877 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
878 struct _Bindres_helper
879 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
881 typedef typename decay<_Func>::type __functor_type;
882 typedef _Bind_result<_Result,
883 __functor_type(
typename decay<_BoundArgs>::type...)>
892 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
893 inline _GLIBCXX20_CONSTEXPR
894 typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
895 bind(_Func&& __f, _BoundArgs&&... __args)
897 typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
898 return typename __helper_type::type(std::forward<_Func>(__f),
899 std::forward<_BoundArgs>(__args)...);
902#if __cplusplus > 201703L
903#define __cpp_lib_bind_front 201907L
905 template<
typename _Fd,
typename... _BoundArgs>
908 static_assert(is_move_constructible_v<_Fd>);
909 static_assert((is_move_constructible_v<_BoundArgs> && ...));
913 template<
typename _Fn,
typename... _Args>
915 _Bind_front(
int, _Fn&& __fn, _Args&&... __args)
916 noexcept(__and_<is_nothrow_constructible<_Fd, _Fn>,
917 is_nothrow_constructible<_BoundArgs, _Args>...>::value)
920 {
static_assert(
sizeof...(_Args) ==
sizeof...(_BoundArgs)); }
922 _Bind_front(
const _Bind_front&) =
default;
923 _Bind_front(_Bind_front&&) =
default;
924 _Bind_front& operator=(
const _Bind_front&) =
default;
925 _Bind_front& operator=(_Bind_front&&) =
default;
926 ~_Bind_front() =
default;
928 template<
typename... _CallArgs>
931 operator()(_CallArgs&&... __call_args) &
932 noexcept(is_nothrow_invocable_v<_Fd&, _BoundArgs&..., _CallArgs...>)
934 return _S_call(*
this, _BoundIndices(),
935 std::forward<_CallArgs>(__call_args)...);
938 template<
typename... _CallArgs>
941 operator()(_CallArgs&&... __call_args)
const &
942 noexcept(is_nothrow_invocable_v<
const _Fd&,
const _BoundArgs&...,
945 return _S_call(*
this, _BoundIndices(),
946 std::forward<_CallArgs>(__call_args)...);
949 template<
typename... _CallArgs>
952 operator()(_CallArgs&&... __call_args) &&
953 noexcept(is_nothrow_invocable_v<_Fd, _BoundArgs..., _CallArgs...>)
955 return _S_call(
std::move(*
this), _BoundIndices(),
956 std::forward<_CallArgs>(__call_args)...);
959 template<
typename... _CallArgs>
962 operator()(_CallArgs&&... __call_args)
const &&
963 noexcept(is_nothrow_invocable_v<
const _Fd,
const _BoundArgs...,
966 return _S_call(
std::move(*
this), _BoundIndices(),
967 std::forward<_CallArgs>(__call_args)...);
973 template<
typename _Tp,
size_t... _Ind,
typename... _CallArgs>
976 _S_call(_Tp&& __g, index_sequence<_Ind...>, _CallArgs&&... __call_args)
979 std::get<_Ind>(std::forward<_Tp>(__g)._M_bound_args)...,
980 std::forward<_CallArgs>(__call_args)...);
987 template<
typename _Fn,
typename... _Args>
989 = _Bind_front<decay_t<_Fn>, decay_t<_Args>...>;
1000 template<
typename _Fn,
typename... _Args>
1001 constexpr _Bind_front_t<_Fn, _Args...>
1003 noexcept(is_nothrow_constructible_v<_Bind_front_t<_Fn, _Args...>,
1004 int, _Fn, _Args...>)
1006 return _Bind_front_t<_Fn, _Args...>(0, std::forward<_Fn>(__fn),
1007 std::forward<_Args>(__args)...);
1011#if __cplusplus >= 201402L
1013 template<
typename _Fn>
1016 template<
typename _Fn2,
typename... _Args>
1017 using __inv_res_t =
typename __invoke_result<_Fn2, _Args...>::type;
1019 template<
typename _Tp>
1020 static decltype(!std::declval<_Tp>())
1021 _S_not()
noexcept(
noexcept(!std::declval<_Tp>()));
1024 template<
typename _Fn2>
1027 : _M_fn(std::forward<_Fn2>(__fn)) { }
1036#define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \
1037 template<typename... _Args> \
1038 _GLIBCXX20_CONSTEXPR \
1039 decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \
1040 operator()(_Args&&... __args) _QUALS \
1041 noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \
1042 && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \
1044 return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \
1045 std::forward<_Args>(__args)...); \
1047 _GLIBCXX_NOT_FN_CALL_OP( & )
1048 _GLIBCXX_NOT_FN_CALL_OP(
const & )
1049 _GLIBCXX_NOT_FN_CALL_OP( && )
1050 _GLIBCXX_NOT_FN_CALL_OP(
const && )
1051#undef _GLIBCXX_NOT_FN_CALL_OP
1057 template<
typename _Tp,
typename _Pred>
1060 template<
typename _Tp>
1061 struct __is_byte_like<_Tp, equal_to<_Tp>>
1062 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
1064 template<
typename _Tp>
1065 struct __is_byte_like<_Tp, equal_to<void>>
1066 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
1068#if __cplusplus >= 201703L
1070 enum class byte :
unsigned char;
1073 struct __is_byte_like<
byte, equal_to<
byte>>
1077 struct __is_byte_like<
byte, equal_to<void>>
1081#define __cpp_lib_not_fn 201603L
1094 template<
typename _Fn>
1095 _GLIBCXX20_CONSTEXPR
1104#define __cpp_lib_boyer_moore_searcher 201603L
1106 template<
typename _ForwardIterator1,
typename _BinaryPredicate = equal_to<>>
1107 class default_searcher
1110 _GLIBCXX20_CONSTEXPR
1111 default_searcher(_ForwardIterator1 __pat_first,
1112 _ForwardIterator1 __pat_last,
1113 _BinaryPredicate __pred = _BinaryPredicate())
1114 : _M_m(__pat_first, __pat_last,
std::
move(__pred))
1117 template<
typename _ForwardIterator2>
1118 _GLIBCXX20_CONSTEXPR
1119 pair<_ForwardIterator2, _ForwardIterator2>
1120 operator()(_ForwardIterator2 __first, _ForwardIterator2 __last)
const
1122 _ForwardIterator2 __first_ret =
1123 std::search(__first, __last, std::get<0>(_M_m), std::get<1>(_M_m),
1125 auto __ret = std::make_pair(__first_ret, __first_ret);
1126 if (__ret.first != __last)
1128 std::get<1>(_M_m)));
1133 tuple<_ForwardIterator1, _ForwardIterator1, _BinaryPredicate> _M_m;
1136 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred>
1137 struct __boyer_moore_map_base
1139 template<
typename _RAIter>
1140 __boyer_moore_map_base(_RAIter __pat,
size_t __patlen,
1141 _Hash&& __hf, _Pred&& __pred)
1145 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1146 _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
1149 using __diff_type = _Tp;
1152 _M_lookup(_Key __key, __diff_type __not_found)
const
1154 auto __iter = _M_bad_char.find(__key);
1155 if (__iter == _M_bad_char.end())
1157 return __iter->second;
1161 _M_pred()
const {
return _M_bad_char.key_eq(); }
1163 _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
1166 template<
typename _Tp,
size_t _Len,
typename _Pred>
1167 struct __boyer_moore_array_base
1169 template<
typename _RAIter,
typename _Unused>
1170 __boyer_moore_array_base(_RAIter __pat,
size_t __patlen,
1171 _Unused&&, _Pred&& __pred)
1172 : _M_bad_char{ array<_Tp, _Len>{},
std::move(__pred) }
1174 std::get<0>(_M_bad_char).fill(__patlen);
1176 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1178 auto __ch = __pat[__i];
1180 auto __uch =
static_cast<_UCh
>(__ch);
1181 std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
1185 using __diff_type = _Tp;
1187 template<
typename _Key>
1189 _M_lookup(_Key __key, __diff_type __not_found)
const
1191 auto __ukey =
static_cast<make_unsigned_t<_Key>
>(__key);
1194 return std::get<0>(_M_bad_char)[__ukey];
1198 _M_pred()
const {
return std::get<1>(_M_bad_char); }
1200 tuple<array<_Tp, _Len>, _Pred> _M_bad_char;
1205 template<
typename _RAIter,
typename _Hash,
typename _Pred,
1206 typename _Val =
typename iterator_traits<_RAIter>::value_type,
1207 typename _Diff =
typename iterator_traits<_RAIter>::difference_type>
1208 using __boyer_moore_base_t
1209 = __conditional_t<__is_byte_like<_Val, _Pred>::value,
1210 __boyer_moore_array_base<_Diff, 256, _Pred>,
1211 __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
1213 template<
typename _RAIter,
typename _Hash
1214 = hash<typename iterator_traits<_RAIter>::value_type>,
1215 typename _BinaryPredicate = equal_to<>>
1216 class boyer_moore_searcher
1217 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1219 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1220 using typename _Base::__diff_type;
1223 boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1224 _Hash __hf = _Hash(),
1225 _BinaryPredicate __pred = _BinaryPredicate());
1227 template<
typename _RandomAccessIterator2>
1228 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1229 operator()(_RandomAccessIterator2 __first,
1230 _RandomAccessIterator2 __last)
const;
1234 _M_is_prefix(_RAIter __word, __diff_type __len,
1237 const auto& __pred = this->_M_pred();
1238 __diff_type __suffixlen = __len - __pos;
1239 for (__diff_type __i = 0; __i < __suffixlen; ++__i)
1240 if (!__pred(__word[__i], __word[__pos + __i]))
1246 _M_suffix_length(_RAIter __word, __diff_type __len,
1249 const auto& __pred = this->_M_pred();
1250 __diff_type __i = 0;
1251 while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
1259 template<
typename _Tp>
1261 _M_bad_char_shift(_Tp __c)
const
1262 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1266 _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
1269 template<
typename _RAIter,
typename _Hash
1270 = hash<typename iterator_traits<_RAIter>::value_type>,
1271 typename _BinaryPredicate = equal_to<>>
1272 class boyer_moore_horspool_searcher
1273 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1275 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1276 using typename _Base::__diff_type;
1279 boyer_moore_horspool_searcher(_RAIter __pat,
1281 _Hash __hf = _Hash(),
1282 _BinaryPredicate __pred
1283 = _BinaryPredicate())
1284 : _Base(__pat, __pat_end - __pat,
std::move(__hf),
std::move(__pred)),
1285 _M_pat(__pat), _M_pat_end(__pat_end)
1288 template<
typename _RandomAccessIterator2>
1289 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1290 operator()(_RandomAccessIterator2 __first,
1291 _RandomAccessIterator2 __last)
const
1293 const auto& __pred = this->_M_pred();
1294 auto __patlen = _M_pat_end - _M_pat;
1296 return std::make_pair(__first, __first);
1297 auto __len = __last - __first;
1298 while (__len >= __patlen)
1300 for (
auto __scan = __patlen - 1;
1301 __pred(__first[__scan], _M_pat[__scan]); --__scan)
1303 return std::make_pair(__first, __first + __patlen);
1304 auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
1308 return std::make_pair(__last, __last);
1312 template<
typename _Tp>
1314 _M_bad_char_shift(_Tp __c)
const
1315 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1321 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1322 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1323 boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
1324 _Hash __hf, _BinaryPredicate __pred)
1325 : _Base(__pat, __pat_end - __pat,
std::move(__hf),
std::move(__pred)),
1326 _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
1328 auto __patlen = __pat_end - __pat;
1331 __diff_type __last_prefix = __patlen - 1;
1332 for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
1334 if (_M_is_prefix(__pat, __patlen, __p + 1))
1335 __last_prefix = __p + 1;
1336 _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
1338 for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
1340 auto __slen = _M_suffix_length(__pat, __patlen, __p);
1341 auto __pos = __patlen - 1 - __slen;
1342 if (!__pred(__pat[__p - __slen], __pat[__pos]))
1343 _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
1347 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1348 template<
typename _RandomAccessIterator2>
1349 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1350 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1351 operator()(_RandomAccessIterator2 __first,
1352 _RandomAccessIterator2 __last)
const
1354 auto __patlen = _M_pat_end - _M_pat;
1356 return std::make_pair(__first, __first);
1357 const auto& __pred = this->_M_pred();
1358 __diff_type __i = __patlen - 1;
1359 auto __stringlen = __last - __first;
1360 while (__i < __stringlen)
1362 __diff_type __j = __patlen - 1;
1363 while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
1370 const auto __match = __first + __i + 1;
1371 return std::make_pair(__match, __match + __patlen);
1373 __i +=
std::max(_M_bad_char_shift(__first[__i]),
1374 _M_good_suffix[__j]);
1376 return std::make_pair(__last, __last);
1383_GLIBCXX_END_NAMESPACE_VERSION
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
typename invoke_result< _Fn, _Args... >::type invoke_result_t
std::invoke_result_t
constexpr tuple< _Elements &&... > forward_as_tuple(_Elements &&... __args) noexcept
Create a tuple of lvalue or rvalue references to the arguments.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr auto not_fn(_Fn &&__fn) noexcept(std::is_nothrow_constructible< std::decay_t< _Fn >, _Fn && >::value)
constexpr _Mem_fn< _Tp _Class::* > mem_fn(_Tp _Class::*__pm) noexcept
Returns a function object that forwards to the member pointer pointer pm.
constexpr _Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs... >::type bind(_Func &&__f, _BoundArgs &&... __args)
Function template for std::bind.
ISO C++ entities toplevel namespace is std.
constexpr invoke_result_t< _Callable, _Args... > invoke(_Callable &&__fn, _Args &&... __args) noexcept(is_nothrow_invocable_v< _Callable, _Args... >)
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr _Bind_front_t< _Fn, _Args... > bind_front(_Fn &&__fn, _Args &&... __args) noexcept(is_nothrow_constructible_v< _Bind_front_t< _Fn, _Args... >, int, _Fn, _Args... >)
make_index_sequence< sizeof...(_Types)> index_sequence_for
Alias template index_sequence_for.
The type of placeholder objects defined by libstdc++.
Trait that identifies a bind expression.
Determines if the given type _Tp is a placeholder in a bind() expression and, if so,...
Type of the function object returned from bind().
Type of the function object returned from bind<R>().
Primary class template, tuple.