functional 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. // <functional> -*- C++ -*-
  2. // Copyright (C) 2001-2018 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /*
  21. * Copyright (c) 1997
  22. * Silicon Graphics Computer Systems, Inc.
  23. *
  24. * Permission to use, copy, modify, distribute and sell this software
  25. * and its documentation for any purpose is hereby granted without fee,
  26. * provided that the above copyright notice appear in all copies and
  27. * that both that copyright notice and this permission notice appear
  28. * in supporting documentation. Silicon Graphics makes no
  29. * representations about the suitability of this software for any
  30. * purpose. It is provided "as is" without express or implied warranty.
  31. *
  32. */
  33. /** @file include/functional
  34. * This is a Standard C++ Library header.
  35. */
  36. #ifndef _GLIBCXX_FUNCTIONAL
  37. #define _GLIBCXX_FUNCTIONAL 1
  38. #pragma GCC system_header
  39. #include <bits/c++config.h>
  40. #include <bits/stl_function.h>
  41. #if __cplusplus >= 201103L
  42. #include <new>
  43. #include <tuple>
  44. #include <type_traits>
  45. #include <bits/functional_hash.h>
  46. #include <bits/invoke.h>
  47. #include <bits/refwrap.h> // std::reference_wrapper and _Mem_fn_traits
  48. #include <bits/std_function.h> // std::function
  49. #if __cplusplus > 201402L
  50. # include <unordered_map>
  51. # include <vector>
  52. # include <array>
  53. # include <utility>
  54. # include <bits/stl_algo.h>
  55. #endif
  56. namespace std _GLIBCXX_VISIBILITY(default)
  57. {
  58. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  59. #if __cplusplus > 201402L
  60. # define __cpp_lib_invoke 201411
  61. /// Invoke a callable object.
  62. template<typename _Callable, typename... _Args>
  63. inline invoke_result_t<_Callable, _Args...>
  64. invoke(_Callable&& __fn, _Args&&... __args)
  65. noexcept(is_nothrow_invocable_v<_Callable, _Args...>)
  66. {
  67. return std::__invoke(std::forward<_Callable>(__fn),
  68. std::forward<_Args>(__args)...);
  69. }
  70. #endif
  71. template<typename _MemFunPtr,
  72. bool __is_mem_fn = is_member_function_pointer<_MemFunPtr>::value>
  73. class _Mem_fn_base
  74. : public _Mem_fn_traits<_MemFunPtr>::__maybe_type
  75. {
  76. using _Traits = _Mem_fn_traits<_MemFunPtr>;
  77. using _Arity = typename _Traits::__arity;
  78. using _Varargs = typename _Traits::__vararg;
  79. template<typename _Func, typename... _BoundArgs>
  80. friend struct _Bind_check_arity;
  81. _MemFunPtr _M_pmf;
  82. public:
  83. using result_type = typename _Traits::__result_type;
  84. explicit constexpr
  85. _Mem_fn_base(_MemFunPtr __pmf) noexcept : _M_pmf(__pmf) { }
  86. template<typename... _Args>
  87. auto
  88. operator()(_Args&&... __args) const
  89. noexcept(noexcept(
  90. std::__invoke(_M_pmf, std::forward<_Args>(__args)...)))
  91. -> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
  92. { return std::__invoke(_M_pmf, std::forward<_Args>(__args)...); }
  93. };
  94. // Partial specialization for member object pointers.
  95. template<typename _MemObjPtr>
  96. class _Mem_fn_base<_MemObjPtr, false>
  97. {
  98. using _Arity = integral_constant<size_t, 0>;
  99. using _Varargs = false_type;
  100. template<typename _Func, typename... _BoundArgs>
  101. friend struct _Bind_check_arity;
  102. _MemObjPtr _M_pm;
  103. public:
  104. explicit constexpr
  105. _Mem_fn_base(_MemObjPtr __pm) noexcept : _M_pm(__pm) { }
  106. template<typename _Tp>
  107. auto
  108. operator()(_Tp&& __obj) const
  109. noexcept(noexcept(std::__invoke(_M_pm, std::forward<_Tp>(__obj))))
  110. -> decltype(std::__invoke(_M_pm, std::forward<_Tp>(__obj)))
  111. { return std::__invoke(_M_pm, std::forward<_Tp>(__obj)); }
  112. };
  113. template<typename _MemberPointer>
  114. struct _Mem_fn; // undefined
  115. template<typename _Res, typename _Class>
  116. struct _Mem_fn<_Res _Class::*>
  117. : _Mem_fn_base<_Res _Class::*>
  118. {
  119. using _Mem_fn_base<_Res _Class::*>::_Mem_fn_base;
  120. };
  121. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  122. // 2048. Unnecessary mem_fn overloads
  123. /**
  124. * @brief Returns a function object that forwards to the member
  125. * pointer @a pm.
  126. * @ingroup functors
  127. */
  128. template<typename _Tp, typename _Class>
  129. inline _Mem_fn<_Tp _Class::*>
  130. mem_fn(_Tp _Class::* __pm) noexcept
  131. {
  132. return _Mem_fn<_Tp _Class::*>(__pm);
  133. }
  134. /**
  135. * @brief Determines if the given type _Tp is a function object that
  136. * should be treated as a subexpression when evaluating calls to
  137. * function objects returned by bind().
  138. *
  139. * C++11 [func.bind.isbind].
  140. * @ingroup binders
  141. */
  142. template<typename _Tp>
  143. struct is_bind_expression
  144. : public false_type { };
  145. /**
  146. * @brief Determines if the given type _Tp is a placeholder in a
  147. * bind() expression and, if so, which placeholder it is.
  148. *
  149. * C++11 [func.bind.isplace].
  150. * @ingroup binders
  151. */
  152. template<typename _Tp>
  153. struct is_placeholder
  154. : public integral_constant<int, 0>
  155. { };
  156. #if __cplusplus > 201402L
  157. template <typename _Tp> inline constexpr bool is_bind_expression_v
  158. = is_bind_expression<_Tp>::value;
  159. template <typename _Tp> inline constexpr int is_placeholder_v
  160. = is_placeholder<_Tp>::value;
  161. #endif // C++17
  162. /** @brief The type of placeholder objects defined by libstdc++.
  163. * @ingroup binders
  164. */
  165. template<int _Num> struct _Placeholder { };
  166. /** @namespace std::placeholders
  167. * @brief ISO C++11 entities sub-namespace for functional.
  168. * @ingroup binders
  169. */
  170. namespace placeholders
  171. {
  172. /* Define a large number of placeholders. There is no way to
  173. * simplify this with variadic templates, because we're introducing
  174. * unique names for each.
  175. */
  176. extern const _Placeholder<1> _1;
  177. extern const _Placeholder<2> _2;
  178. extern const _Placeholder<3> _3;
  179. extern const _Placeholder<4> _4;
  180. extern const _Placeholder<5> _5;
  181. extern const _Placeholder<6> _6;
  182. extern const _Placeholder<7> _7;
  183. extern const _Placeholder<8> _8;
  184. extern const _Placeholder<9> _9;
  185. extern const _Placeholder<10> _10;
  186. extern const _Placeholder<11> _11;
  187. extern const _Placeholder<12> _12;
  188. extern const _Placeholder<13> _13;
  189. extern const _Placeholder<14> _14;
  190. extern const _Placeholder<15> _15;
  191. extern const _Placeholder<16> _16;
  192. extern const _Placeholder<17> _17;
  193. extern const _Placeholder<18> _18;
  194. extern const _Placeholder<19> _19;
  195. extern const _Placeholder<20> _20;
  196. extern const _Placeholder<21> _21;
  197. extern const _Placeholder<22> _22;
  198. extern const _Placeholder<23> _23;
  199. extern const _Placeholder<24> _24;
  200. extern const _Placeholder<25> _25;
  201. extern const _Placeholder<26> _26;
  202. extern const _Placeholder<27> _27;
  203. extern const _Placeholder<28> _28;
  204. extern const _Placeholder<29> _29;
  205. }
  206. /**
  207. * Partial specialization of is_placeholder that provides the placeholder
  208. * number for the placeholder objects defined by libstdc++.
  209. * @ingroup binders
  210. */
  211. template<int _Num>
  212. struct is_placeholder<_Placeholder<_Num> >
  213. : public integral_constant<int, _Num>
  214. { };
  215. template<int _Num>
  216. struct is_placeholder<const _Placeholder<_Num> >
  217. : public integral_constant<int, _Num>
  218. { };
  219. // Like tuple_element_t but SFINAE-friendly.
  220. template<std::size_t __i, typename _Tuple>
  221. using _Safe_tuple_element_t
  222. = typename enable_if<(__i < tuple_size<_Tuple>::value),
  223. tuple_element<__i, _Tuple>>::type::type;
  224. /**
  225. * Maps an argument to bind() into an actual argument to the bound
  226. * function object [func.bind.bind]/10. Only the first parameter should
  227. * be specified: the rest are used to determine among the various
  228. * implementations. Note that, although this class is a function
  229. * object, it isn't entirely normal because it takes only two
  230. * parameters regardless of the number of parameters passed to the
  231. * bind expression. The first parameter is the bound argument and
  232. * the second parameter is a tuple containing references to the
  233. * rest of the arguments.
  234. */
  235. template<typename _Arg,
  236. bool _IsBindExp = is_bind_expression<_Arg>::value,
  237. bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
  238. class _Mu;
  239. /**
  240. * If the argument is reference_wrapper<_Tp>, returns the
  241. * underlying reference.
  242. * C++11 [func.bind.bind] p10 bullet 1.
  243. */
  244. template<typename _Tp>
  245. class _Mu<reference_wrapper<_Tp>, false, false>
  246. {
  247. public:
  248. /* Note: This won't actually work for const volatile
  249. * reference_wrappers, because reference_wrapper::get() is const
  250. * but not volatile-qualified. This might be a defect in the TR.
  251. */
  252. template<typename _CVRef, typename _Tuple>
  253. _Tp&
  254. operator()(_CVRef& __arg, _Tuple&) const volatile
  255. { return __arg.get(); }
  256. };
  257. /**
  258. * If the argument is a bind expression, we invoke the underlying
  259. * function object with the same cv-qualifiers as we are given and
  260. * pass along all of our arguments (unwrapped).
  261. * C++11 [func.bind.bind] p10 bullet 2.
  262. */
  263. template<typename _Arg>
  264. class _Mu<_Arg, true, false>
  265. {
  266. public:
  267. template<typename _CVArg, typename... _Args>
  268. auto
  269. operator()(_CVArg& __arg,
  270. tuple<_Args...>& __tuple) const volatile
  271. -> decltype(__arg(declval<_Args>()...))
  272. {
  273. // Construct an index tuple and forward to __call
  274. typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
  275. _Indexes;
  276. return this->__call(__arg, __tuple, _Indexes());
  277. }
  278. private:
  279. // Invokes the underlying function object __arg by unpacking all
  280. // of the arguments in the tuple.
  281. template<typename _CVArg, typename... _Args, std::size_t... _Indexes>
  282. auto
  283. __call(_CVArg& __arg, tuple<_Args...>& __tuple,
  284. const _Index_tuple<_Indexes...>&) const volatile
  285. -> decltype(__arg(declval<_Args>()...))
  286. {
  287. return __arg(std::get<_Indexes>(std::move(__tuple))...);
  288. }
  289. };
  290. /**
  291. * If the argument is a placeholder for the Nth argument, returns
  292. * a reference to the Nth argument to the bind function object.
  293. * C++11 [func.bind.bind] p10 bullet 3.
  294. */
  295. template<typename _Arg>
  296. class _Mu<_Arg, false, true>
  297. {
  298. public:
  299. template<typename _Tuple>
  300. _Safe_tuple_element_t<(is_placeholder<_Arg>::value - 1), _Tuple>&&
  301. operator()(const volatile _Arg&, _Tuple& __tuple) const volatile
  302. {
  303. return
  304. ::std::get<(is_placeholder<_Arg>::value - 1)>(std::move(__tuple));
  305. }
  306. };
  307. /**
  308. * If the argument is just a value, returns a reference to that
  309. * value. The cv-qualifiers on the reference are determined by the caller.
  310. * C++11 [func.bind.bind] p10 bullet 4.
  311. */
  312. template<typename _Arg>
  313. class _Mu<_Arg, false, false>
  314. {
  315. public:
  316. template<typename _CVArg, typename _Tuple>
  317. _CVArg&&
  318. operator()(_CVArg&& __arg, _Tuple&) const volatile
  319. { return std::forward<_CVArg>(__arg); }
  320. };
  321. // std::get<I> for volatile-qualified tuples
  322. template<std::size_t _Ind, typename... _Tp>
  323. inline auto
  324. __volget(volatile tuple<_Tp...>& __tuple)
  325. -> __tuple_element_t<_Ind, tuple<_Tp...>> volatile&
  326. { return std::get<_Ind>(const_cast<tuple<_Tp...>&>(__tuple)); }
  327. // std::get<I> for const-volatile-qualified tuples
  328. template<std::size_t _Ind, typename... _Tp>
  329. inline auto
  330. __volget(const volatile tuple<_Tp...>& __tuple)
  331. -> __tuple_element_t<_Ind, tuple<_Tp...>> const volatile&
  332. { return std::get<_Ind>(const_cast<const tuple<_Tp...>&>(__tuple)); }
  333. /// Type of the function object returned from bind().
  334. template<typename _Signature>
  335. struct _Bind;
  336. template<typename _Functor, typename... _Bound_args>
  337. class _Bind<_Functor(_Bound_args...)>
  338. : public _Weak_result_type<_Functor>
  339. {
  340. typedef typename _Build_index_tuple<sizeof...(_Bound_args)>::__type
  341. _Bound_indexes;
  342. _Functor _M_f;
  343. tuple<_Bound_args...> _M_bound_args;
  344. // Call unqualified
  345. template<typename _Result, typename... _Args, std::size_t... _Indexes>
  346. _Result
  347. __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>)
  348. {
  349. return std::__invoke(_M_f,
  350. _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
  351. );
  352. }
  353. // Call as const
  354. template<typename _Result, typename... _Args, std::size_t... _Indexes>
  355. _Result
  356. __call_c(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) const
  357. {
  358. return std::__invoke(_M_f,
  359. _Mu<_Bound_args>()(std::get<_Indexes>(_M_bound_args), __args)...
  360. );
  361. }
  362. // Call as volatile
  363. template<typename _Result, typename... _Args, std::size_t... _Indexes>
  364. _Result
  365. __call_v(tuple<_Args...>&& __args,
  366. _Index_tuple<_Indexes...>) volatile
  367. {
  368. return std::__invoke(_M_f,
  369. _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
  370. );
  371. }
  372. // Call as const volatile
  373. template<typename _Result, typename... _Args, std::size_t... _Indexes>
  374. _Result
  375. __call_c_v(tuple<_Args...>&& __args,
  376. _Index_tuple<_Indexes...>) const volatile
  377. {
  378. return std::__invoke(_M_f,
  379. _Mu<_Bound_args>()(__volget<_Indexes>(_M_bound_args), __args)...
  380. );
  381. }
  382. template<typename _BoundArg, typename _CallArgs>
  383. using _Mu_type = decltype(
  384. _Mu<typename remove_cv<_BoundArg>::type>()(
  385. std::declval<_BoundArg&>(), std::declval<_CallArgs&>()) );
  386. template<typename _Fn, typename _CallArgs, typename... _BArgs>
  387. using _Res_type_impl
  388. = typename result_of< _Fn&(_Mu_type<_BArgs, _CallArgs>&&...) >::type;
  389. template<typename _CallArgs>
  390. using _Res_type = _Res_type_impl<_Functor, _CallArgs, _Bound_args...>;
  391. template<typename _CallArgs>
  392. using __dependent = typename
  393. enable_if<bool(tuple_size<_CallArgs>::value+1), _Functor>::type;
  394. template<typename _CallArgs, template<class> class __cv_quals>
  395. using _Res_type_cv = _Res_type_impl<
  396. typename __cv_quals<__dependent<_CallArgs>>::type,
  397. _CallArgs,
  398. typename __cv_quals<_Bound_args>::type...>;
  399. public:
  400. template<typename... _Args>
  401. explicit _Bind(const _Functor& __f, _Args&&... __args)
  402. : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
  403. { }
  404. template<typename... _Args>
  405. explicit _Bind(_Functor&& __f, _Args&&... __args)
  406. : _M_f(std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
  407. { }
  408. _Bind(const _Bind&) = default;
  409. _Bind(_Bind&& __b)
  410. : _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args))
  411. { }
  412. // Call unqualified
  413. template<typename... _Args,
  414. typename _Result = _Res_type<tuple<_Args...>>>
  415. _Result
  416. operator()(_Args&&... __args)
  417. {
  418. return this->__call<_Result>(
  419. std::forward_as_tuple(std::forward<_Args>(__args)...),
  420. _Bound_indexes());
  421. }
  422. // Call as const
  423. template<typename... _Args,
  424. typename _Result = _Res_type_cv<tuple<_Args...>, add_const>>
  425. _Result
  426. operator()(_Args&&... __args) const
  427. {
  428. return this->__call_c<_Result>(
  429. std::forward_as_tuple(std::forward<_Args>(__args)...),
  430. _Bound_indexes());
  431. }
  432. #if __cplusplus > 201402L
  433. # define _GLIBCXX_DEPR_BIND \
  434. [[deprecated("std::bind does not support volatile in C++17")]]
  435. #else
  436. # define _GLIBCXX_DEPR_BIND
  437. #endif
  438. // Call as volatile
  439. template<typename... _Args,
  440. typename _Result = _Res_type_cv<tuple<_Args...>, add_volatile>>
  441. _GLIBCXX_DEPR_BIND
  442. _Result
  443. operator()(_Args&&... __args) volatile
  444. {
  445. return this->__call_v<_Result>(
  446. std::forward_as_tuple(std::forward<_Args>(__args)...),
  447. _Bound_indexes());
  448. }
  449. // Call as const volatile
  450. template<typename... _Args,
  451. typename _Result = _Res_type_cv<tuple<_Args...>, add_cv>>
  452. _GLIBCXX_DEPR_BIND
  453. _Result
  454. operator()(_Args&&... __args) const volatile
  455. {
  456. return this->__call_c_v<_Result>(
  457. std::forward_as_tuple(std::forward<_Args>(__args)...),
  458. _Bound_indexes());
  459. }
  460. };
  461. /// Type of the function object returned from bind<R>().
  462. template<typename _Result, typename _Signature>
  463. struct _Bind_result;
  464. template<typename _Result, typename _Functor, typename... _Bound_args>
  465. class _Bind_result<_Result, _Functor(_Bound_args...)>
  466. {
  467. typedef typename _Build_index_tuple<sizeof...(_Bound_args)>::__type
  468. _Bound_indexes;
  469. _Functor _M_f;
  470. tuple<_Bound_args...> _M_bound_args;
  471. // sfinae types
  472. template<typename _Res>
  473. using __enable_if_void
  474. = typename enable_if<is_void<_Res>{}>::type;
  475. template<typename _Res>
  476. using __disable_if_void
  477. = typename enable_if<!is_void<_Res>{}, _Result>::type;
  478. // Call unqualified
  479. template<typename _Res, typename... _Args, std::size_t... _Indexes>
  480. __disable_if_void<_Res>
  481. __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>)
  482. {
  483. return std::__invoke(_M_f, _Mu<_Bound_args>()
  484. (std::get<_Indexes>(_M_bound_args), __args)...);
  485. }
  486. // Call unqualified, return void
  487. template<typename _Res, typename... _Args, std::size_t... _Indexes>
  488. __enable_if_void<_Res>
  489. __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>)
  490. {
  491. std::__invoke(_M_f, _Mu<_Bound_args>()
  492. (std::get<_Indexes>(_M_bound_args), __args)...);
  493. }
  494. // Call as const
  495. template<typename _Res, typename... _Args, std::size_t... _Indexes>
  496. __disable_if_void<_Res>
  497. __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) const
  498. {
  499. return std::__invoke(_M_f, _Mu<_Bound_args>()
  500. (std::get<_Indexes>(_M_bound_args), __args)...);
  501. }
  502. // Call as const, return void
  503. template<typename _Res, typename... _Args, std::size_t... _Indexes>
  504. __enable_if_void<_Res>
  505. __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) const
  506. {
  507. std::__invoke(_M_f, _Mu<_Bound_args>()
  508. (std::get<_Indexes>(_M_bound_args), __args)...);
  509. }
  510. // Call as volatile
  511. template<typename _Res, typename... _Args, std::size_t... _Indexes>
  512. __disable_if_void<_Res>
  513. __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) volatile
  514. {
  515. return std::__invoke(_M_f, _Mu<_Bound_args>()
  516. (__volget<_Indexes>(_M_bound_args), __args)...);
  517. }
  518. // Call as volatile, return void
  519. template<typename _Res, typename... _Args, std::size_t... _Indexes>
  520. __enable_if_void<_Res>
  521. __call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) volatile
  522. {
  523. std::__invoke(_M_f, _Mu<_Bound_args>()
  524. (__volget<_Indexes>(_M_bound_args), __args)...);
  525. }
  526. // Call as const volatile
  527. template<typename _Res, typename... _Args, std::size_t... _Indexes>
  528. __disable_if_void<_Res>
  529. __call(tuple<_Args...>&& __args,
  530. _Index_tuple<_Indexes...>) const volatile
  531. {
  532. return std::__invoke(_M_f, _Mu<_Bound_args>()
  533. (__volget<_Indexes>(_M_bound_args), __args)...);
  534. }
  535. // Call as const volatile, return void
  536. template<typename _Res, typename... _Args, std::size_t... _Indexes>
  537. __enable_if_void<_Res>
  538. __call(tuple<_Args...>&& __args,
  539. _Index_tuple<_Indexes...>) const volatile
  540. {
  541. std::__invoke(_M_f, _Mu<_Bound_args>()
  542. (__volget<_Indexes>(_M_bound_args), __args)...);
  543. }
  544. public:
  545. typedef _Result result_type;
  546. template<typename... _Args>
  547. explicit _Bind_result(const _Functor& __f, _Args&&... __args)
  548. : _M_f(__f), _M_bound_args(std::forward<_Args>(__args)...)
  549. { }
  550. template<typename... _Args>
  551. explicit _Bind_result(_Functor&& __f, _Args&&... __args)
  552. : _M_f(std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
  553. { }
  554. _Bind_result(const _Bind_result&) = default;
  555. _Bind_result(_Bind_result&& __b)
  556. : _M_f(std::move(__b._M_f)), _M_bound_args(std::move(__b._M_bound_args))
  557. { }
  558. // Call unqualified
  559. template<typename... _Args>
  560. result_type
  561. operator()(_Args&&... __args)
  562. {
  563. return this->__call<_Result>(
  564. std::forward_as_tuple(std::forward<_Args>(__args)...),
  565. _Bound_indexes());
  566. }
  567. // Call as const
  568. template<typename... _Args>
  569. result_type
  570. operator()(_Args&&... __args) const
  571. {
  572. return this->__call<_Result>(
  573. std::forward_as_tuple(std::forward<_Args>(__args)...),
  574. _Bound_indexes());
  575. }
  576. // Call as volatile
  577. template<typename... _Args>
  578. _GLIBCXX_DEPR_BIND
  579. result_type
  580. operator()(_Args&&... __args) volatile
  581. {
  582. return this->__call<_Result>(
  583. std::forward_as_tuple(std::forward<_Args>(__args)...),
  584. _Bound_indexes());
  585. }
  586. // Call as const volatile
  587. template<typename... _Args>
  588. _GLIBCXX_DEPR_BIND
  589. result_type
  590. operator()(_Args&&... __args) const volatile
  591. {
  592. return this->__call<_Result>(
  593. std::forward_as_tuple(std::forward<_Args>(__args)...),
  594. _Bound_indexes());
  595. }
  596. };
  597. #undef _GLIBCXX_DEPR_BIND
  598. /**
  599. * @brief Class template _Bind is always a bind expression.
  600. * @ingroup binders
  601. */
  602. template<typename _Signature>
  603. struct is_bind_expression<_Bind<_Signature> >
  604. : public true_type { };
  605. /**
  606. * @brief Class template _Bind is always a bind expression.
  607. * @ingroup binders
  608. */
  609. template<typename _Signature>
  610. struct is_bind_expression<const _Bind<_Signature> >
  611. : public true_type { };
  612. /**
  613. * @brief Class template _Bind is always a bind expression.
  614. * @ingroup binders
  615. */
  616. template<typename _Signature>
  617. struct is_bind_expression<volatile _Bind<_Signature> >
  618. : public true_type { };
  619. /**
  620. * @brief Class template _Bind is always a bind expression.
  621. * @ingroup binders
  622. */
  623. template<typename _Signature>
  624. struct is_bind_expression<const volatile _Bind<_Signature>>
  625. : public true_type { };
  626. /**
  627. * @brief Class template _Bind_result is always a bind expression.
  628. * @ingroup binders
  629. */
  630. template<typename _Result, typename _Signature>
  631. struct is_bind_expression<_Bind_result<_Result, _Signature>>
  632. : public true_type { };
  633. /**
  634. * @brief Class template _Bind_result is always a bind expression.
  635. * @ingroup binders
  636. */
  637. template<typename _Result, typename _Signature>
  638. struct is_bind_expression<const _Bind_result<_Result, _Signature>>
  639. : public true_type { };
  640. /**
  641. * @brief Class template _Bind_result is always a bind expression.
  642. * @ingroup binders
  643. */
  644. template<typename _Result, typename _Signature>
  645. struct is_bind_expression<volatile _Bind_result<_Result, _Signature>>
  646. : public true_type { };
  647. /**
  648. * @brief Class template _Bind_result is always a bind expression.
  649. * @ingroup binders
  650. */
  651. template<typename _Result, typename _Signature>
  652. struct is_bind_expression<const volatile _Bind_result<_Result, _Signature>>
  653. : public true_type { };
  654. template<typename _Func, typename... _BoundArgs>
  655. struct _Bind_check_arity { };
  656. template<typename _Ret, typename... _Args, typename... _BoundArgs>
  657. struct _Bind_check_arity<_Ret (*)(_Args...), _BoundArgs...>
  658. {
  659. static_assert(sizeof...(_BoundArgs) == sizeof...(_Args),
  660. "Wrong number of arguments for function");
  661. };
  662. template<typename _Ret, typename... _Args, typename... _BoundArgs>
  663. struct _Bind_check_arity<_Ret (*)(_Args......), _BoundArgs...>
  664. {
  665. static_assert(sizeof...(_BoundArgs) >= sizeof...(_Args),
  666. "Wrong number of arguments for function");
  667. };
  668. template<typename _Tp, typename _Class, typename... _BoundArgs>
  669. struct _Bind_check_arity<_Tp _Class::*, _BoundArgs...>
  670. {
  671. using _Arity = typename _Mem_fn<_Tp _Class::*>::_Arity;
  672. using _Varargs = typename _Mem_fn<_Tp _Class::*>::_Varargs;
  673. static_assert(_Varargs::value
  674. ? sizeof...(_BoundArgs) >= _Arity::value + 1
  675. : sizeof...(_BoundArgs) == _Arity::value + 1,
  676. "Wrong number of arguments for pointer-to-member");
  677. };
  678. // Trait type used to remove std::bind() from overload set via SFINAE
  679. // when first argument has integer type, so that std::bind() will
  680. // not be a better match than ::bind() from the BSD Sockets API.
  681. template<typename _Tp, typename _Tp2 = typename decay<_Tp>::type>
  682. using __is_socketlike = __or_<is_integral<_Tp2>, is_enum<_Tp2>>;
  683. template<bool _SocketLike, typename _Func, typename... _BoundArgs>
  684. struct _Bind_helper
  685. : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
  686. {
  687. typedef typename decay<_Func>::type __func_type;
  688. typedef _Bind<__func_type(typename decay<_BoundArgs>::type...)> type;
  689. };
  690. // Partial specialization for is_socketlike == true, does not define
  691. // nested type so std::bind() will not participate in overload resolution
  692. // when the first argument might be a socket file descriptor.
  693. template<typename _Func, typename... _BoundArgs>
  694. struct _Bind_helper<true, _Func, _BoundArgs...>
  695. { };
  696. /**
  697. * @brief Function template for std::bind.
  698. * @ingroup binders
  699. */
  700. template<typename _Func, typename... _BoundArgs>
  701. inline typename
  702. _Bind_helper<__is_socketlike<_Func>::value, _Func, _BoundArgs...>::type
  703. bind(_Func&& __f, _BoundArgs&&... __args)
  704. {
  705. typedef _Bind_helper<false, _Func, _BoundArgs...> __helper_type;
  706. return typename __helper_type::type(std::forward<_Func>(__f),
  707. std::forward<_BoundArgs>(__args)...);
  708. }
  709. template<typename _Result, typename _Func, typename... _BoundArgs>
  710. struct _Bindres_helper
  711. : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
  712. {
  713. typedef typename decay<_Func>::type __functor_type;
  714. typedef _Bind_result<_Result,
  715. __functor_type(typename decay<_BoundArgs>::type...)>
  716. type;
  717. };
  718. /**
  719. * @brief Function template for std::bind<R>.
  720. * @ingroup binders
  721. */
  722. template<typename _Result, typename _Func, typename... _BoundArgs>
  723. inline
  724. typename _Bindres_helper<_Result, _Func, _BoundArgs...>::type
  725. bind(_Func&& __f, _BoundArgs&&... __args)
  726. {
  727. typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
  728. return typename __helper_type::type(std::forward<_Func>(__f),
  729. std::forward<_BoundArgs>(__args)...);
  730. }
  731. #if __cplusplus >= 201402L
  732. /// Generalized negator.
  733. template<typename _Fn>
  734. class _Not_fn
  735. {
  736. template<typename _Fn2, typename... _Args>
  737. using __inv_res_t = typename __invoke_result<_Fn2, _Args...>::type;
  738. template<typename _Tp>
  739. static decltype(!std::declval<_Tp>())
  740. _S_not() noexcept(noexcept(!std::declval<_Tp>()));
  741. public:
  742. template<typename _Fn2>
  743. _Not_fn(_Fn2&& __fn, int)
  744. : _M_fn(std::forward<_Fn2>(__fn)) { }
  745. _Not_fn(const _Not_fn& __fn) = default;
  746. _Not_fn(_Not_fn&& __fn) = default;
  747. ~_Not_fn() = default;
  748. // Macro to define operator() with given cv-qualifiers ref-qualifiers,
  749. // forwarding _M_fn and the function arguments with the same qualifiers,
  750. // and deducing the return type and exception-specification.
  751. #define _GLIBCXX_NOT_FN_CALL_OP( _QUALS ) \
  752. template<typename... _Args> \
  753. decltype(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>()) \
  754. operator()(_Args&&... __args) _QUALS \
  755. noexcept(__is_nothrow_invocable<_Fn _QUALS, _Args...>::value \
  756. && noexcept(_S_not<__inv_res_t<_Fn _QUALS, _Args...>>())) \
  757. { \
  758. return !std::__invoke(std::forward< _Fn _QUALS >(_M_fn), \
  759. std::forward<_Args>(__args)...); \
  760. }
  761. _GLIBCXX_NOT_FN_CALL_OP( & )
  762. _GLIBCXX_NOT_FN_CALL_OP( const & )
  763. _GLIBCXX_NOT_FN_CALL_OP( && )
  764. _GLIBCXX_NOT_FN_CALL_OP( const && )
  765. #undef _GLIBCXX_NOT_FN_CALL
  766. private:
  767. _Fn _M_fn;
  768. };
  769. template<typename _Tp, typename _Pred>
  770. struct __is_byte_like : false_type { };
  771. template<typename _Tp>
  772. struct __is_byte_like<_Tp, equal_to<_Tp>>
  773. : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
  774. template<typename _Tp>
  775. struct __is_byte_like<_Tp, equal_to<void>>
  776. : __bool_constant<sizeof(_Tp) == 1 && is_integral<_Tp>::value> { };
  777. #if __cplusplus >= 201703L
  778. // Declare std::byte (full definition is in <cstddef>).
  779. enum class byte : unsigned char;
  780. template<>
  781. struct __is_byte_like<byte, equal_to<byte>>
  782. : true_type { };
  783. template<>
  784. struct __is_byte_like<byte, equal_to<void>>
  785. : true_type { };
  786. #define __cpp_lib_not_fn 201603
  787. /// [func.not_fn] Function template not_fn
  788. template<typename _Fn>
  789. inline auto
  790. not_fn(_Fn&& __fn)
  791. noexcept(std::is_nothrow_constructible<std::decay_t<_Fn>, _Fn&&>::value)
  792. {
  793. return _Not_fn<std::decay_t<_Fn>>{std::forward<_Fn>(__fn), 0};
  794. }
  795. // Searchers
  796. #define __cpp_lib_boyer_moore_searcher 201603
  797. template<typename _ForwardIterator1, typename _BinaryPredicate = equal_to<>>
  798. class default_searcher
  799. {
  800. public:
  801. default_searcher(_ForwardIterator1 __pat_first,
  802. _ForwardIterator1 __pat_last,
  803. _BinaryPredicate __pred = _BinaryPredicate())
  804. : _M_m(__pat_first, __pat_last, std::move(__pred))
  805. { }
  806. template<typename _ForwardIterator2>
  807. pair<_ForwardIterator2, _ForwardIterator2>
  808. operator()(_ForwardIterator2 __first, _ForwardIterator2 __last) const
  809. {
  810. _ForwardIterator2 __first_ret =
  811. std::search(__first, __last, std::get<0>(_M_m), std::get<1>(_M_m),
  812. std::get<2>(_M_m));
  813. auto __ret = std::make_pair(__first_ret, __first_ret);
  814. if (__ret.first != __last)
  815. std::advance(__ret.second, std::distance(std::get<0>(_M_m),
  816. std::get<1>(_M_m)));
  817. return __ret;
  818. }
  819. private:
  820. tuple<_ForwardIterator1, _ForwardIterator1, _BinaryPredicate> _M_m;
  821. };
  822. template<typename _Key, typename _Tp, typename _Hash, typename _Pred>
  823. struct __boyer_moore_map_base
  824. {
  825. template<typename _RAIter>
  826. __boyer_moore_map_base(_RAIter __pat, size_t __patlen,
  827. _Hash&& __hf, _Pred&& __pred)
  828. : _M_bad_char{ __patlen, std::move(__hf), std::move(__pred) }
  829. {
  830. if (__patlen > 0)
  831. for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
  832. _M_bad_char[__pat[__i]] = __patlen - 1 - __i;
  833. }
  834. using __diff_type = _Tp;
  835. __diff_type
  836. _M_lookup(_Key __key, __diff_type __not_found) const
  837. {
  838. auto __iter = _M_bad_char.find(__key);
  839. if (__iter == _M_bad_char.end())
  840. return __not_found;
  841. return __iter->second;
  842. }
  843. _Pred
  844. _M_pred() const { return _M_bad_char.key_eq(); }
  845. _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _Pred> _M_bad_char;
  846. };
  847. template<typename _Tp, size_t _Len, typename _Pred>
  848. struct __boyer_moore_array_base
  849. {
  850. template<typename _RAIter, typename _Unused>
  851. __boyer_moore_array_base(_RAIter __pat, size_t __patlen,
  852. _Unused&&, _Pred&& __pred)
  853. : _M_bad_char{ _GLIBCXX_STD_C::array<_Tp, _Len>{}, std::move(__pred) }
  854. {
  855. std::get<0>(_M_bad_char).fill(__patlen);
  856. if (__patlen > 0)
  857. for (__diff_type __i = 0; __i < __patlen - 1; ++__i)
  858. {
  859. auto __ch = __pat[__i];
  860. using _UCh = make_unsigned_t<decltype(__ch)>;
  861. auto __uch = static_cast<_UCh>(__ch);
  862. std::get<0>(_M_bad_char)[__uch] = __patlen - 1 - __i;
  863. }
  864. }
  865. using __diff_type = _Tp;
  866. template<typename _Key>
  867. __diff_type
  868. _M_lookup(_Key __key, __diff_type __not_found) const
  869. {
  870. auto __ukey = static_cast<make_unsigned_t<_Key>>(__key);
  871. if (__ukey >= _Len)
  872. return __not_found;
  873. return std::get<0>(_M_bad_char)[__ukey];
  874. }
  875. const _Pred&
  876. _M_pred() const { return std::get<1>(_M_bad_char); }
  877. tuple<_GLIBCXX_STD_C::array<_Tp, _Len>, _Pred> _M_bad_char;
  878. };
  879. // Use __boyer_moore_array_base when pattern consists of narrow characters
  880. // (or std::byte) and uses std::equal_to as the predicate.
  881. template<typename _RAIter, typename _Hash, typename _Pred,
  882. typename _Val = typename iterator_traits<_RAIter>::value_type,
  883. typename _Diff = typename iterator_traits<_RAIter>::difference_type>
  884. using __boyer_moore_base_t
  885. = conditional_t<__is_byte_like<_Val, _Pred>::value,
  886. __boyer_moore_array_base<_Diff, 256, _Pred>,
  887. __boyer_moore_map_base<_Val, _Diff, _Hash, _Pred>>;
  888. template<typename _RAIter, typename _Hash
  889. = hash<typename iterator_traits<_RAIter>::value_type>,
  890. typename _BinaryPredicate = equal_to<>>
  891. class boyer_moore_searcher
  892. : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
  893. {
  894. using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
  895. using typename _Base::__diff_type;
  896. public:
  897. boyer_moore_searcher(_RAIter __pat_first, _RAIter __pat_last,
  898. _Hash __hf = _Hash(),
  899. _BinaryPredicate __pred = _BinaryPredicate());
  900. template<typename _RandomAccessIterator2>
  901. pair<_RandomAccessIterator2, _RandomAccessIterator2>
  902. operator()(_RandomAccessIterator2 __first,
  903. _RandomAccessIterator2 __last) const;
  904. private:
  905. bool
  906. _M_is_prefix(_RAIter __word, __diff_type __len,
  907. __diff_type __pos)
  908. {
  909. const auto& __pred = this->_M_pred();
  910. __diff_type __suffixlen = __len - __pos;
  911. for (__diff_type __i = 0; __i < __suffixlen; ++__i)
  912. if (!__pred(__word[__i], __word[__pos + __i]))
  913. return false;
  914. return true;
  915. }
  916. __diff_type
  917. _M_suffix_length(_RAIter __word, __diff_type __len,
  918. __diff_type __pos)
  919. {
  920. const auto& __pred = this->_M_pred();
  921. __diff_type __i = 0;
  922. while (__pred(__word[__pos - __i], __word[__len - 1 - __i])
  923. && __i < __pos)
  924. {
  925. ++__i;
  926. }
  927. return __i;
  928. }
  929. template<typename _Tp>
  930. __diff_type
  931. _M_bad_char_shift(_Tp __c) const
  932. { return this->_M_lookup(__c, _M_pat_end - _M_pat); }
  933. _RAIter _M_pat;
  934. _RAIter _M_pat_end;
  935. _GLIBCXX_STD_C::vector<__diff_type> _M_good_suffix;
  936. };
  937. template<typename _RAIter, typename _Hash
  938. = hash<typename iterator_traits<_RAIter>::value_type>,
  939. typename _BinaryPredicate = equal_to<>>
  940. class boyer_moore_horspool_searcher
  941. : __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>
  942. {
  943. using _Base = __boyer_moore_base_t<_RAIter, _Hash, _BinaryPredicate>;
  944. using typename _Base::__diff_type;
  945. public:
  946. boyer_moore_horspool_searcher(_RAIter __pat,
  947. _RAIter __pat_end,
  948. _Hash __hf = _Hash(),
  949. _BinaryPredicate __pred
  950. = _BinaryPredicate())
  951. : _Base(__pat, __pat_end - __pat, std::move(__hf), std::move(__pred)),
  952. _M_pat(__pat), _M_pat_end(__pat_end)
  953. { }
  954. template<typename _RandomAccessIterator2>
  955. pair<_RandomAccessIterator2, _RandomAccessIterator2>
  956. operator()(_RandomAccessIterator2 __first,
  957. _RandomAccessIterator2 __last) const
  958. {
  959. const auto& __pred = this->_M_pred();
  960. auto __patlen = _M_pat_end - _M_pat;
  961. if (__patlen == 0)
  962. return std::make_pair(__first, __first);
  963. auto __len = __last - __first;
  964. while (__len >= __patlen)
  965. {
  966. for (auto __scan = __patlen - 1;
  967. __pred(__first[__scan], _M_pat[__scan]); --__scan)
  968. if (__scan == 0)
  969. return std::make_pair(__first, __first + __patlen);
  970. auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
  971. __len -= __shift;
  972. __first += __shift;
  973. }
  974. return std::make_pair(__last, __last);
  975. }
  976. private:
  977. template<typename _Tp>
  978. __diff_type
  979. _M_bad_char_shift(_Tp __c) const
  980. { return this->_M_lookup(__c, _M_pat_end - _M_pat); }
  981. _RAIter _M_pat;
  982. _RAIter _M_pat_end;
  983. };
  984. template<typename _RAIter, typename _Hash, typename _BinaryPredicate>
  985. boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
  986. boyer_moore_searcher(_RAIter __pat, _RAIter __pat_end,
  987. _Hash __hf, _BinaryPredicate __pred)
  988. : _Base(__pat, __pat_end - __pat, std::move(__hf), std::move(__pred)),
  989. _M_pat(__pat), _M_pat_end(__pat_end), _M_good_suffix(__pat_end - __pat)
  990. {
  991. auto __patlen = __pat_end - __pat;
  992. if (__patlen == 0)
  993. return;
  994. __diff_type __last_prefix = __patlen - 1;
  995. for (__diff_type __p = __patlen - 1; __p >= 0; --__p)
  996. {
  997. if (_M_is_prefix(__pat, __patlen, __p + 1))
  998. __last_prefix = __p + 1;
  999. _M_good_suffix[__p] = __last_prefix + (__patlen - 1 - __p);
  1000. }
  1001. for (__diff_type __p = 0; __p < __patlen - 1; ++__p)
  1002. {
  1003. auto __slen = _M_suffix_length(__pat, __patlen, __p);
  1004. auto __pos = __patlen - 1 - __slen;
  1005. if (!__pred(__pat[__p - __slen], __pat[__pos]))
  1006. _M_good_suffix[__pos] = __patlen - 1 - __p + __slen;
  1007. }
  1008. }
  1009. template<typename _RAIter, typename _Hash, typename _BinaryPredicate>
  1010. template<typename _RandomAccessIterator2>
  1011. pair<_RandomAccessIterator2, _RandomAccessIterator2>
  1012. boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
  1013. operator()(_RandomAccessIterator2 __first,
  1014. _RandomAccessIterator2 __last) const
  1015. {
  1016. auto __patlen = _M_pat_end - _M_pat;
  1017. if (__patlen == 0)
  1018. return std::make_pair(__first, __first);
  1019. const auto& __pred = this->_M_pred();
  1020. __diff_type __i = __patlen - 1;
  1021. auto __stringlen = __last - __first;
  1022. while (__i < __stringlen)
  1023. {
  1024. __diff_type __j = __patlen - 1;
  1025. while (__j >= 0 && __pred(__first[__i], _M_pat[__j]))
  1026. {
  1027. --__i;
  1028. --__j;
  1029. }
  1030. if (__j < 0)
  1031. {
  1032. const auto __match = __first + __i + 1;
  1033. return std::make_pair(__match, __match + __patlen);
  1034. }
  1035. __i += std::max(_M_bad_char_shift(__first[__i]),
  1036. _M_good_suffix[__j]);
  1037. }
  1038. return std::make_pair(__last, __last);
  1039. }
  1040. #endif // C++17
  1041. #endif // C++14
  1042. _GLIBCXX_END_NAMESPACE_VERSION
  1043. } // namespace std
  1044. #endif // C++11
  1045. #endif // _GLIBCXX_FUNCTIONAL