43#ifndef _GLIBCXX_FUNCTIONAL
44#define _GLIBCXX_FUNCTIONAL 1
46#pragma GCC system_header
51#if __cplusplus >= 201103L
61#if __cplusplus >= 201703L
69#if __cplusplus >= 202002L
73#if __cplusplus > 202002L && _GLIBCXX_HOSTED
79namespace std _GLIBCXX_VISIBILITY(default)
81_GLIBCXX_BEGIN_NAMESPACE_VERSION
89#if __cplusplus >= 201103L
91#if __cplusplus >= 201703L
92# define __cpp_lib_invoke 201411L
93# if __cplusplus > 201703L
94# define __cpp_lib_constexpr_functional 201907L
108 template<
typename _Callable,
typename... _Args>
110 invoke(_Callable&& __fn, _Args&&... __args)
111 noexcept(is_nothrow_invocable_v<_Callable, _Args...>)
114 std::forward<_Args>(__args)...);
117#if __cplusplus > 202002L
118# define __cpp_lib_invoke_r 202106L
127 template<
typename _Res,
typename _Callable,
typename... _Args>
128 requires is_invocable_r_v<_Res, _Callable, _Args...>
130 invoke_r(_Callable&& __fn, _Args&&... __args)
131 noexcept(is_nothrow_invocable_r_v<_Res, _Callable, _Args...>)
133 return std::__invoke_r<_Res>(std::forward<_Callable>(__fn),
134 std::forward<_Args>(__args)...);
141 template<
typename _MemFunPtr,
142 bool __is_mem_fn = is_member_function_pointer<_MemFunPtr>::value>
144 :
public _Mem_fn_traits<_MemFunPtr>::__maybe_type
146 using _Traits = _Mem_fn_traits<_MemFunPtr>;
148 using _Arity =
typename _Traits::__arity;
149 using _Varargs =
typename _Traits::__vararg;
151 template<
typename _Func,
typename... _BoundArgs>
152 friend struct _Bind_check_arity;
158 using result_type =
typename _Traits::__result_type;
161 _Mem_fn_base(_MemFunPtr __pmf) noexcept : _M_pmf(__pmf) { }
163 template<
typename... _Args>
166 operator()(_Args&&... __args)
const
169 ->
decltype(
std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
170 {
return std::__invoke(_M_pmf, std::forward<_Args>(__args)...); }
174 template<
typename _MemObjPtr>
175 class _Mem_fn_base<_MemObjPtr, false>
177 using _Arity = integral_constant<size_t, 0>;
180 template<
typename _Func,
typename... _BoundArgs>
181 friend struct _Bind_check_arity;
187 _Mem_fn_base(_MemObjPtr __pm) noexcept : _M_pm(__pm) { }
189 template<
typename _Tp>
192 operator()(_Tp&& __obj)
const
193 noexcept(
noexcept(
std::__invoke(_M_pm, std::forward<_Tp>(__obj))))
198 template<
typename _MemberPo
inter>
201 template<
typename _Res,
typename _Class>
202 struct _Mem_fn<_Res _Class::*>
203 : _Mem_fn_base<_Res _Class::*>
205 using _Mem_fn_base<_Res _Class::*>::_Mem_fn_base;
234 template<
typename _Tp,
typename _Class>
236 inline _Mem_fn<_Tp _Class::*>
239 return _Mem_fn<_Tp _Class::*>(__pm);
253 template<
typename _Tp>
265 template<
typename _Tp>
270#if __cplusplus > 201402L
271 template <
typename _Tp>
inline constexpr bool is_bind_expression_v
273 template <
typename _Tp>
inline constexpr int is_placeholder_v
282 namespace placeholders
288#if __cpp_inline_variables
289# define _GLIBCXX_PLACEHOLDER inline
291# define _GLIBCXX_PLACEHOLDER extern
324#undef _GLIBCXX_PLACEHOLDER
346 template<std::
size_t __i,
typename _Tuple>
347 using _Safe_tuple_element_t
348 =
typename enable_if<(__i < tuple_size<_Tuple>::value),
349 tuple_element<__i, _Tuple>>::type::type;
362 template<
typename _Arg,
363 bool _IsBindExp = is_bind_expression<_Arg>::value,
364 bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
372 template<
typename _Tp>
373 class _Mu<reference_wrapper<_Tp>, false, false>
380 template<
typename _CVRef,
typename _Tuple>
383 operator()(_CVRef& __arg, _Tuple&)
const volatile
384 {
return __arg.get(); }
393 template<
typename _Arg>
394 class _Mu<_Arg, true, false>
397 template<
typename _CVArg,
typename... _Args>
400 operator()(_CVArg& __arg,
401 tuple<_Args...>& __tuple)
const volatile
402 ->
decltype(__arg(declval<_Args>()...))
405 typedef typename _Build_index_tuple<
sizeof...(_Args)>::__type
407 return this->__call(__arg, __tuple, _Indexes());
413 template<
typename _CVArg,
typename... _Args, std::size_t... _Indexes>
416 __call(_CVArg& __arg, tuple<_Args...>& __tuple,
417 const _Index_tuple<_Indexes...>&)
const volatile
418 ->
decltype(__arg(declval<_Args>()...))
420 return __arg(std::get<_Indexes>(
std::move(__tuple))...);
429 template<
typename _Arg>
430 class _Mu<_Arg, false, true>
433 template<
typename _Tuple>
435 _Safe_tuple_element_t<(is_placeholder<_Arg>::value - 1), _Tuple>&&
436 operator()(
const volatile _Arg&, _Tuple& __tuple)
const volatile
439 ::std::get<(is_placeholder<_Arg>::value - 1)>(
std::move(__tuple));
448 template<
typename _Arg>
449 class _Mu<_Arg, false, false>
452 template<
typename _CVArg,
typename _Tuple>
455 operator()(_CVArg&& __arg, _Tuple&)
const volatile
456 {
return std::forward<_CVArg>(__arg); }
460 template<std::size_t _Ind,
typename... _Tp>
462 __volget(
volatile tuple<_Tp...>& __tuple)
463 -> __tuple_element_t<_Ind, tuple<_Tp...>>
volatile&
464 {
return std::get<_Ind>(
const_cast<tuple<_Tp...
>&>(__tuple)); }
467 template<std::size_t _Ind,
typename... _Tp>
469 __volget(
const volatile tuple<_Tp...>& __tuple)
470 -> __tuple_element_t<_Ind, tuple<_Tp...>>
const volatile&
471 {
return std::get<_Ind>(
const_cast<const tuple<_Tp...
>&>(__tuple)); }
475#if __cplusplus == 201703L && _GLIBCXX_USE_DEPRECATED
476# define _GLIBCXX_VOLATILE_BIND
479# define _GLIBCXX_DEPR_BIND \
480 [[deprecated("std::bind does not support volatile in C++17")]]
481#elif __cplusplus < 201703L
482# define _GLIBCXX_VOLATILE_BIND
483# define _GLIBCXX_DEPR_BIND
487 template<
typename _Signature>
490 template<
typename _Functor,
typename... _Bound_args>
491 class _Bind<_Functor(_Bound_args...)>
492 :
public _Weak_result_type<_Functor>
494 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
498 tuple<_Bound_args...> _M_bound_args;
501 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
507 _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
512 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
518 _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
522#ifdef _GLIBCXX_VOLATILE_BIND
524 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
526 __call_v(tuple<_Args...>&& __args,
527 _Index_tuple<_Indexes...>)
volatile
530 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
535 template<
typename _Result,
typename... _Args, std::size_t... _Indexes>
537 __call_c_v(tuple<_Args...>&& __args,
538 _Index_tuple<_Indexes...>)
const volatile
541 _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
546 template<
typename _BoundArg,
typename _CallArgs>
547 using _Mu_type =
decltype(
548 _Mu<typename remove_cv<_BoundArg>::type>()(
549 std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );
551 template<
typename _Fn,
typename _CallArgs,
typename... _BArgs>
553 =
typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
555 template<
typename _CallArgs>
556 using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
558 template<
typename _CallArgs>
559 using __dependent =
typename
560 enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
562 template<
typename _CallArgs,
template<
class>
class __cv_quals>
563 using _Res_type_cv = _Res_type_impl<
564 typename __cv_quals<__dependent<_CallArgs>>::type,
566 typename __cv_quals<_Bound_args>::type...>;
569 template<
typename... _Args>
570 explicit _GLIBCXX20_CONSTEXPR
571 _Bind(
const _Functor& __f, _Args&&... __args)
572 : _M_f(__f), _M_bound_args(
std::
forward<_Args>(__args)...)
575 template<
typename... _Args>
576 explicit _GLIBCXX20_CONSTEXPR
577 _Bind(_Functor&& __f, _Args&&... __args)
581 _Bind(
const _Bind&) =
default;
582 _Bind(_Bind&&) =
default;
585 template<
typename... _Args,
586 typename _Result = _Res_type<tuple<_Args...>>>
589 operator()(_Args&&... __args)
591 return this->__call<_Result>(
597 template<
typename... _Args,
598 typename _Result = _Res_type_cv<tuple<_Args...>, add_const>>
601 operator()(_Args&&... __args)
const
603 return this->__call_c<_Result>(
608#ifdef _GLIBCXX_VOLATILE_BIND
610 template<
typename... _Args,
611 typename _Result = _Res_type_cv<tuple<_Args...>, add_volatile>>
614 operator()(_Args&&... __args)
volatile
616 return this->__call_v<_Result>(
622 template<
typename... _Args,
623 typename _Result = _Res_type_cv<tuple<_Args...>, add_cv>>
626 operator()(_Args&&... __args)
const volatile
628 return this->__call_c_v<_Result>(
636 template<
typename _Result,
typename _Signature>
639 template<
typename _Result,
typename _Functor,
typename... _Bound_args>
642 typedef typename _Build_index_tuple<
sizeof...(_Bound_args)>::__type
646 tuple<_Bound_args...> _M_bound_args;
649 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
654 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
655 (std::get<_Indexes>(_M_bound_args), __args)...);
659 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
664 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
665 (std::get<_Indexes>(_M_bound_args), __args)...);
668#ifdef _GLIBCXX_VOLATILE_BIND
670 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
674 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
675 (__volget<_Indexes>(_M_bound_args), __args)...);
679 template<
typename _Res,
typename... _Args, std::size_t... _Indexes>
682 _Index_tuple<_Indexes...>)
const volatile
684 return std::__invoke_r<_Res>(_M_f, _Mu<_Bound_args>()
685 (__volget<_Indexes>(_M_bound_args), __args)...);
690 typedef _Result result_type;
692 template<
typename... _Args>
693 explicit _GLIBCXX20_CONSTEXPR
695 : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
698 template<
typename... _Args>
699 explicit _GLIBCXX20_CONSTEXPR
701 : _M_f(
std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
708 template<
typename... _Args>
711 operator()(_Args&&... __args)
713 return this->__call<_Result>(
719 template<
typename... _Args>
722 operator()(_Args&&... __args)
const
724 return this->__call<_Result>(
729#ifdef _GLIBCXX_VOLATILE_BIND
731 template<
typename... _Args>
734 operator()(_Args&&... __args)
volatile
736 return this->__call<_Result>(
742 template<
typename... _Args>
745 operator()(_Args&&... __args)
const volatile
747 return this->__call<_Result>(
752 template<
typename... _Args>
753 void operator()(_Args&&...)
const volatile =
delete;
757#undef _GLIBCXX_VOLATILE_BIND
758#undef _GLIBCXX_DEPR_BIND
764 template<
typename _Signature>
772 template<
typename _Signature>
780 template<
typename _Signature>
788 template<
typename _Signature>
796 template<
typename _Result,
typename _Signature>
804 template<
typename _Result,
typename _Signature>
812 template<
typename _Result,
typename _Signature>
820 template<
typename _Result,
typename _Signature>
824 template<
typename _Func,
typename... _BoundArgs>
825 struct _Bind_check_arity { };
827 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
828 struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
830 static_assert(
sizeof...(_BoundArgs) ==
sizeof...(_Args),
831 "Wrong number of arguments for function");
834 template<
typename _Ret,
typename... _Args,
typename... _BoundArgs>
835 struct _Bind_check_arity<_Ret (*)(_Args......), _BoundArgs...>
837 static_assert(
sizeof...(_BoundArgs) >=
sizeof...(_Args),
838 "Wrong number of arguments for function");
841 template<
typename _Tp,
typename _Class,
typename... _BoundArgs>
842 struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
844 using _Arity =
typename _Mem_fn<_Tp _Class::*>::_Arity;
845 using _Varargs =
typename _Mem_fn<_Tp _Class::*>::_Varargs;
846 static_assert(_Varargs::value
847 ?
sizeof...(_BoundArgs) >= _Arity::value + 1
848 :
sizeof...(_BoundArgs) == _Arity::value + 1,
849 "Wrong number of arguments for pointer-to-member");
855 template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
856 using __is_socketlike = __or_<is_integral<_Tp2>, is_enum<_Tp2>>;
858 template<
bool _SocketLike,
typename _Func,
typename... _BoundArgs>
860 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
862 typedef typename decay<_Func>::type __func_type;
863 typedef _Bind<__func_type(
typename decay<_BoundArgs>::type...)> type;
869 template<
typename _Func,
typename... _BoundArgs>
870 struct _Bind_helper<true, _Func, _BoundArgs...>
878 template<
typename _Func,
typename... _BoundArgs>
879 inline _GLIBCXX20_CONSTEXPR
typename
880 _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
881 bind(_Func&& __f, _BoundArgs&&... __args)
883 typedef _Bind_helper<
false, _Func, _BoundArgs...> __helper_type;
884 return typename __helper_type::type(std::forward<_Func>(__f),
885 std::forward<_BoundArgs>(__args)...);
888 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
889 struct _Bindres_helper
890 : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
892 typedef typename decay<_Func>::type __functor_type;
893 typedef _Bind_result<_Result,
894 __functor_type(
typename decay<_BoundArgs>::type...)>
903 template<
typename _Result,
typename _Func,
typename... _BoundArgs>
904 inline _GLIBCXX20_CONSTEXPR
905 typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
906 bind(_Func&& __f, _BoundArgs&&... __args)
908 typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
909 return typename __helper_type::type(std::forward<_Func>(__f),
910 std::forward<_BoundArgs>(__args)...);
913#if __cplusplus > 201703L
914#define __cpp_lib_bind_front 201907L
916 template<
typename _Fd,
typename... _BoundArgs>
919 static_assert(is_move_constructible_v<_Fd>);
920 static_assert((is_move_constructible_v<_BoundArgs> && ...));
924 template<
typename _Fn,
typename... _Args>
926 _Bind_front(
int, _Fn&& __fn, _Args&&... __args)
927 noexcept(__and_<is_nothrow_constructible<_Fd, _Fn>,
928 is_nothrow_constructible<_BoundArgs, _Args>...>::value)
929 : _M_fd(std::forward<_Fn>(__fn)),
930 _M_bound_args(std::forward<_Args>(__args)...)
931 {
static_assert(
sizeof...(_Args) ==
sizeof...(_BoundArgs)); }
933 _Bind_front(
const _Bind_front&) =
default;
934 _Bind_front(_Bind_front&&) =
default;
935 _Bind_front& operator=(
const _Bind_front&) =
default;
936 _Bind_front& operator=(_Bind_front&&) =
default;
937 ~_Bind_front() =
default;
939 template<
typename... _CallArgs>
942 operator()(_CallArgs&&... __call_args) &
943 noexcept(is_nothrow_invocable_v<_Fd&, _BoundArgs&..., _CallArgs...>)
945 return _S_call(*
this, _BoundIndices(),
946 std::forward<_CallArgs>(__call_args)...);
949 template<
typename... _CallArgs>
952 operator()(_CallArgs&&... __call_args)
const &
953 noexcept(is_nothrow_invocable_v<
const _Fd&,
const _BoundArgs&...,
956 return _S_call(*
this, _BoundIndices(),
957 std::forward<_CallArgs>(__call_args)...);
960 template<
typename... _CallArgs>
963 operator()(_CallArgs&&... __call_args) &&
964 noexcept(is_nothrow_invocable_v<_Fd, _BoundArgs..., _CallArgs...>)
966 return _S_call(
std::move(*
this), _BoundIndices(),
967 std::forward<_CallArgs>(__call_args)...);
970 template<
typename... _CallArgs>
973 operator()(_CallArgs&&... __call_args)
const &&
974 noexcept(is_nothrow_invocable_v<
const _Fd,
const _BoundArgs...,
977 return _S_call(
std::move(*
this), _BoundIndices(),
978 std::forward<_CallArgs>(__call_args)...);
984 template<
typename _Tp,
size_t... _Ind,
typename... _CallArgs>
987 _S_call(_Tp&& __g, index_sequence<_Ind...>, _CallArgs&&... __call_args)
990 std::get<_Ind>(std::forward<_Tp>(__g)._M_bound_args)...,
991 std::forward<_CallArgs>(__call_args)...);
994 [[no_unique_address]] _Fd _M_fd;
995 [[no_unique_address]]
std::tuple<_BoundArgs...> _M_bound_args;
999 template<
typename _Fd>
1002 static_assert(is_move_constructible_v<_Fd>);
1006 template<
typename _Fn>
1008 _Bind_front0(
int, _Fn&& __fn)
1009 noexcept(is_nothrow_constructible_v<_Fd, _Fn>)
1010 : _M_fd(std::forward<_Fn>(__fn))
1013 _Bind_front0(
const _Bind_front0&) =
default;
1014 _Bind_front0(_Bind_front0&&) =
default;
1015 _Bind_front0& operator=(
const _Bind_front0&) =
default;
1016 _Bind_front0& operator=(_Bind_front0&&) =
default;
1017 ~_Bind_front0() =
default;
1019 template<
typename... _CallArgs>
1022 operator()(_CallArgs&&... __call_args) &
1023 noexcept(is_nothrow_invocable_v<_Fd&, _CallArgs...>)
1024 {
return std::invoke(_M_fd, std::forward<_CallArgs>(__call_args)...); }
1026 template<
typename... _CallArgs>
1029 operator()(_CallArgs&&... __call_args)
const &
1030 noexcept(is_nothrow_invocable_v<
const _Fd&, _CallArgs...>)
1031 {
return std::invoke(_M_fd, std::forward<_CallArgs>(__call_args)...); }
1033 template<
typename... _CallArgs>
1036 operator()(_CallArgs&&... __call_args) &&
1037 noexcept(is_nothrow_invocable_v<_Fd, _CallArgs...>)
1040 std::forward<_CallArgs>(__call_args)...);
1043 template<
typename... _CallArgs>
1046 operator()(_CallArgs&&... __call_args)
const &&
1047 noexcept(is_nothrow_invocable_v<
const _Fd, _CallArgs...>)
1050 std::forward<_CallArgs>(__call_args)...);
1054 [[no_unique_address]] _Fd _M_fd;
1057 template<
typename _Fn,
typename... _Args>
1059 = __conditional_t<
sizeof...(_Args) == 0, _Bind_front0<decay_t<_Fn>>,
1060 _Bind_front<decay_t<_Fn>, decay_t<_Args>...>>;
1071 template<
typename _Fn,
typename... _Args>
1072 constexpr _Bind_front_t<_Fn, _Args...>
1074 noexcept(is_nothrow_constructible_v<_Bind_front_t<_Fn, _Args...>,
1075 int, _Fn, _Args...>)
1077 return _Bind_front_t<_Fn, _Args...>(0, std::forward<_Fn>(__fn),
1078 std::forward<_Args>(__args)...);
1082#if __cplusplus >= 201402L
1084 template<
typename _Fn>
1087 template<
typename _Fn2,
typename... _Args>
1088 using __inv_res_t =
typename __invoke_result<_Fn2, _Args...>::type;
1090 template<
typename _Tp>
1091 static decltype(!std::declval<_Tp>())
1092 _S_not()
noexcept(
noexcept(!std::declval<_Tp>()));
1095 template<
typename _Fn2>
1098 : _M_fn(std::forward<_Fn2>(__fn)) { }
1107#define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \
1108 template<typename... _Args> \
1109 _GLIBCXX20_CONSTEXPR \
1110 decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \
1111 operator()(_Args&&... __args) _QUALS \
1112 noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \
1113 && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \
1115 return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \
1116 std::forward<_Args>(__args)...); \
1118 _GLIBCXX_NOT_FN_CALL_OP( & )
1119 _GLIBCXX_NOT_FN_CALL_OP(
const & )
1120 _GLIBCXX_NOT_FN_CALL_OP( && )
1121 _GLIBCXX_NOT_FN_CALL_OP(
const && )
1122#undef _GLIBCXX_NOT_FN_CALL_OP
1128 template<
typename _Tp,
typename _Pred>
1131 template<
typename _Tp>
1132 struct __is_byte_like<_Tp, equal_to<_Tp>>
1133 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
1135 template<
typename _Tp>
1136 struct __is_byte_like<_Tp, equal_to<void>>
1137 : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
1139#if __cplusplus >= 201703L
1141 enum class byte :
unsigned char;
1144 struct __is_byte_like<
byte, equal_to<
byte>>
1148 struct __is_byte_like<
byte, equal_to<void>>
1152#define __cpp_lib_not_fn 201603L
1165 template<
typename _Fn>
1166 _GLIBCXX20_CONSTEXPR
1176 template<
typename _ForwardIterator1,
typename _BinaryPredicate = equal_to<>>
1177 class default_searcher
1180 _GLIBCXX20_CONSTEXPR
1181 default_searcher(_ForwardIterator1 __pat_first,
1182 _ForwardIterator1 __pat_last,
1183 _BinaryPredicate __pred = _BinaryPredicate())
1184 : _M_m(__pat_first, __pat_last,
std::
move(__pred))
1187 template<
typename _ForwardIterator2>
1188 _GLIBCXX20_CONSTEXPR
1189 pair<_ForwardIterator2, _ForwardIterator2>
1190 operator()(_ForwardIterator2 __first, _ForwardIterator2 __last)
const
1192 _ForwardIterator2 __first_ret =
1193 std::search(__first, __last, std::get<0>(_M_m), std::get<1>(_M_m),
1195 auto __ret = std::make_pair(__first_ret, __first_ret);
1196 if (__ret.first != __last)
1198 std::get<1>(_M_m)));
1203 tuple<_ForwardIterator1, _ForwardIterator1, _BinaryPredicate> _M_m;
1207#define __cpp_lib_boyer_moore_searcher 201603L
1209 template<
typename _Key,
typename _Tp,
typename _Hash,
typename _Pred>
1210 struct __boyer_moore_map_base
1212 template<
typename _RAIter>
1213 __boyer_moore_map_base(_RAIter __pat,
size_t __patlen,
1214 _Hash&& __hf, _Pred&& __pred)
1218 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1219 _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
1222 using __diff_type = _Tp;
1225 _M_lookup(_Key __key, __diff_type __not_found)
const
1227 auto __iter = _M_bad_char.find(__key);
1228 if (__iter == _M_bad_char.end())
1230 return __iter->second;
1234 _M_pred()
const {
return _M_bad_char.key_eq(); }
1236 _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
1239 template<
typename _Tp,
size_t _Len,
typename _Pred>
1240 struct __boyer_moore_array_base
1242 template<
typename _RAIter,
typename _Unused>
1243 __boyer_moore_array_base(_RAIter __pat,
size_t __patlen,
1244 _Unused&&, _Pred&& __pred)
1245 : _M_bad_char{ array<_Tp, _Len>{},
std::move(__pred) }
1247 std::get<0>(_M_bad_char).fill(__patlen);
1249 for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
1251 auto __ch = __pat[__i];
1253 auto __uch =
static_cast<_UCh
>(__ch);
1254 std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
1258 using __diff_type = _Tp;
1260 template<
typename _Key>
1262 _M_lookup(_Key __key, __diff_type __not_found)
const
1264 auto __ukey =
static_cast<make_unsigned_t<_Key>
>(__key);
1267 return std::get<0>(_M_bad_char)[__ukey];
1271 _M_pred()
const {
return std::get<1>(_M_bad_char); }
1273 tuple<array<_Tp, _Len>, _Pred> _M_bad_char;
1278 template<
typename _RAIter,
typename _Hash,
typename _Pred,
1279 typename _Val =
typename iterator_traits<_RAIter>::value_type,
1280 typename _Diff =
typename iterator_traits<_RAIter>::difference_type>
1281 using __boyer_moore_base_t
1282 = __conditional_t<__is_byte_like<_Val, _Pred>::value,
1283 __boyer_moore_array_base<_Diff, 256, _Pred>,
1284 __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
1286 template<
typename _RAIter,
typename _Hash
1287 = hash<typename iterator_traits<_RAIter>::value_type>,
1288 typename _BinaryPredicate = equal_to<>>
1289 class boyer_moore_searcher
1290 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1292 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1293 using typename _Base::__diff_type;
1296 boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
1297 _Hash __hf = _Hash(),
1298 _BinaryPredicate __pred = _BinaryPredicate());
1300 template<
typename _RandomAccessIterator2>
1301 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1302 operator()(_RandomAccessIterator2 __first,
1303 _RandomAccessIterator2 __last)
const;
1307 _M_is_prefix(_RAIter __word, __diff_type __len,
1310 const auto& __pred = this->_M_pred();
1311 __diff_type __suffixlen = __len - __pos;
1312 for (__diff_type __i = 0; __i < __suffixlen; ++__i)
1313 if (!__pred(__word[__i], __word[__pos + __i]))
1319 _M_suffix_length(_RAIter __word, __diff_type __len,
1322 const auto& __pred = this->_M_pred();
1323 __diff_type __i = 0;
1324 while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
1332 template<
typename _Tp>
1334 _M_bad_char_shift(_Tp __c)
const
1335 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1339 _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
1342 template<
typename _RAIter,
typename _Hash
1343 = hash<typename iterator_traits<_RAIter>::value_type>,
1344 typename _BinaryPredicate = equal_to<>>
1345 class boyer_moore_horspool_searcher
1346 : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
1348 using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
1349 using typename _Base::__diff_type;
1352 boyer_moore_horspool_searcher(_RAIter __pat,
1354 _Hash __hf = _Hash(),
1355 _BinaryPredicate __pred
1356 = _BinaryPredicate())
1357 : _Base(__pat, __pat_end - __pat,
std::move(__hf),
std::move(__pred)),
1358 _M_pat(__pat), _M_pat_end(__pat_end)
1361 template<
typename _RandomAccessIterator2>
1362 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1363 operator()(_RandomAccessIterator2 __first,
1364 _RandomAccessIterator2 __last)
const
1366 const auto& __pred = this->_M_pred();
1367 auto __patlen = _M_pat_end - _M_pat;
1369 return std::make_pair(__first, __first);
1370 auto __len = __last - __first;
1371 while (__len >= __patlen)
1373 for (
auto __scan = __patlen - 1;
1374 __pred(__first[__scan], _M_pat[__scan]); --__scan)
1376 return std::make_pair(__first, __first + __patlen);
1377 auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
1381 return std::make_pair(__last, __last);
1385 template<
typename _Tp>
1387 _M_bad_char_shift(_Tp __c)
const
1388 {
return this->_M_lookup(__c, _M_pat_end - _M_pat); }
1394 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1395 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1396 boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
1397 _Hash __hf, _BinaryPredicate __pred)
1398 : _Base(__pat, __pat_end - __pat,
std::move(__hf),
std::move(__pred)),
1399 _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
1401 auto __patlen = __pat_end - __pat;
1404 __diff_type __last_prefix = __patlen - 1;
1405 for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
1407 if (_M_is_prefix(__pat, __patlen, __p + 1))
1408 __last_prefix = __p + 1;
1409 _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
1411 for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
1413 auto __slen = _M_suffix_length(__pat, __patlen, __p);
1414 auto __pos = __patlen - 1 - __slen;
1415 if (!__pred(__pat[__p - __slen], __pat[__pos]))
1416 _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
1420 template<
typename _RAIter,
typename _Hash,
typename _BinaryPredicate>
1421 template<
typename _RandomAccessIterator2>
1422 pair<_RandomAccessIterator2, _RandomAccessIterator2>
1423 boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
1424 operator()(_RandomAccessIterator2 __first,
1425 _RandomAccessIterator2 __last)
const
1427 auto __patlen = _M_pat_end - _M_pat;
1429 return std::make_pair(__first, __first);
1430 const auto& __pred = this->_M_pred();
1431 __diff_type __i = __patlen - 1;
1432 auto __stringlen = __last - __first;
1433 while (__i < __stringlen)
1435 __diff_type __j = __patlen - 1;
1436 while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
1443 const auto __match = __first + __i + 1;
1444 return std::make_pair(__match, __match + __patlen);
1446 __i +=
std::max(_M_bad_char_shift(__first[__i]),
1447 _M_good_suffix[__j]);
1449 return std::make_pair(__last, __last);
1457_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.