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