43 #ifndef _GLIBCXX_FUNCTIONAL
44 #define _GLIBCXX_FUNCTIONAL 1
46 #pragma GCC system_header
51 #if __cplusplus >= 201103L
60 #if __cplusplus > 201402L
61 # include <unordered_map>
67 #if __cplusplus > 201703L
72 namespace std _GLIBCXX_VISIBILITY(default)
74 _GLIBCXX_BEGIN_NAMESPACE_VERSION
76 #if __cplusplus >= 201703L
77 # define __cpp_lib_invoke 201411L
78 # if __cplusplus > 201703L
79 # define __cpp_lib_constexpr_functional 201907L
83 template<
typename _Callable,
typename... _Args>
84 inline _GLIBCXX20_CONSTEXPR invoke_result_t<_Callable, _Args...>
85 invoke(_Callable&& __fn, _Args&&... __args)
86 noexcept(is_nothrow_invocable_v<_Callable, _Args...>)
88 return std::__invoke(std::forward<_Callable>(__fn),
89 std::forward<_Args>(__args)...);
93 template<
typename _MemFunPtr,
94 bool __is_mem_fn = is_member_function_pointer<_MemFunPtr>::value>
96 :
public _Mem_fn_traits<_MemFunPtr>::__maybe_type
98 using _Traits = _Mem_fn_traits<_MemFunPtr>;
100 using _Arity =
typename _Traits::__arity;
101 using _Varargs =
typename _Traits::__vararg;
103 template<
typename _Func,
typename... _BoundArgs>
104 friend struct _Bind_check_arity;
110 using result_type =
typename _Traits::__result_type;
113 _Mem_fn_base(_MemFunPtr __pmf) noexcept : _M_pmf(__pmf) { }
115 template<
typename... _Args>
118 operator()(_Args&&... __args) const
120 std::__invoke(_M_pmf, std::
forward<_Args>(__args)...)))
121 -> decltype(std::__invoke(_M_pmf, std::
forward<_Args>(__args)...))
122 {
return std::__invoke(_M_pmf, std::forward<_Args>(__args)...); }
126 template<
typename _MemObjPtr>
127 class _Mem_fn_base<_MemObjPtr, false>
129 using _Arity = integral_constant<size_t, 0>;
132 template<
typename _Func,
typename... _BoundArgs>
133 friend struct _Bind_check_arity;
139 _Mem_fn_base(_MemObjPtr __pm) noexcept : _M_pm(__pm) { }
141 template<
typename _Tp>
144 operator()(_Tp&& __obj) const
145 noexcept(noexcept(std::__invoke(_M_pm, std::
forward<_Tp>(__obj))))
146 -> decltype(std::__invoke(_M_pm, std::
forward<_Tp>(__obj)))
147 {
return std::__invoke(_M_pm, std::forward<_Tp>(__obj)); }
150 template<
typename _MemberPo
inter>
153 template<
typename _Res,
typename _Class>
154 struct _Mem_fn<_Res _Class::*>
155 : _Mem_fn_base<_Res _Class::*>
157 using _Mem_fn_base<_Res _Class::*>::_Mem_fn_base;
167 template<
typename _Tp,
typename _Class>
169 inline _Mem_fn<_Tp _Class::*>
172 return _Mem_fn<_Tp _Class::*>(__pm);
183 template<
typename _Tp>
194 template<
typename _Tp>
199 #if __cplusplus > 201402L
200 template <
typename _Tp>
inline constexpr
bool is_bind_expression_v
202 template <
typename _Tp>
inline constexpr
int is_placeholder_v
215 namespace placeholders
269 template<std::
size_t __i,
typename _Tuple>
270 using _Safe_tuple_element_t
271 =
typename enable_if<(__i < tuple_size<_Tuple>::value),
272 tuple_element<__i, _Tuple>>::type::type;
285 template<
typename _Arg,
286 bool _IsBindExp = is_bind_expression<_Arg>::value,
287 bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
295 template<
typename _Tp>
303 template<
typename _CVRef,
typename _Tuple>
306 operator()(_CVRef& __arg, _Tuple&)
const volatile
307 {
return __arg.get(); }
316 template<
typename _Arg>
317 class _Mu<_Arg, true, false>
320 template<
typename _CVArg,
typename... _Args>
323 operator()(_CVArg& __arg,
325 -> decltype(__arg(declval<_Args>()...))
328 typedef typename _Build_index_tuple<
sizeof...(_Args)>::__type
330 return this->__call(__arg, __tuple, _Indexes());
336 template<
typename _CVArg,
typename... _Args, std::size_t... _Indexes>
340 const _Index_tuple<_Indexes...>&)
const volatile
341 -> decltype(__arg(declval<_Args>()...))
343 return __arg(std::get<_Indexes>(
std::move(__tuple))...);
352 template<
typename _Arg>
353 class _Mu<_Arg, false, true>
356 template<
typename _Tuple>
358 _Safe_tuple_element_t<(is_placeholder<_Arg>::value - 1), _Tuple>&&
359 operator()(
const volatile _Arg&, _Tuple& __tuple)
const volatile
362 ::std::get<(is_placeholder<_Arg>::value - 1)>(
std::move(__tuple));
371 template<
typename _Arg>
372 class _Mu<_Arg, false, false>
375 template<
typename _CVArg,
typename _Tuple>
378 operator()(_CVArg&& __arg, _Tuple&)
const volatile
379 {
return std::forward<_CVArg>(__arg); }
383 template<std::size_t _Ind,
typename... _Tp>
386 -> __tuple_element_t<_Ind,
tuple<_Tp...>>
volatile&
387 {
return std::get<_Ind>(
const_cast<tuple<_Tp...
>&>(__tuple)); }
390 template<std::size_t _Ind,
typename... _Tp>
392 __volget(
const volatile tuple<_Tp...>& __tuple)
393 -> __tuple_element_t<_Ind, tuple<_Tp...>>
const volatile&
394 {
return std::get<_Ind>(
const_cast<const tuple<_Tp...
>&>(__tuple)); }
397 template<
typename _Signature>
400 template<
typename _Functor,
typename... _Bound_args>
401 class _Bind<_Functor(_Bound_args...)>
402 :
public _Weak_result_type<_Functor>
404 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
408 tuple<_Bound_args...> _M_bound_args;
411 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
416 return std::__invoke(_M_f,
422 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
427 return std::__invoke(_M_f,
433 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
435 __call_v(tuple<_Args...>&& __args,
436 _Index_tuple<_Indexes...>)
volatile
438 return std::__invoke(_M_f,
439 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
444 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
446 __call_c_v(tuple<_Args...>&& __args,
447 _Index_tuple<_Indexes...>)
const volatile
449 return std::__invoke(_M_f,
450 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
454 template<
typename _BoundArg,
typename _CallArgs>
455 using _Mu_type = decltype(
456 _Mu<
typename remove_cv<_BoundArg>::type>()(
457 std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );
459 template<
typename _Fn,
typename _CallArgs,
typename... _BArgs>
461 =
typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
463 template<
typename _CallArgs>
464 using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
466 template<
typename _CallArgs>
467 using __dependent =
typename
468 enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
470 template<
typename _CallArgs,
template<
class>
class __cv_quals>
471 using _Res_type_cv = _Res_type_impl<
472 typename __cv_quals<__dependent<_CallArgs>>::type,
474 typename __cv_quals<_Bound_args>::type...>;
477 template<
typename... _Args>
478 explicit _GLIBCXX20_CONSTEXPR
479 _Bind(
const _Functor& __f, _Args&&... __args)
480 : _M_f(__f), _M_bound_args(std::
forward<_Args>(__args)...)
483 template<
typename... _Args>
484 explicit _GLIBCXX20_CONSTEXPR
485 _Bind(_Functor&& __f, _Args&&... __args)
486 : _M_f(std::
move(__f)), _M_bound_args(std::
forward<_Args>(__args)...)
489 _Bind(
const _Bind&) =
default;
490 _Bind(_Bind&&) =
default;
493 template<
typename... _Args,
494 typename _Result = _Res_type<tuple<_Args...>>>
497 operator()(_Args&&... __args)
499 return this->__call<_Result>(
505 template<
typename... _Args,
506 typename _Result = _Res_type_cv<tuple<_Args...>, add_const>>
509 operator()(_Args&&... __args)
const
511 return this->__call_c<_Result>(
516 #if __cplusplus > 201402L
517 # define _GLIBCXX_DEPR_BIND \
518 [[deprecated("std::bind does not support volatile in C++17")]]
520 # define _GLIBCXX_DEPR_BIND
523 template<
typename... _Args,
524 typename _Result = _Res_type_cv<tuple<_Args...>, add_volatile>>
527 operator()(_Args&&... __args)
volatile
529 return this->__call_v<_Result>(
535 template<
typename... _Args,
536 typename _Result = _Res_type_cv<tuple<_Args...>, add_cv>>
539 operator()(_Args&&... __args)
const volatile
541 return this->__call_c_v<_Result>(
548 template<
typename _Result,
typename _Signature>
551 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
554 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
558 tuple<_Bound_args...> _M_bound_args;
561 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
567 (std::get<_Indexes>(_M_bound_args), __args)...);
571 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
577 (std::get<_Indexes>(_M_bound_args), __args)...);
581 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
587 (__volget<_Indexes>(_M_bound_args), __args)...);
591 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
595 _Index_tuple<_Indexes...>)
const volatile
598 (__volget<_Indexes>(_M_bound_args), __args)...);
602 typedef _Result result_type;
604 template<
typename... _Args>
605 explicit _GLIBCXX20_CONSTEXPR
607 : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
610 template<
typename... _Args>
611 explicit _GLIBCXX20_CONSTEXPR
612 _Bind_result(_Functor&& __f, _Args&&... __args)
613 : _M_f(
std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
616 _Bind_result(
const _Bind_result&) =
default;
617 _Bind_result(_Bind_result&&) =
default;
620 template<
typename... _Args>
623 operator()(_Args&&... __args)
625 return this->__call<_Result>(
631 template<
typename... _Args>
634 operator()(_Args&&... __args)
const
636 return this->__call<_Result>(
642 template<
typename... _Args>
645 operator()(_Args&&... __args)
volatile
647 return this->__call<_Result>(
653 template<
typename... _Args>
656 operator()(_Args&&... __args)
const volatile
658 return this->__call<_Result>(
663 #undef _GLIBCXX_DEPR_BIND
669 template<
typename _Signature>
677 template<
typename _Signature>
685 template<
typename _Signature>
693 template<
typename _Signature>
701 template<
typename _Result,
typename _Signature>
709 template<
typename _Result,
typename _Signature>
717 template<
typename _Result,
typename _Signature>
725 template<
typename _Result,
typename _Signature>
729 template<
typename _Func,
typename... _BoundArgs>
730 struct _Bind_check_arity { };
732 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
733 struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
735 static_assert(
sizeof...(_BoundArgs) ==
sizeof...(_Args),
736 "Wrong number of arguments for function");
739 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
740 struct _Bind_check_arity<_Ret (*)(_Args......), _BoundArgs...>
742 static_assert(
sizeof...(_BoundArgs) >=
sizeof...(_Args),
743 "Wrong number of arguments for function");
746 template<
typename _Tp,
typename _Class,
typename... _BoundArgs>
747 struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
749 using _Arity =
typename _Mem_fn<_Tp _Class::*>::_Arity;
750 using _Varargs =
typename _Mem_fn<_Tp _Class::*>::_Varargs;
751 static_assert(_Varargs::value
752 ?
sizeof...(_BoundArgs) >= _Arity::value + 1
753 :
sizeof...(_BoundArgs) == _Arity::value + 1,
754 "Wrong number of arguments for pointer-to-member");
760 template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
761 using __is_socketlike = __or_<is_integral<_Tp2>, is_enum<_Tp2>>;
763 template<
bool _SocketLike,
typename _Func,
typename... _BoundArgs>
765 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
767 typedef typename decay<_Func>::type __func_type;
768 typedef _Bind<__func_type(typename decay<_BoundArgs>::type...)> type;
774 template<
typename _Func,
typename... _BoundArgs>
775 struct _Bind_helper<true, _Func, _BoundArgs...>
782 template<
typename _Func,
typename... _BoundArgs>
783 inline _GLIBCXX20_CONSTEXPR
typename
784 _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
785 bind(_Func&& __f, _BoundArgs&&... __args)
787 typedef _Bind_helper<
false, _Func, _BoundArgs...> __helper_type;
788 return typename __helper_type::type(std::forward<_Func>(__f),
789 std::forward<_BoundArgs>(__args)...);
792 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
793 struct _Bindres_helper
794 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
796 typedef typename decay<_Func>::type __functor_type;
797 typedef _Bind_result<_Result,
798 __functor_type(
typename decay<_BoundArgs>::type...)>
806 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
807 inline _GLIBCXX20_CONSTEXPR
808 typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
809 bind(_Func&& __f, _BoundArgs&&... __args)
811 typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
812 return typename __helper_type::type(std::forward<_Func>(__f),
813 std::forward<_BoundArgs>(__args)...);
816 #if __cplusplus > 201703L
817 #define __cpp_lib_bind_front 201907L
819 template<
typename _Fd,
typename... _BoundArgs>
822 static_assert(is_move_constructible_v<_Fd>);
823 static_assert((is_move_constructible_v<_BoundArgs> && ...));
827 template<
typename _Fn,
typename... _Args>
829 _Bind_front(
int, _Fn&& __fn, _Args&&... __args)
830 noexcept(__and_<is_nothrow_constructible<_Fd, _Fn>,
831 is_nothrow_constructible<_BoundArgs, _Args>...>::value)
832 : _M_fd(std::
forward<_Fn>(__fn)),
833 _M_bound_args(std::
forward<_Args>(__args)...)
834 { static_assert(
sizeof...(_Args) ==
sizeof...(_BoundArgs)); }
836 _Bind_front(
const _Bind_front&) =
default;
837 _Bind_front(_Bind_front&&) =
default;
838 _Bind_front& operator=(
const _Bind_front&) =
default;
839 _Bind_front& operator=(_Bind_front&&) =
default;
840 ~_Bind_front() =
default;
842 template<
typename... _CallArgs>
844 invoke_result_t<_Fd&, _BoundArgs&..., _CallArgs...>
845 operator()(_CallArgs&&... __call_args) &
846 noexcept(is_nothrow_invocable_v<_Fd&, _BoundArgs&..., _CallArgs...>)
848 return _S_call(*
this, _BoundIndices(),
849 std::forward<_CallArgs>(__call_args)...);
852 template<
typename... _CallArgs>
854 invoke_result_t<
const _Fd&,
const _BoundArgs&..., _CallArgs...>
855 operator()(_CallArgs&&... __call_args) const &
856 noexcept(is_nothrow_invocable_v<const _Fd&, const _BoundArgs&...,
859 return _S_call(*
this, _BoundIndices(),
860 std::forward<_CallArgs>(__call_args)...);
863 template<
typename... _CallArgs>
865 invoke_result_t<_Fd, _BoundArgs..., _CallArgs...>
866 operator()(_CallArgs&&... __call_args) &&
867 noexcept(is_nothrow_invocable_v<_Fd, _BoundArgs..., _CallArgs...>)
869 return _S_call(
std::move(*
this), _BoundIndices(),
870 std::forward<_CallArgs>(__call_args)...);
873 template<
typename... _CallArgs>
875 invoke_result_t<
const _Fd,
const _BoundArgs..., _CallArgs...>
876 operator()(_CallArgs&&... __call_args) const &&
877 noexcept(is_nothrow_invocable_v<const _Fd, const _BoundArgs...,
880 return _S_call(
std::move(*
this), _BoundIndices(),
881 std::forward<_CallArgs>(__call_args)...);
887 template<
typename _Tp,
size_t... _Ind,
typename... _CallArgs>
890 _S_call(_Tp&& __g,
index_sequence<_Ind...>, _CallArgs&&... __call_args)
892 return std::invoke(std::forward<_Tp>(__g)._M_fd,
893 std::get<_Ind>(std::forward<_Tp>(__g)._M_bound_args)...,
894 std::forward<_CallArgs>(__call_args)...);
901 template<
typename _Fn,
typename... _Args>
903 = _Bind_front<decay_t<_Fn>, decay_t<_Args>...>;
905 template<
typename _Fn,
typename... _Args>
906 constexpr _Bind_front_t<_Fn, _Args...>
907 bind_front(_Fn&& __fn, _Args&&... __args)
908 noexcept(is_nothrow_constructible_v<_Bind_front_t<_Fn, _Args...>,
911 return _Bind_front_t<_Fn, _Args...>(0, std::forward<_Fn>(__fn),
912 std::forward<_Args>(__args)...);
916 #if __cplusplus >= 201402L
918 template<
typename _Fn>
921 template<
typename _Fn2,
typename... _Args>
922 using __inv_res_t =
typename __invoke_result<_Fn2, _Args...>::type;
924 template<
typename _Tp>
925 static decltype(!std::declval<_Tp>())
926 _S_not() noexcept(noexcept(!std::declval<_Tp>()));
929 template<
typename _Fn2>
932 : _M_fn(std::forward<_Fn2>(__fn)) { }
934 _Not_fn(
const _Not_fn& __fn) =
default;
935 _Not_fn(_Not_fn&& __fn) =
default;
936 ~_Not_fn() =
default;
941 #define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \
942 template<typename... _Args> \
943 _GLIBCXX20_CONSTEXPR \
944 decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \
945 operator()(_Args&&... __args) _QUALS \
946 noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \
947 && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \
949 return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \
950 std::forward<_Args>(__args)...); \
952 _GLIBCXX_NOT_FN_CALL_OP( & )
953 _GLIBCXX_NOT_FN_CALL_OP(
const & )
954 _GLIBCXX_NOT_FN_CALL_OP( && )
955 _GLIBCXX_NOT_FN_CALL_OP(
const && )
956 #undef _GLIBCXX_NOT_FN_CALL_OP
962 template<
typename _Tp,
typename _Pred>
965 template<
typename _Tp>
966 struct __is_byte_like<_Tp, equal_to<_Tp>>
967 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
969 template<
typename _Tp>
970 struct __is_byte_like<_Tp, equal_to<void>>
971 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
973 #if __cplusplus >= 201703L
975 enum class byte : unsigned char;
978 struct __is_byte_like<byte, equal_to<byte>>
982 struct __is_byte_like<byte, equal_to<void>>
985 #define __cpp_lib_not_fn 201603
987 template<
typename _Fn>
991 noexcept(std::is_nothrow_constructible<std::
decay_t<_Fn>, _Fn&&>::value)
993 return _Not_fn<std::decay_t<_Fn>>{std::forward<_Fn>(__fn), 0};
997 #define __cpp_lib_boyer_moore_searcher 201603
999 template<
typename _ForwardIterator1,
typename _BinaryPredicate = equal_to<>>
1000 class default_searcher
1003 _GLIBCXX20_CONSTEXPR
1004 default_searcher(_ForwardIterator1 __pat_first,
1005 _ForwardIterator1 __pat_last,
1006 _BinaryPredicate __pred = _BinaryPredicate())
1007 : _M_m(__pat_first, __pat_last, std::
move(__pred))
1010 template<
typename _ForwardIterator2>
1011 _GLIBCXX20_CONSTEXPR
1012 pair<_ForwardIterator2, _ForwardIterator2>
1013 operator()(_ForwardIterator2 __first, _ForwardIterator2 __last)
const
1015 _ForwardIterator2 __first_ret =
1016 std::search(__first, __last, std::get<0>(_M_m), std::get<1>(_M_m),
1018 auto __ret = std::make_pair(__first_ret, __first_ret);
1019 if (__ret.first != __last)
1021 std::get<1>(_M_m)));
1026 tuple<_ForwardIterator1, _ForwardIterator1, _BinaryPredicate> _M_m;
1029 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred>
1030 struct __boyer_moore_map_base
1032 template<
typename _RAIter>
1033 __boyer_moore_map_base(_RAIter __pat,
size_t __patlen,
1034 _Hash&& __hf, _Pred&& __pred)
1038 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1039 _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
1042 using __diff_type = _Tp;
1045 _M_lookup(_Key __key, __diff_type __not_found)
const
1047 auto __iter = _M_bad_char.find(__key);
1048 if (__iter == _M_bad_char.end())
1050 return __iter->second;
1054 _M_pred()
const {
return _M_bad_char.key_eq(); }
1056 _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
1059 template<
typename _Tp,
size_t _Len,
typename _Pred>
1060 struct __boyer_moore_array_base
1062 template<
typename _RAIter,
typename _Unused>
1063 __boyer_moore_array_base(_RAIter __pat,
size_t __patlen,
1064 _Unused&&, _Pred&& __pred)
1065 : _M_bad_char{ _GLIBCXX_STD_C::array<_Tp, _Len>{},
std::move(__pred) }
1067 std::get<0>(_M_bad_char).fill(__patlen);
1069 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1071 auto __ch = __pat[__i];
1072 using _UCh = make_unsigned_t<decltype(__ch)>;
1073 auto __uch =
static_cast<_UCh
>(__ch);
1074 std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
1078 using __diff_type = _Tp;
1080 template<
typename _Key>
1082 _M_lookup(_Key __key, __diff_type __not_found)
const
1084 auto __ukey =
static_cast<make_unsigned_t<_Key>
>(__key);
1087 return std::get<0>(_M_bad_char)[__ukey];
1091 _M_pred()
const {
return std::get<1>(_M_bad_char); }
1093 tuple<_GLIBCXX_STD_C::array<_Tp, _Len>, _Pred> _M_bad_char;
1098 template<
typename _RAIter,
typename _Hash,
typename _Pred,
1099 typename _Val =
typename iterator_traits<_RAIter>::value_type,
1100 typename _Diff =
typename iterator_traits<_RAIter>::difference_type>
1101 using __boyer_moore_base_t
1102 = conditional_t<__is_byte_like<_Val, _Pred>::value,
1103 __boyer_moore_array_base<_Diff, 256, _Pred>,
1104 __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
1106 template<
typename _RAIter,
typename _Hash
1107 = hash<typename iterator_traits<_RAIter>::value_type>,
1108 typename _BinaryPredicate = equal_to<>>
1109 class boyer_moore_searcher
1110 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1112 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1113 using typename _Base::__diff_type;
1116 boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1117 _Hash __hf = _Hash(),
1118 _BinaryPredicate __pred = _BinaryPredicate());
1120 template<
typename _RandomAccessIterator2>
1121 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1122 operator()(_RandomAccessIterator2 __first,
1123 _RandomAccessIterator2 __last)
const;
1127 _M_is_prefix(_RAIter __word, __diff_type __len,
1130 const auto& __pred = this->_M_pred();
1131 __diff_type __suffixlen = __len - __pos;
1132 for (__diff_type __i = 0; __i < __suffixlen; ++__i)
1133 if (!__pred(__word[__i], __word[__pos + __i]))
1139 _M_suffix_length(_RAIter __word, __diff_type __len,
1142 const auto& __pred = this->_M_pred();
1143 __diff_type __i = 0;
1144 while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
1152 template<
typename _Tp>
1154 _M_bad_char_shift(_Tp __c)
const
1155 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1159 _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
1162 template<
typename _RAIter,
typename _Hash
1163 = hash<typename iterator_traits<_RAIter>::value_type>,
1164 typename _BinaryPredicate = equal_to<>>
1165 class boyer_moore_horspool_searcher
1166 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1168 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1169 using typename _Base::__diff_type;
1172 boyer_moore_horspool_searcher(_RAIter __pat,
1174 _Hash __hf = _Hash(),
1175 _BinaryPredicate __pred
1176 = _BinaryPredicate())
1177 : _Base(__pat, __pat_end - __pat, std::
move(__hf), std::
move(__pred)),
1178 _M_pat(__pat), _M_pat_end(__pat_end)
1181 template<
typename _RandomAccessIterator2>
1182 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1183 operator()(_RandomAccessIterator2 __first,
1184 _RandomAccessIterator2 __last)
const
1186 const auto& __pred = this->_M_pred();
1187 auto __patlen = _M_pat_end - _M_pat;
1189 return std::make_pair(__first, __first);
1190 auto __len = __last - __first;
1191 while (__len >= __patlen)
1193 for (
auto __scan = __patlen - 1;
1194 __pred(__first[__scan], _M_pat[__scan]); --__scan)
1196 return std::make_pair(__first, __first + __patlen);
1197 auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
1201 return std::make_pair(__last, __last);
1205 template<
typename _Tp>
1207 _M_bad_char_shift(_Tp __c)
const
1208 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1214 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1215 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1216 boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
1217 _Hash __hf, _BinaryPredicate __pred)
1218 : _Base(__pat, __pat_end - __pat, std::
move(__hf), std::
move(__pred)),
1219 _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
1221 auto __patlen = __pat_end - __pat;
1224 __diff_type __last_prefix = __patlen - 1;
1225 for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
1227 if (_M_is_prefix(__pat, __patlen, __p + 1))
1228 __last_prefix = __p + 1;
1229 _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
1231 for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
1233 auto __slen = _M_suffix_length(__pat, __patlen, __p);
1234 auto __pos = __patlen - 1 - __slen;
1235 if (!__pred(__pat[__p - __slen], __pat[__pos]))
1236 _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
1240 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1241 template<
typename _RandomAccessIterator2>
1242 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1243 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1244 operator()(_RandomAccessIterator2 __first,
1245 _RandomAccessIterator2 __last)
const
1247 auto __patlen = _M_pat_end - _M_pat;
1249 return std::make_pair(__first, __first);
1250 const auto& __pred = this->_M_pred();
1251 __diff_type __i = __patlen - 1;
1252 auto __stringlen = __last - __first;
1253 while (__i < __stringlen)
1255 __diff_type __j = __patlen - 1;
1256 while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
1263 const auto __match = __first + __i + 1;
1264 return std::make_pair(__match, __match + __patlen);
1266 __i +=
std::max(_M_bad_char_shift(__first[__i]),
1267 _M_good_suffix[__j]);
1269 return std::make_pair(__last, __last);
1275 _GLIBCXX_END_NAMESPACE_VERSION
1280 #endif // _GLIBCXX_FUNCTIONAL
constexpr _Bind_helper< __is_socketlike< _Func >::value, _Func, _BoundArgs...>::type bind(_Func &&__f, _BoundArgs &&...__args)
Function template for std::bind.
integer_sequence< size_t, _Idx...> index_sequence
Alias template index_sequence.
constexpr tuple< _Elements &&...> forward_as_tuple(_Elements &&...__args) noexcept
std::forward_as_tuple
constexpr _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __predicate)
Search a sequence for a matching sub-sequence using a predicate.
Determines if the given type _Tp is a function object that should be treated as a subexpression when ...
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
Primary class template for reference_wrapper.
Primary class template, tuple.
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 _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 void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
Type of the function object returned from bind().
Determines if the given type _Tp is a placeholder in a bind() expression and, if so, which placeholder it is.
make_index_sequence< sizeof...(_Types)> index_sequence_for
Alias template index_sequence_for.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Type of the function object returned from bind<R>().
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
typename decay< _Tp >::type decay_t
Alias template for decay.