43#ifndef _GLIBCXX_FUNCTIONAL
44#define _GLIBCXX_FUNCTIONAL 1
47#pragma GCC system_header
53#if __cplusplus >= 201103L
55#define __glibcxx_want_boyer_moore_searcher
56#define __glibcxx_want_bind_front
57#define __glibcxx_want_bind_back
58#define __glibcxx_want_constexpr_functional
59#define __glibcxx_want_copyable_function
60#define __glibcxx_want_function_ref
61#define __glibcxx_want_invoke
62#define __glibcxx_want_invoke_r
63#define __glibcxx_want_move_only_function
64#define __glibcxx_want_not_fn
65#define __glibcxx_want_ranges
66#define __glibcxx_want_reference_wrapper
67#define __glibcxx_want_transparent_operators
77#if __cplusplus >= 201703L
85#if __cplusplus >= 202002L
86# include <bits/binders.h>
90#if __glibcxx_move_only_function || __glibcxx_copyable_function || \
91 __glibcxx_function_ref
97namespace std _GLIBCXX_VISIBILITY(default)
99_GLIBCXX_BEGIN_NAMESPACE_VERSION
107#ifdef __cpp_lib_invoke
120 template<
typename _Callable,
typename... _Args>
121 inline _GLIBCXX20_CONSTEXPR invoke_result_t<_Callable, _Args...>
122 invoke(_Callable&& __fn, _Args&&... __args)
123 noexcept(is_nothrow_invocable_v<_Callable, _Args...>)
130#ifdef __cpp_lib_invoke_r
139 template<
typename _Res,
typename _Callable,
typename... _Args>
140 requires is_invocable_r_v<_Res, _Callable, _Args...>
142 invoke_r(_Callable&& __fn, _Args&&... __args)
143 noexcept(is_nothrow_invocable_r_v<_Res, _Callable, _Args...>)
152#if __cplusplus >= 201103L
153 template<
typename _MemFunPtr,
156 :
public _Mem_fn_traits<_MemFunPtr>::__maybe_type
158 using _Traits = _Mem_fn_traits<_MemFunPtr>;
160 using _Arity =
typename _Traits::__arity;
161 using _Varargs =
typename _Traits::__vararg;
163 template<
typename _Func,
typename... _BoundArgs>
164 friend struct _Bind_check_arity;
170 using result_type =
typename _Traits::__result_type;
173 _Mem_fn_base(_MemFunPtr __pmf) noexcept : _M_pmf(__pmf) { }
175 template<
typename... _Args>
178 operator()(_Args&&... __args)
const
186 template<
typename _MemObjPtr>
187 class _Mem_fn_base<_MemObjPtr, false>
189 using _Arity = integral_constant<size_t, 0>;
192 template<
typename _Func,
typename... _BoundArgs>
193 friend struct _Bind_check_arity;
199 _Mem_fn_base(_MemObjPtr __pm) noexcept : _M_pm(__pm) { }
201 template<
typename _Tp>
204 operator()(_Tp&& __obj)
const
210 template<
typename _MemberPo
inter>
213 template<
typename _Res,
typename _Class>
214 struct _Mem_fn<_Res _Class::*>
215 : _Mem_fn_base<_Res _Class::*>
217 using _Mem_fn_base<_Res _Class::*>::_Mem_fn_base;
246 template<
typename _Tp,
typename _Class>
248 inline _Mem_fn<_Tp _Class::*>
251 return _Mem_fn<_Tp _Class::*>(__pm);
265 template<
typename _Tp>
277 template<
typename _Tp>
282#if __cplusplus > 201402L
283 template <
typename _Tp>
inline constexpr bool is_bind_expression_v
285 template <
typename _Tp>
inline constexpr int is_placeholder_v
286 = is_placeholder<_Tp>::value;
300#if __cpp_inline_variables
301# define _GLIBCXX_PLACEHOLDER inline
303# define _GLIBCXX_PLACEHOLDER extern
336#undef _GLIBCXX_PLACEHOLDER
358 template<std::
size_t __i,
typename _Tuple>
359 using _Safe_tuple_element_t
360 =
typename enable_if<(__i < tuple_size<_Tuple>::value),
361 tuple_element<__i, _Tuple>>::type::type;
374 template<
typename _Arg,
375 bool _IsBindExp = is_bind_expression<_Arg>::value,
376 bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
384 template<
typename _Tp>
385 class _Mu<reference_wrapper<_Tp>, false, false>
392 template<
typename _CVRef,
typename _Tuple>
395 operator()(_CVRef& __arg, _Tuple&)
const volatile
396 {
return __arg.get(); }
405 template<
typename _Arg>
406 class _Mu<_Arg, true, false>
409 template<
typename _CVArg,
typename... _Args>
412 operator()(_CVArg& __arg,
413 tuple<_Args...>& __tuple)
const volatile
414 ->
decltype(__arg(declval<_Args>()...))
417 typedef typename _Build_index_tuple<
sizeof...(_Args)>::__type
419 return this->__call(__arg, __tuple, _Indexes());
425 template<
typename _CVArg,
typename... _Args, std::size_t... _Indexes>
428 __call(_CVArg& __arg, tuple<_Args...>& __tuple,
429 const _Index_tuple<_Indexes...>&)
const volatile
430 ->
decltype(__arg(declval<_Args>()...))
432 return __arg(std::get<_Indexes>(
std::move(__tuple))...);
441 template<
typename _Arg>
442 class _Mu<_Arg, false, true>
445 template<
typename _Tuple>
447 _Safe_tuple_element_t<(is_placeholder<_Arg>::value - 1), _Tuple>&&
448 operator()(
const volatile _Arg&, _Tuple& __tuple)
const volatile
451 ::std::get<(is_placeholder<_Arg>::value - 1)>(
std::move(__tuple));
460 template<
typename _Arg>
461 class _Mu<_Arg, false, false>
464 template<
typename _CVArg,
typename _Tuple>
467 operator()(_CVArg&& __arg, _Tuple&)
const volatile
472 template<std::size_t _Ind,
typename... _Tp>
475 -> __tuple_element_t<_Ind,
tuple<_Tp...>>
volatile&
476 {
return std::get<_Ind>(
const_cast<tuple<_Tp...
>&>(__tuple)); }
479 template<std::size_t _Ind,
typename... _Tp>
482 -> __tuple_element_t<_Ind,
tuple<_Tp...>>
const volatile&
483 {
return std::get<_Ind>(
const_cast<const tuple<_Tp...
>&>(__tuple)); }
487#if __cplusplus == 201703L && _GLIBCXX_USE_DEPRECATED
488# define _GLIBCXX_VOLATILE_BIND
491# define _GLIBCXX_DEPR_BIND \
492 [[deprecated("std::bind does not support volatile in C++17")]]
493#elif __cplusplus < 201703L
494# define _GLIBCXX_VOLATILE_BIND
495# define _GLIBCXX_DEPR_BIND
499 template<
typename _Signature>
502 template<
typename _Functor,
typename... _Bound_args>
503 class _Bind<_Functor(_Bound_args...)>
504 :
public _Weak_result_type<_Functor>
506 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
510 tuple<_Bound_args...> _M_bound_args;
513 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
519 _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
524 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
530 _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
534#ifdef _GLIBCXX_VOLATILE_BIND
536 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
538 __call_v(tuple<_Args...>&& __args,
539 _Index_tuple<_Indexes...>)
volatile
542 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
547 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
549 __call_c_v(tuple<_Args...>&& __args,
550 _Index_tuple<_Indexes...>)
const volatile
553 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
558 template<
typename _BoundArg,
typename _CallArgs>
559 using _Mu_type =
decltype(
560 _Mu<typename remove_cv<_BoundArg>::type>()(
563 template<
typename _Fn,
typename _CallArgs,
typename... _BArgs>
565 = __invoke_result_t<_Fn&, _Mu_type<_BArgs, _CallArgs>&&...>;
567 template<
typename _CallArgs>
568 using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
570 template<
typename _CallArgs>
571 using __dependent =
typename
572 enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
574 template<
typename _CallArgs,
template<
class>
class __cv_quals>
575 using _Res_type_cv = _Res_type_impl<
576 typename __cv_quals<__dependent<_CallArgs>>::type,
578 typename __cv_quals<_Bound_args>::type...>;
581 template<
typename... _Args>
582 explicit _GLIBCXX20_CONSTEXPR
583 _Bind(
const _Functor& __f, _Args&&... __args)
584 : _M_f(__f), _M_bound_args(std::
forward<_Args>(__args)...)
587 template<
typename... _Args>
588 explicit _GLIBCXX20_CONSTEXPR
589 _Bind(_Functor&& __f, _Args&&... __args)
590 : _M_f(std::
move(__f)), _M_bound_args(std::
forward<_Args>(__args)...)
593 _Bind(
const _Bind&) =
default;
594 _Bind(_Bind&&) =
default;
597 template<
typename... _Args,
598 typename _Result = _Res_type<tuple<_Args...>>>
601 operator()(_Args&&... __args)
603 return this->__call<_Result>(
609 template<
typename... _Args,
610 typename _Result = _Res_type_cv<tuple<_Args...>, add_const>>
613 operator()(_Args&&... __args)
const
615 return this->__call_c<_Result>(
620#ifdef _GLIBCXX_VOLATILE_BIND
622 template<
typename... _Args,
623 typename _Result = _Res_type_cv<tuple<_Args...>, add_volatile>>
626 operator()(_Args&&... __args)
volatile
628 return this->__call_v<_Result>(
634 template<
typename... _Args,
635 typename _Result = _Res_type_cv<tuple<_Args...>, add_cv>>
638 operator()(_Args&&... __args)
const volatile
640 return this->__call_c_v<_Result>(
648 template<
typename _Result,
typename _Signature>
651 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
654 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
658 tuple<_Bound_args...> _M_bound_args;
661 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
666 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
667 (std::get<_Indexes>(_M_bound_args), __args)...);
671 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
676 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
677 (std::get<_Indexes>(_M_bound_args), __args)...);
680#ifdef _GLIBCXX_VOLATILE_BIND
682 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
686 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
687 (__volget<_Indexes>(_M_bound_args), __args)...);
691 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
694 _Index_tuple<_Indexes...>)
const volatile
696 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
697 (__volget<_Indexes>(_M_bound_args), __args)...);
702 typedef _Result result_type;
704 template<
typename... _Args>
705 explicit _GLIBCXX20_CONSTEXPR
710 template<
typename... _Args>
711 explicit _GLIBCXX20_CONSTEXPR
720 template<
typename... _Args>
723 operator()(_Args&&... __args)
725 return this->__call<_Result>(
731 template<
typename... _Args>
734 operator()(_Args&&... __args)
const
736 return this->__call<_Result>(
741#ifdef _GLIBCXX_VOLATILE_BIND
743 template<
typename... _Args>
746 operator()(_Args&&... __args)
volatile
748 return this->__call<_Result>(
754 template<
typename... _Args>
757 operator()(_Args&&... __args)
const volatile
759 return this->__call<_Result>(
764 template<
typename... _Args>
765 void operator()(_Args&&...)
const volatile =
delete;
769#undef _GLIBCXX_VOLATILE_BIND
770#undef _GLIBCXX_DEPR_BIND
776 template<
typename _Signature>
784 template<
typename _Signature>
792 template<
typename _Signature>
800 template<
typename _Signature>
808 template<
typename _Result,
typename _Signature>
816 template<
typename _Result,
typename _Signature>
824 template<
typename _Result,
typename _Signature>
832 template<
typename _Result,
typename _Signature>
836 template<
typename _Func,
typename... _BoundArgs>
837 struct _Bind_check_arity { };
839 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
840 struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
842 static_assert(
sizeof...(_BoundArgs) ==
sizeof...(_Args),
843 "Wrong number of arguments for function");
846 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
847 struct _Bind_check_arity<_Ret (*)(_Args..., ...), _BoundArgs...>
849 static_assert(
sizeof...(_BoundArgs) >=
sizeof...(_Args),
850 "Wrong number of arguments for function");
853 template<
typename _Tp,
typename _Class,
typename... _BoundArgs>
854 struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
856 using _Arity =
typename _Mem_fn<_Tp _Class::*>::_Arity;
857 using _Varargs =
typename _Mem_fn<_Tp _Class::*>::_Varargs;
858 static_assert(_Varargs::value
859 ?
sizeof...(_BoundArgs) >= _Arity::value + 1
860 :
sizeof...(_BoundArgs) == _Arity::value + 1,
861 "Wrong number of arguments for pointer-to-member");
867 template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
868 using __is_socketlike = __or_<is_integral<_Tp2>,
is_enum<_Tp2>>;
870 template<
bool _SocketLike,
typename _Func,
typename... _BoundArgs>
872 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
874 typedef typename decay<_Func>::type __func_type;
875 typedef _Bind<__func_type(
typename decay<_BoundArgs>::type...)> type;
881 template<
typename _Func,
typename... _BoundArgs>
882 struct _Bind_helper<true, _Func, _BoundArgs...>
890 template<
typename _Func,
typename... _BoundArgs>
891 inline _GLIBCXX20_CONSTEXPR
typename
892 _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
893 bind(_Func&& __f, _BoundArgs&&... __args)
895 typedef _Bind_helper<
false, _Func, _BoundArgs...> __helper_type;
900 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
901 struct _Bindres_helper
902 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
904 typedef typename decay<_Func>::type __functor_type;
905 typedef _Bind_result<_Result,
906 __functor_type(
typename decay<_BoundArgs>::type...)>
915 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
916 inline _GLIBCXX20_CONSTEXPR
917 typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
918 bind(_Func&& __f, _BoundArgs&&... __args)
920 typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
925#if __cpp_lib_bind_front >= 202306L || __cpp_lib_bind_back >= 202306L
929 using _Fn =
const decltype(__fn)&;
930 template <
typename... _Args>
931 requires is_invocable_v<_Fn, _Args...>
932 constexpr static decltype(
auto)
933 operator()(_Args&&... __args)
934 noexcept(is_nothrow_invocable_v<_Fn, _Args...>)
939#ifdef __cpp_lib_bind_front
949 template<
typename _Fn,
typename... _Args>
950 constexpr _Bind_front_t<_Fn, _Args...>
951 bind_front(_Fn&& __fn, _Args&&... __args)
952 noexcept(is_nothrow_constructible_v<_Bind_front_t<_Fn, _Args...>,
959#if __cpp_lib_bind_front >= 202306L
970 template<
auto __fn,
typename... _BindArgs>
971 constexpr decltype(
auto)
972 bind_front(_BindArgs&&... __bind_args)
973 noexcept(__and_v<is_nothrow_constructible<_BindArgs>...>)
975 using _Fn =
decltype(__fn);
977 (is_constructible_v<decay_t<_BindArgs>, _BindArgs> && ...) &&
978 (is_move_constructible_v<decay_t<_BindArgs>> && ...));
979 if constexpr (is_pointer_v<_Fn> || is_member_pointer_v<_Fn>)
980 static_assert(__fn !=
nullptr);
982 if constexpr (
sizeof...(_BindArgs) == 0)
983 return _Bind_fn_t<__fn>{};
986 <
typename _Self,
typename... _CallArgs>
987 (
this _Self&&, _CallArgs&&... __call_args)
988 noexcept(is_nothrow_invocable_v<
991 requires is_invocable_v<
994 return std::invoke(__fn,
995 std::forward_like<_Self>(__bound_args)...,
1004#ifdef __cpp_lib_bind_back
1014 template<
typename _Fn,
typename... _Args>
1015 constexpr _Bind_back_t<_Fn, _Args...>
1016 bind_back(_Fn&& __fn, _Args&&... __args)
1017 noexcept(is_nothrow_constructible_v<_Bind_back_t<_Fn, _Args...>,
1018 int, _Fn, _Args...>)
1024#if __cpp_lib_bind_back >= 202306L
1035 template<
auto __fn,
typename... _BindArgs>
1036 constexpr decltype(
auto)
1037 bind_back(_BindArgs&&... __bind_args)
1038 noexcept(__and_v<is_nothrow_constructible<_BindArgs>...>)
1040 using _Fn =
decltype(__fn);
1042 (is_constructible_v<decay_t<_BindArgs>, _BindArgs> && ...) &&
1043 (is_move_constructible_v<decay_t<_BindArgs>> && ...));
1044 if constexpr (is_pointer_v<_Fn> || is_member_pointer_v<_Fn>)
1045 static_assert(__fn !=
nullptr);
1047 if constexpr (
sizeof...(_BindArgs) == 0)
1048 return _Bind_fn_t<__fn>{};
1053 <
typename _Self,
typename... _CallArgs>
1054 (
this _Self&&, _CallArgs&&... __call_args)
1055 noexcept(is_nothrow_invocable_v<
1056 const _Fn&, _CallArgs..., __like_t<_Self, decay_t<_BindArgs>>...>)
1058 requires is_invocable_v<
1059 const _Fn&, _CallArgs..., __like_t<_Self, decay_t<_BindArgs>>...>
1061 return std::invoke(__fn,
1063 std::forward_like<_Self>(__bound_args)...);
1071#if __cplusplus >= 201402L
1073 template<
typename _Fn>
1076 template<
typename _Fn2,
typename... _Args>
1077 using __inv_res_t =
typename __invoke_result<_Fn2, _Args...>
::type;
1079 template<
typename _Tp>
1084 template<
typename _Fn2>
1086 _Not_fn(_Fn2&& __fn,
int)
1089 _Not_fn(
const _Not_fn& __fn) =
default;
1090 _Not_fn(_Not_fn&& __fn) =
default;
1091 ~_Not_fn() =
default;
1096#define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \
1097 template<typename... _Args, \
1098 typename = enable_if_t<__is_invocable<_Fn _QUALS, _Args...>::value>> \
1099 _GLIBCXX20_CONSTEXPR \
1100 decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \
1101 operator()(_Args&&... __args) _QUALS \
1102 noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \
1103 && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \
1105 return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \
1106 std::forward<_Args>(__args)...); \
1109 template<typename... _Args, \
1110 typename = enable_if_t<!__is_invocable<_Fn _QUALS, _Args...>::value>> \
1111 void operator()(_Args&&... __args) _QUALS = delete;
1113 _GLIBCXX_NOT_FN_CALL_OP( & )
1114 _GLIBCXX_NOT_FN_CALL_OP(
const & )
1115 _GLIBCXX_NOT_FN_CALL_OP( && )
1116 _GLIBCXX_NOT_FN_CALL_OP(
const && )
1117#undef _GLIBCXX_NOT_FN_CALL_OP
1123 template<
typename _Tp,
typename _Pred>
1126 template<
typename _Tp>
1127 struct __is_byte_like<_Tp, equal_to<_Tp>>
1128 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
1130 template<
typename _Tp>
1131 struct __is_byte_like<_Tp, equal_to<void>>
1132 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
1134#if __cplusplus >= 201703L
1136 enum class byte :
unsigned char;
1139 struct __is_byte_like<byte, equal_to<byte>>
1143 struct __is_byte_like<byte, equal_to<void>>
1148#ifdef __cpp_lib_not_fn
1161 template<
typename _Fn>
1162 _GLIBCXX20_CONSTEXPR
1170#if __cpp_lib_not_fn >= 202306L
1185 constexpr decltype(
auto)
1188 using _Fn =
decltype(__fn);
1189 if constexpr (is_pointer_v<_Fn> || is_member_pointer_v<_Fn>)
1190 static_assert(__fn !=
nullptr);
1191 return []<
typename... _Args>(_Args&&... __args)
static
1203#if __cplusplus >= 201703L
1206 template<
typename _ForwardIterator1,
typename _BinaryPredicate = equal_to<>>
1207 class default_searcher
1210 _GLIBCXX20_CONSTEXPR
1211 default_searcher(_ForwardIterator1 __pat_first,
1212 _ForwardIterator1 __pat_last,
1213 _BinaryPredicate __pred = _BinaryPredicate())
1214 : _M_m(__pat_first, __pat_last, std::
move(__pred))
1217 template<
typename _ForwardIterator2>
1218 _GLIBCXX20_CONSTEXPR
1219 pair<_ForwardIterator2, _ForwardIterator2>
1220 operator()(_ForwardIterator2 __first, _ForwardIterator2 __last)
const
1222 _ForwardIterator2 __first_ret =
1223 std::search(__first, __last, std::get<0>(_M_m), std::get<1>(_M_m),
1226 if (__ret.first != __last)
1228 std::get<1>(_M_m)));
1233 tuple<_ForwardIterator1, _ForwardIterator1, _BinaryPredicate> _M_m;
1236#ifdef __cpp_lib_boyer_moore_searcher
1238 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred>
1239 struct __boyer_moore_map_base
1241 template<
typename _RAIter>
1242 __boyer_moore_map_base(_RAIter __pat,
size_t __patlen,
1243 _Hash&& __hf, _Pred&& __pred)
1244 : _M_bad_char{ __patlen, std::
move(__hf), std::
move(__pred) }
1247 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1248 _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
1251 using __diff_type = _Tp;
1254 _M_lookup(_Key __key, __diff_type __not_found)
const
1256 auto __iter = _M_bad_char.find(__key);
1257 if (__iter == _M_bad_char.end())
1259 return __iter->second;
1263 _M_pred()
const {
return _M_bad_char.key_eq(); }
1265 _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
1268 template<
typename _Tp,
size_t _Len,
typename _Pred>
1269 struct __boyer_moore_array_base
1271 template<
typename _RAIter,
typename _Unused>
1272 __boyer_moore_array_base(_RAIter __pat,
size_t __patlen,
1273 _Unused&&, _Pred&& __pred)
1274 : _M_bad_char{ array<_Tp, _Len>{},
std::move(__pred) }
1276 std::get<0>(_M_bad_char).fill(__patlen);
1278 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1280 auto __ch = __pat[__i];
1282 auto __uch =
static_cast<_UCh
>(__ch);
1283 std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
1287 using __diff_type = _Tp;
1289 template<
typename _Key>
1291 _M_lookup(_Key __key, __diff_type __not_found)
const
1293 auto __ukey =
static_cast<make_unsigned_t<_Key>
>(__key);
1296 return std::get<0>(_M_bad_char)[__ukey];
1300 _M_pred()
const {
return std::get<1>(_M_bad_char); }
1302 tuple<array<_Tp, _Len>, _Pred> _M_bad_char;
1307 template<
typename _RAIter,
typename _Hash,
typename _Pred,
1308 typename _Val =
typename iterator_traits<_RAIter>::value_type,
1309 typename _Diff =
typename iterator_traits<_RAIter>::difference_type>
1310 using __boyer_moore_base_t
1311 = __conditional_t<__is_byte_like<_Val, _Pred>::value,
1312 __boyer_moore_array_base<_Diff, 256, _Pred>,
1313 __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
1315 template<
typename _RAIter,
typename _Hash
1316 = hash<typename iterator_traits<_RAIter>::value_type>,
1317 typename _BinaryPredicate = equal_to<>>
1318 class boyer_moore_searcher
1319 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1321 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1322 using typename _Base::__diff_type;
1325 boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1326 _Hash __hf = _Hash(),
1327 _BinaryPredicate __pred = _BinaryPredicate());
1329 template<
typename _RandomAccessIterator2>
1330 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1331 operator()(_RandomAccessIterator2 __first,
1332 _RandomAccessIterator2 __last)
const;
1336 _M_is_prefix(_RAIter __word, __diff_type __len,
1339 const auto& __pred = this->_M_pred();
1340 __diff_type __suffixlen = __len - __pos;
1341 for (__diff_type __i = 0; __i < __suffixlen; ++__i)
1342 if (!__pred(__word[__i], __word[__pos + __i]))
1348 _M_suffix_length(_RAIter __word, __diff_type __len,
1351 const auto& __pred = this->_M_pred();
1352 __diff_type __i = 0;
1353 while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
1361 template<
typename _Tp>
1363 _M_bad_char_shift(_Tp __c)
const
1364 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1368 _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
1371 template<
typename _RAIter,
typename _Hash
1372 = hash<typename iterator_traits<_RAIter>::value_type>,
1373 typename _BinaryPredicate = equal_to<>>
1374 class boyer_moore_horspool_searcher
1375 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1377 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1378 using typename _Base::__diff_type;
1381 boyer_moore_horspool_searcher(_RAIter __pat,
1383 _Hash __hf = _Hash(),
1384 _BinaryPredicate __pred
1385 = _BinaryPredicate())
1386 : _Base(__pat, __pat_end - __pat, std::
move(__hf), std::
move(__pred)),
1387 _M_pat(__pat), _M_pat_end(__pat_end)
1390 template<
typename _RandomAccessIterator2>
1391 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1392 operator()(_RandomAccessIterator2 __first,
1393 _RandomAccessIterator2 __last)
const
1395#ifdef __glibcxx_concepts
1398 static_assert(is_same_v<iter_value_t<_RAIter>,
1399 iter_value_t<_RandomAccessIterator2>>);
1401 const auto& __pred = this->_M_pred();
1402 auto __patlen = _M_pat_end - _M_pat;
1405 auto __len = __last - __first;
1406 while (__len >= __patlen)
1408 for (
auto __scan = __patlen - 1;
1409 __pred(__first[__scan], _M_pat[__scan]); --__scan)
1412 auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
1420 template<
typename _Tp>
1422 _M_bad_char_shift(_Tp __c)
const
1423 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1429 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1430 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1431 boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
1432 _Hash __hf, _BinaryPredicate __pred)
1433 : _Base(__pat, __pat_end - __pat,
std::
move(__hf),
std::
move(__pred)),
1434 _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
1436 auto __patlen = __pat_end - __pat;
1439 __diff_type __last_prefix = __patlen - 1;
1440 for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
1442 if (_M_is_prefix(__pat, __patlen, __p + 1))
1443 __last_prefix = __p + 1;
1444 _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
1446 for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
1448 auto __slen = _M_suffix_length(__pat, __patlen, __p);
1449 auto __pos = __patlen - 1 - __slen;
1450 if (!__pred(__pat[__p - __slen], __pat[__pos]))
1451 _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
1455 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1456 template<
typename _RandomAccessIterator2>
1458 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1459 operator()(_RandomAccessIterator2 __first,
1460 _RandomAccessIterator2 __last)
const
1462#ifdef __glibcxx_concepts
1465 static_assert(is_same_v<iter_value_t<_RAIter>,
1466 iter_value_t<_RandomAccessIterator2>>);
1468 auto __patlen = _M_pat_end - _M_pat;
1471 const auto& __pred = this->_M_pred();
1472 __diff_type __i = __patlen - 1;
1473 auto __stringlen = __last - __first;
1474 while (__i < __stringlen)
1476 __diff_type __j = __patlen - 1;
1477 while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
1484 const auto __match = __first + __diff_type(__i + 1);
1487 __i +=
std::max(_M_bad_char_shift(__first[__i]),
1488 _M_good_suffix[__j]);
1498_GLIBCXX_END_NAMESPACE_VERSION
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
typename make_unsigned< _Tp >::type make_unsigned_t
Alias template for make_unsigned.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
typename decay< _Tp >::type decay_t
Alias template for decay.
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.
auto declval() noexcept -> decltype(__declval< _Tp >(0))
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 _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 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.
auto not_fn(_Fn &&__fn) noexcept(std::is_nothrow_constructible< std::decay_t< _Fn >, _Fn && >::value)
[func.not_fn] Function template not_fn
ISO C++ 2011 namespace for std::bind placeholders.
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.
is_member_function_pointer
Struct holding two objects of arbitrary type.