1// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_FUNCTIONAL
11#define _LIBCPP_FUNCTIONAL
12
13/*
14    functional synopsis
15
16namespace std
17{
18
19template <class Arg, class Result>
20struct unary_function
21{
22    typedef Arg    argument_type;
23    typedef Result result_type;
24};
25
26template <class Arg1, class Arg2, class Result>
27struct binary_function
28{
29    typedef Arg1   first_argument_type;
30    typedef Arg2   second_argument_type;
31    typedef Result result_type;
32};
33
34template <class T>
35class reference_wrapper
36    : public unary_function<T1, R> // if wrapping a unary functor
37    : public binary_function<T1, T2, R> // if wraping a binary functor
38{
39public:
40    // types
41    typedef T type;
42    typedef see below result_type; // Not always defined
43
44    // construct/copy/destroy
45    template<class U>
46      reference_wrapper(U&&);
47    reference_wrapper(const reference_wrapper<T>& x) noexcept;
48
49    // assignment
50    reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
51
52    // access
53    operator T& () const noexcept;
54    T& get() const noexcept;
55
56    // invoke
57    template <class... ArgTypes>
58      typename result_of<T&(ArgTypes&&...)>::type
59          operator() (ArgTypes&&...) const;
60};
61
62template <class T>
63  reference_wrapper(T&) -> reference_wrapper<T>;
64
65template <class T> reference_wrapper<T> ref(T& t) noexcept;
66template <class T> void ref(const T&& t) = delete;
67template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
68
69template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
70template <class T> void cref(const T&& t) = delete;
71template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
72
73template <class T> struct unwrap_reference;                                       // since C++20
74template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { };    // since C++20
75template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
76template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
77
78template <class T> // <class T=void> in C++14
79struct plus {
80    T operator()(const T& x, const T& y) const;
81};
82
83template <class T> // <class T=void> in C++14
84struct minus {
85    T operator()(const T& x, const T& y) const;
86};
87
88template <class T> // <class T=void> in C++14
89struct multiplies {
90    T operator()(const T& x, const T& y) const;
91};
92
93template <class T> // <class T=void> in C++14
94struct divides {
95    T operator()(const T& x, const T& y) const;
96};
97
98template <class T> // <class T=void> in C++14
99struct modulus {
100    T operator()(const T& x, const T& y) const;
101};
102
103template <class T> // <class T=void> in C++14
104struct negate {
105    T operator()(const T& x) const;
106};
107
108template <class T> // <class T=void> in C++14
109struct equal_to {
110    bool operator()(const T& x, const T& y) const;
111};
112
113template <class T> // <class T=void> in C++14
114struct not_equal_to {
115    bool operator()(const T& x, const T& y) const;
116};
117
118template <class T> // <class T=void> in C++14
119struct greater {
120    bool operator()(const T& x, const T& y) const;
121};
122
123template <class T> // <class T=void> in C++14
124struct less {
125    bool operator()(const T& x, const T& y) const;
126};
127
128template <class T> // <class T=void> in C++14
129struct greater_equal {
130    bool operator()(const T& x, const T& y) const;
131};
132
133template <class T> // <class T=void> in C++14
134struct less_equal {
135    bool operator()(const T& x, const T& y) const;
136};
137
138template <class T> // <class T=void> in C++14
139struct logical_and {
140    bool operator()(const T& x, const T& y) const;
141};
142
143template <class T> // <class T=void> in C++14
144struct logical_or {
145    bool operator()(const T& x, const T& y) const;
146};
147
148template <class T> // <class T=void> in C++14
149struct logical_not {
150    bool operator()(const T& x) const;
151};
152
153template <class T> // <class T=void> in C++14
154struct bit_and {
155    T operator()(const T& x, const T& y) const;
156};
157
158template <class T> // <class T=void> in C++14
159struct bit_or {
160    T operator()(const T& x, const T& y) const;
161};
162
163template <class T> // <class T=void> in C++14
164struct bit_xor {
165    T operator()(const T& x, const T& y) const;
166};
167
168template <class T=void> // C++14
169struct bit_not {
170    T operator()(const T& x) const;
171};
172
173struct identity; // C++20
174
175template <class Predicate>
176class unary_negate // deprecated in C++17, removed in C++20
177    : public unary_function<typename Predicate::argument_type, bool>
178{
179public:
180    explicit unary_negate(const Predicate& pred);
181    bool operator()(const typename Predicate::argument_type& x) const;
182};
183
184template <class Predicate> // deprecated in C++17, removed in C++20
185unary_negate<Predicate> not1(const Predicate& pred);
186
187template <class Predicate>
188class binary_negate // deprecated in C++17, removed in C++20
189    : public binary_function<typename Predicate::first_argument_type,
190                             typename Predicate::second_argument_type,
191                             bool>
192{
193public:
194    explicit binary_negate(const Predicate& pred);
195    bool operator()(const typename Predicate::first_argument_type& x,
196                    const typename Predicate::second_argument_type& y) const;
197};
198
199template <class Predicate> // deprecated in C++17, removed in C++20
200binary_negate<Predicate> not2(const Predicate& pred);
201
202template <class F>
203constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
204
205template<class T> struct is_bind_expression;
206template<class T> struct is_placeholder;
207
208    // See C++14 20.9.9, Function object binders
209template <class T> inline constexpr bool is_bind_expression_v
210  = is_bind_expression<T>::value; // C++17
211template <class T> inline constexpr int is_placeholder_v
212  = is_placeholder<T>::value; // C++17
213
214
215template<class Fn, class... BoundArgs>
216  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
217template<class R, class Fn, class... BoundArgs>
218  constexpr unspecified bind(Fn&&, BoundArgs&&...);  // constexpr in C++20
219
220template<class F, class... Args>
221 constexpr // constexpr in C++20
222 invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
223    noexcept(is_nothrow_invocable_v<F, Args...>);
224
225namespace placeholders {
226  // M is the implementation-defined number of placeholders
227  extern unspecified _1;
228  extern unspecified _2;
229  .
230  .
231  .
232  extern unspecified _Mp;
233}
234
235template <class Operation>
236class binder1st     // deprecated in C++11, removed in C++17
237    : public unary_function<typename Operation::second_argument_type,
238                            typename Operation::result_type>
239{
240protected:
241    Operation                               op;
242    typename Operation::first_argument_type value;
243public:
244    binder1st(const Operation& x, const typename Operation::first_argument_type y);
245    typename Operation::result_type operator()(      typename Operation::second_argument_type& x) const;
246    typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
247};
248
249template <class Operation, class T>
250binder1st<Operation> bind1st(const Operation& op, const T& x);  // deprecated in C++11, removed in C++17
251
252template <class Operation>
253class binder2nd     // deprecated in C++11, removed in C++17
254    : public unary_function<typename Operation::first_argument_type,
255                            typename Operation::result_type>
256{
257protected:
258    Operation                                op;
259    typename Operation::second_argument_type value;
260public:
261    binder2nd(const Operation& x, const typename Operation::second_argument_type y);
262    typename Operation::result_type operator()(      typename Operation::first_argument_type& x) const;
263    typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
264};
265
266template <class Operation, class T>
267binder2nd<Operation> bind2nd(const Operation& op, const T& x);  // deprecated in C++11, removed in C++17
268
269template <class Arg, class Result>      // deprecated in C++11, removed in C++17
270class pointer_to_unary_function : public unary_function<Arg, Result>
271{
272public:
273    explicit pointer_to_unary_function(Result (*f)(Arg));
274    Result operator()(Arg x) const;
275};
276
277template <class Arg, class Result>
278pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));      // deprecated in C++11, removed in C++17
279
280template <class Arg1, class Arg2, class Result>      // deprecated in C++11, removed in C++17
281class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
282{
283public:
284    explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
285    Result operator()(Arg1 x, Arg2 y) const;
286};
287
288template <class Arg1, class Arg2, class Result>
289pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));      // deprecated in C++11, removed in C++17
290
291template<class S, class T>      // deprecated in C++11, removed in C++17
292class mem_fun_t : public unary_function<T*, S>
293{
294public:
295    explicit mem_fun_t(S (T::*p)());
296    S operator()(T* p) const;
297};
298
299template<class S, class T, class A>
300class mem_fun1_t : public binary_function<T*, A, S>      // deprecated in C++11, removed in C++17
301{
302public:
303    explicit mem_fun1_t(S (T::*p)(A));
304    S operator()(T* p, A x) const;
305};
306
307template<class S, class T>          mem_fun_t<S,T>    mem_fun(S (T::*f)());      // deprecated in C++11, removed in C++17
308template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));     // deprecated in C++11, removed in C++17
309
310template<class S, class T>
311class mem_fun_ref_t : public unary_function<T, S>      // deprecated in C++11, removed in C++17
312{
313public:
314    explicit mem_fun_ref_t(S (T::*p)());
315    S operator()(T& p) const;
316};
317
318template<class S, class T, class A>
319class mem_fun1_ref_t : public binary_function<T, A, S>      // deprecated in C++11, removed in C++17
320{
321public:
322    explicit mem_fun1_ref_t(S (T::*p)(A));
323    S operator()(T& p, A x) const;
324};
325
326template<class S, class T>          mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)());      // deprecated in C++11, removed in C++17
327template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));     // deprecated in C++11, removed in C++17
328
329template <class S, class T>
330class const_mem_fun_t : public unary_function<const T*, S>      // deprecated in C++11, removed in C++17
331{
332public:
333    explicit const_mem_fun_t(S (T::*p)() const);
334    S operator()(const T* p) const;
335};
336
337template <class S, class T, class A>
338class const_mem_fun1_t : public binary_function<const T*, A, S>      // deprecated in C++11, removed in C++17
339{
340public:
341    explicit const_mem_fun1_t(S (T::*p)(A) const);
342    S operator()(const T* p, A x) const;
343};
344
345template <class S, class T>          const_mem_fun_t<S,T>    mem_fun(S (T::*f)() const);      // deprecated in C++11, removed in C++17
346template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);     // deprecated in C++11, removed in C++17
347
348template <class S, class T>
349class const_mem_fun_ref_t : public unary_function<T, S>      // deprecated in C++11, removed in C++17
350{
351public:
352    explicit const_mem_fun_ref_t(S (T::*p)() const);
353    S operator()(const T& p) const;
354};
355
356template <class S, class T, class A>
357class const_mem_fun1_ref_t : public binary_function<T, A, S>      // deprecated in C++11, removed in C++17
358{
359public:
360    explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
361    S operator()(const T& p, A x) const;
362};
363
364template <class S, class T>          const_mem_fun_ref_t<S,T>    mem_fun_ref(S (T::*f)() const);   // deprecated in C++11, removed in C++17
365template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);  // deprecated in C++11, removed in C++17
366
367template<class R, class T>
368constexpr unspecified mem_fn(R T::*); // constexpr in C++20
369
370class bad_function_call
371    : public exception
372{
373};
374
375template<class> class function; // undefined
376
377template<class R, class... ArgTypes>
378class function<R(ArgTypes...)>
379  : public unary_function<T1, R>      // iff sizeof...(ArgTypes) == 1 and
380                                      // ArgTypes contains T1
381  : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
382                                      // ArgTypes contains T1 and T2
383{
384public:
385    typedef R result_type;
386
387    // construct/copy/destroy:
388    function() noexcept;
389    function(nullptr_t) noexcept;
390    function(const function&);
391    function(function&&) noexcept;
392    template<class F>
393      function(F);
394    template<Allocator Alloc>
395      function(allocator_arg_t, const Alloc&) noexcept;            // removed in C++17
396    template<Allocator Alloc>
397      function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
398    template<Allocator Alloc>
399      function(allocator_arg_t, const Alloc&, const function&);    // removed in C++17
400    template<Allocator Alloc>
401      function(allocator_arg_t, const Alloc&, function&&);         // removed in C++17
402    template<class F, Allocator Alloc>
403      function(allocator_arg_t, const Alloc&, F);                  // removed in C++17
404
405    function& operator=(const function&);
406    function& operator=(function&&) noexcept;
407    function& operator=(nullptr_t) noexcept;
408    template<class F>
409      function& operator=(F&&);
410    template<class F>
411      function& operator=(reference_wrapper<F>) noexcept;
412
413    ~function();
414
415    // function modifiers:
416    void swap(function&) noexcept;
417    template<class F, class Alloc>
418      void assign(F&&, const Alloc&);                 // Removed in C++17
419
420    // function capacity:
421    explicit operator bool() const noexcept;
422
423    // function invocation:
424    R operator()(ArgTypes...) const;
425
426    // function target access:
427    const std::type_info& target_type() const noexcept;
428    template <typename T>       T* target() noexcept;
429    template <typename T> const T* target() const noexcept;
430};
431
432// Deduction guides
433template<class R, class ...Args>
434function(R(*)(Args...)) -> function<R(Args...)>; // since C++17
435
436template<class F>
437function(F) -> function<see-below>; // since C++17
438
439// Null pointer comparisons:
440template <class R, class ... ArgTypes>
441  bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
442
443template <class R, class ... ArgTypes>
444  bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
445
446template <class R, class ... ArgTypes>
447  bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
448
449template <class  R, class ... ArgTypes>
450  bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
451
452// specialized algorithms:
453template <class  R, class ... ArgTypes>
454  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
455
456template <class T> struct hash;
457
458template <> struct hash<bool>;
459template <> struct hash<char>;
460template <> struct hash<signed char>;
461template <> struct hash<unsigned char>;
462template <> struct hash<char8_t>; // since C++20
463template <> struct hash<char16_t>;
464template <> struct hash<char32_t>;
465template <> struct hash<wchar_t>;
466template <> struct hash<short>;
467template <> struct hash<unsigned short>;
468template <> struct hash<int>;
469template <> struct hash<unsigned int>;
470template <> struct hash<long>;
471template <> struct hash<long long>;
472template <> struct hash<unsigned long>;
473template <> struct hash<unsigned long long>;
474
475template <> struct hash<float>;
476template <> struct hash<double>;
477template <> struct hash<long double>;
478
479template<class T> struct hash<T*>;
480template <> struct hash<nullptr_t>;  // C++17
481
482}  // std
483
484POLICY:  For non-variadic implementations, the number of arguments is limited
485         to 3.  It is hoped that the need for non-variadic implementations
486         will be minimal.
487
488*/
489
490#include <__config>
491#include <__debug>
492#include <__functional_base>
493#include <__functional/search.h>
494#include <__utility/forward.h>
495#include <concepts>
496#include <exception>
497#include <memory>
498#include <tuple>
499#include <type_traits>
500#include <typeinfo>
501#include <utility>
502#include <version>
503
504#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
505#pragma GCC system_header
506#endif
507
508_LIBCPP_BEGIN_NAMESPACE_STD
509
510_LIBCPP_SUPPRESS_DEPRECATED_PUSH
511#if _LIBCPP_STD_VER > 11
512template <class _Tp = void>
513#else
514template <class _Tp>
515#endif
516struct _LIBCPP_TEMPLATE_VIS plus
517#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
518    : binary_function<_Tp, _Tp, _Tp>
519#endif
520{
521_LIBCPP_SUPPRESS_DEPRECATED_POP
522    typedef _Tp __result_type;  // used by valarray
523#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
524    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
525    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
526    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
527#endif
528    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
529    _Tp operator()(const _Tp& __x, const _Tp& __y) const
530        {return __x + __y;}
531};
532
533#if _LIBCPP_STD_VER > 11
534template <>
535struct _LIBCPP_TEMPLATE_VIS plus<void>
536{
537    template <class _T1, class _T2>
538    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
539    auto operator()(_T1&& __t, _T2&& __u) const
540    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
541    -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
542        { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
543    typedef void is_transparent;
544};
545#endif
546
547
548_LIBCPP_SUPPRESS_DEPRECATED_PUSH
549#if _LIBCPP_STD_VER > 11
550template <class _Tp = void>
551#else
552template <class _Tp>
553#endif
554struct _LIBCPP_TEMPLATE_VIS minus
555#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
556    : binary_function<_Tp, _Tp, _Tp>
557#endif
558{
559_LIBCPP_SUPPRESS_DEPRECATED_POP
560    typedef _Tp __result_type;  // used by valarray
561#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
562    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
563    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
564    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
565#endif
566    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
567    _Tp operator()(const _Tp& __x, const _Tp& __y) const
568        {return __x - __y;}
569};
570
571#if _LIBCPP_STD_VER > 11
572template <>
573struct _LIBCPP_TEMPLATE_VIS minus<void>
574{
575    template <class _T1, class _T2>
576    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
577    auto operator()(_T1&& __t, _T2&& __u) const
578    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
579    -> decltype        (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
580        { return        _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
581    typedef void is_transparent;
582};
583#endif
584
585
586_LIBCPP_SUPPRESS_DEPRECATED_PUSH
587#if _LIBCPP_STD_VER > 11
588template <class _Tp = void>
589#else
590template <class _Tp>
591#endif
592struct _LIBCPP_TEMPLATE_VIS multiplies
593#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
594    : binary_function<_Tp, _Tp, _Tp>
595#endif
596{
597_LIBCPP_SUPPRESS_DEPRECATED_POP
598    typedef _Tp __result_type;  // used by valarray
599#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
600    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
601    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
602    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
603#endif
604    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
605    _Tp operator()(const _Tp& __x, const _Tp& __y) const
606        {return __x * __y;}
607};
608
609#if _LIBCPP_STD_VER > 11
610template <>
611struct _LIBCPP_TEMPLATE_VIS multiplies<void>
612{
613    template <class _T1, class _T2>
614    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
615    auto operator()(_T1&& __t, _T2&& __u) const
616    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
617    -> decltype        (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
618        { return        _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
619    typedef void is_transparent;
620};
621#endif
622
623
624_LIBCPP_SUPPRESS_DEPRECATED_PUSH
625#if _LIBCPP_STD_VER > 11
626template <class _Tp = void>
627#else
628template <class _Tp>
629#endif
630struct _LIBCPP_TEMPLATE_VIS divides
631#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
632    : binary_function<_Tp, _Tp, _Tp>
633#endif
634{
635_LIBCPP_SUPPRESS_DEPRECATED_POP
636    typedef _Tp __result_type;  // used by valarray
637#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
638    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
639    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
640    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
641#endif
642    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
643    _Tp operator()(const _Tp& __x, const _Tp& __y) const
644        {return __x / __y;}
645};
646
647#if _LIBCPP_STD_VER > 11
648template <>
649struct _LIBCPP_TEMPLATE_VIS divides<void>
650{
651    template <class _T1, class _T2>
652    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
653    auto operator()(_T1&& __t, _T2&& __u) const
654    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
655    -> decltype        (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
656        { return        _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
657    typedef void is_transparent;
658};
659#endif
660
661
662_LIBCPP_SUPPRESS_DEPRECATED_PUSH
663#if _LIBCPP_STD_VER > 11
664template <class _Tp = void>
665#else
666template <class _Tp>
667#endif
668struct _LIBCPP_TEMPLATE_VIS modulus
669#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
670    : binary_function<_Tp, _Tp, _Tp>
671#endif
672{
673_LIBCPP_SUPPRESS_DEPRECATED_POP
674    typedef _Tp __result_type;  // used by valarray
675#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
676    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
677    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
678    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
679#endif
680    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
681    _Tp operator()(const _Tp& __x, const _Tp& __y) const
682        {return __x % __y;}
683};
684
685#if _LIBCPP_STD_VER > 11
686template <>
687struct _LIBCPP_TEMPLATE_VIS modulus<void>
688{
689    template <class _T1, class _T2>
690    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
691    auto operator()(_T1&& __t, _T2&& __u) const
692    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
693    -> decltype        (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
694        { return        _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
695    typedef void is_transparent;
696};
697#endif
698
699
700_LIBCPP_SUPPRESS_DEPRECATED_PUSH
701#if _LIBCPP_STD_VER > 11
702template <class _Tp = void>
703#else
704template <class _Tp>
705#endif
706struct _LIBCPP_TEMPLATE_VIS negate
707#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
708    : unary_function<_Tp, _Tp>
709#endif
710{
711_LIBCPP_SUPPRESS_DEPRECATED_POP
712    typedef _Tp __result_type;  // used by valarray
713#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
714    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
715    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
716#endif
717    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
718    _Tp operator()(const _Tp& __x) const
719        {return -__x;}
720};
721
722#if _LIBCPP_STD_VER > 11
723template <>
724struct _LIBCPP_TEMPLATE_VIS negate<void>
725{
726    template <class _Tp>
727    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
728    auto operator()(_Tp&& __x) const
729    _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
730    -> decltype        (- _VSTD::forward<_Tp>(__x))
731        { return        - _VSTD::forward<_Tp>(__x); }
732    typedef void is_transparent;
733};
734#endif
735
736
737_LIBCPP_SUPPRESS_DEPRECATED_PUSH
738#if _LIBCPP_STD_VER > 11
739template <class _Tp = void>
740#else
741template <class _Tp>
742#endif
743struct _LIBCPP_TEMPLATE_VIS equal_to
744#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
745    : binary_function<_Tp, _Tp, bool>
746#endif
747{
748_LIBCPP_SUPPRESS_DEPRECATED_POP
749    typedef bool __result_type;  // used by valarray
750#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
751    _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
752    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
753    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
754#endif
755    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
756    bool operator()(const _Tp& __x, const _Tp& __y) const
757        {return __x == __y;}
758};
759
760#if _LIBCPP_STD_VER > 11
761template <>
762struct _LIBCPP_TEMPLATE_VIS equal_to<void>
763{
764    template <class _T1, class _T2>
765    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
766    auto operator()(_T1&& __t, _T2&& __u) const
767    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
768    -> decltype        (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
769        { return        _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
770    typedef void is_transparent;
771};
772#endif
773
774
775_LIBCPP_SUPPRESS_DEPRECATED_PUSH
776#if _LIBCPP_STD_VER > 11
777template <class _Tp = void>
778#else
779template <class _Tp>
780#endif
781struct _LIBCPP_TEMPLATE_VIS not_equal_to
782#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
783    : binary_function<_Tp, _Tp, bool>
784#endif
785{
786_LIBCPP_SUPPRESS_DEPRECATED_POP
787    typedef bool __result_type;  // used by valarray
788#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
789    _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
790    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
791    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
792#endif
793    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
794    bool operator()(const _Tp& __x, const _Tp& __y) const
795        {return __x != __y;}
796};
797
798#if _LIBCPP_STD_VER > 11
799template <>
800struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
801{
802    template <class _T1, class _T2>
803    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
804    auto operator()(_T1&& __t, _T2&& __u) const
805    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
806    -> decltype        (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
807        { return        _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
808    typedef void is_transparent;
809};
810#endif
811
812
813_LIBCPP_SUPPRESS_DEPRECATED_PUSH
814#if _LIBCPP_STD_VER > 11
815template <class _Tp = void>
816#else
817template <class _Tp>
818#endif
819struct _LIBCPP_TEMPLATE_VIS greater
820#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
821    : binary_function<_Tp, _Tp, bool>
822#endif
823{
824_LIBCPP_SUPPRESS_DEPRECATED_POP
825    typedef bool __result_type;  // used by valarray
826#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
827    _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
828    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
829    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
830#endif
831    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
832    bool operator()(const _Tp& __x, const _Tp& __y) const
833        {return __x > __y;}
834};
835
836#if _LIBCPP_STD_VER > 11
837template <>
838struct _LIBCPP_TEMPLATE_VIS greater<void>
839{
840    template <class _T1, class _T2>
841    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
842    auto operator()(_T1&& __t, _T2&& __u) const
843    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
844    -> decltype        (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
845        { return        _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
846    typedef void is_transparent;
847};
848#endif
849
850
851// less in <__functional_base>
852
853
854_LIBCPP_SUPPRESS_DEPRECATED_PUSH
855#if _LIBCPP_STD_VER > 11
856template <class _Tp = void>
857#else
858template <class _Tp>
859#endif
860struct _LIBCPP_TEMPLATE_VIS greater_equal
861#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
862    : binary_function<_Tp, _Tp, bool>
863#endif
864{
865_LIBCPP_SUPPRESS_DEPRECATED_POP
866    typedef bool __result_type;  // used by valarray
867#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
868    _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
869    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
870    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
871#endif
872    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
873    bool operator()(const _Tp& __x, const _Tp& __y) const
874        {return __x >= __y;}
875};
876
877#if _LIBCPP_STD_VER > 11
878template <>
879struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
880{
881    template <class _T1, class _T2>
882    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
883    auto operator()(_T1&& __t, _T2&& __u) const
884    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
885    -> decltype        (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
886        { return        _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
887    typedef void is_transparent;
888};
889#endif
890
891
892_LIBCPP_SUPPRESS_DEPRECATED_PUSH
893#if _LIBCPP_STD_VER > 11
894template <class _Tp = void>
895#else
896template <class _Tp>
897#endif
898struct _LIBCPP_TEMPLATE_VIS less_equal
899#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
900    : binary_function<_Tp, _Tp, bool>
901#endif
902{
903_LIBCPP_SUPPRESS_DEPRECATED_POP
904    typedef bool __result_type;  // used by valarray
905#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
906    _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
907    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
908    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
909#endif
910    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
911    bool operator()(const _Tp& __x, const _Tp& __y) const
912        {return __x <= __y;}
913};
914
915#if _LIBCPP_STD_VER > 11
916template <>
917struct _LIBCPP_TEMPLATE_VIS less_equal<void>
918{
919    template <class _T1, class _T2>
920    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
921    auto operator()(_T1&& __t, _T2&& __u) const
922    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
923    -> decltype        (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
924        { return        _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
925    typedef void is_transparent;
926};
927#endif
928
929
930_LIBCPP_SUPPRESS_DEPRECATED_PUSH
931#if _LIBCPP_STD_VER > 11
932template <class _Tp = void>
933#else
934template <class _Tp>
935#endif
936struct _LIBCPP_TEMPLATE_VIS logical_and
937#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
938    : binary_function<_Tp, _Tp, bool>
939#endif
940{
941_LIBCPP_SUPPRESS_DEPRECATED_POP
942    typedef bool __result_type;  // used by valarray
943#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
944    _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
945    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
946    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
947#endif
948    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
949    bool operator()(const _Tp& __x, const _Tp& __y) const
950        {return __x && __y;}
951};
952
953#if _LIBCPP_STD_VER > 11
954template <>
955struct _LIBCPP_TEMPLATE_VIS logical_and<void>
956{
957    template <class _T1, class _T2>
958    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
959    auto operator()(_T1&& __t, _T2&& __u) const
960    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
961    -> decltype        (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
962        { return        _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
963    typedef void is_transparent;
964};
965#endif
966
967
968_LIBCPP_SUPPRESS_DEPRECATED_PUSH
969#if _LIBCPP_STD_VER > 11
970template <class _Tp = void>
971#else
972template <class _Tp>
973#endif
974struct _LIBCPP_TEMPLATE_VIS logical_or
975#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
976    : binary_function<_Tp, _Tp, bool>
977#endif
978{
979_LIBCPP_SUPPRESS_DEPRECATED_POP
980    typedef bool __result_type;  // used by valarray
981#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
982    _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
983    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
984    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
985#endif
986    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
987    bool operator()(const _Tp& __x, const _Tp& __y) const
988        {return __x || __y;}
989};
990
991#if _LIBCPP_STD_VER > 11
992template <>
993struct _LIBCPP_TEMPLATE_VIS logical_or<void>
994{
995    template <class _T1, class _T2>
996    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
997    auto operator()(_T1&& __t, _T2&& __u) const
998    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
999    -> decltype        (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
1000        { return        _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
1001    typedef void is_transparent;
1002};
1003#endif
1004
1005
1006_LIBCPP_SUPPRESS_DEPRECATED_PUSH
1007#if _LIBCPP_STD_VER > 11
1008template <class _Tp = void>
1009#else
1010template <class _Tp>
1011#endif
1012struct _LIBCPP_TEMPLATE_VIS logical_not
1013#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1014    : unary_function<_Tp, bool>
1015#endif
1016{
1017_LIBCPP_SUPPRESS_DEPRECATED_POP
1018    typedef bool __result_type;  // used by valarray
1019#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1020    _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1021    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1022#endif
1023    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1024    bool operator()(const _Tp& __x) const
1025        {return !__x;}
1026};
1027
1028#if _LIBCPP_STD_VER > 11
1029template <>
1030struct _LIBCPP_TEMPLATE_VIS logical_not<void>
1031{
1032    template <class _Tp>
1033    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1034    auto operator()(_Tp&& __x) const
1035    _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
1036    -> decltype        (!_VSTD::forward<_Tp>(__x))
1037        { return        !_VSTD::forward<_Tp>(__x); }
1038    typedef void is_transparent;
1039};
1040#endif
1041
1042
1043_LIBCPP_SUPPRESS_DEPRECATED_PUSH
1044#if _LIBCPP_STD_VER > 11
1045template <class _Tp = void>
1046#else
1047template <class _Tp>
1048#endif
1049struct _LIBCPP_TEMPLATE_VIS bit_and
1050#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1051    : binary_function<_Tp, _Tp, _Tp>
1052#endif
1053{
1054_LIBCPP_SUPPRESS_DEPRECATED_POP
1055    typedef _Tp __result_type;  // used by valarray
1056#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1057    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1058    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1059    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1060#endif
1061    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1062    _Tp operator()(const _Tp& __x, const _Tp& __y) const
1063        {return __x & __y;}
1064};
1065
1066#if _LIBCPP_STD_VER > 11
1067template <>
1068struct _LIBCPP_TEMPLATE_VIS bit_and<void>
1069{
1070    template <class _T1, class _T2>
1071    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1072    auto operator()(_T1&& __t, _T2&& __u) const
1073    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
1074    -> decltype        (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
1075        { return        _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
1076    typedef void is_transparent;
1077};
1078#endif
1079
1080
1081_LIBCPP_SUPPRESS_DEPRECATED_PUSH
1082#if _LIBCPP_STD_VER > 11
1083template <class _Tp = void>
1084#else
1085template <class _Tp>
1086#endif
1087struct _LIBCPP_TEMPLATE_VIS bit_or
1088#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1089    : binary_function<_Tp, _Tp, _Tp>
1090#endif
1091{
1092_LIBCPP_SUPPRESS_DEPRECATED_POP
1093    typedef _Tp __result_type;  // used by valarray
1094#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1095    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1096    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1097    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1098#endif
1099    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1100    _Tp operator()(const _Tp& __x, const _Tp& __y) const
1101        {return __x | __y;}
1102};
1103
1104#if _LIBCPP_STD_VER > 11
1105template <>
1106struct _LIBCPP_TEMPLATE_VIS bit_or<void>
1107{
1108    template <class _T1, class _T2>
1109    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1110    auto operator()(_T1&& __t, _T2&& __u) const
1111    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
1112    -> decltype        (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
1113        { return        _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
1114    typedef void is_transparent;
1115};
1116#endif
1117
1118
1119_LIBCPP_SUPPRESS_DEPRECATED_PUSH
1120#if _LIBCPP_STD_VER > 11
1121template <class _Tp = void>
1122#else
1123template <class _Tp>
1124#endif
1125struct _LIBCPP_TEMPLATE_VIS bit_xor
1126#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1127    : binary_function<_Tp, _Tp, _Tp>
1128#endif
1129{
1130_LIBCPP_SUPPRESS_DEPRECATED_POP
1131    typedef _Tp __result_type;  // used by valarray
1132#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1133    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1134    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1135    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1136#endif
1137    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1138    _Tp operator()(const _Tp& __x, const _Tp& __y) const
1139        {return __x ^ __y;}
1140};
1141
1142#if _LIBCPP_STD_VER > 11
1143template <>
1144struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
1145{
1146    template <class _T1, class _T2>
1147    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1148    auto operator()(_T1&& __t, _T2&& __u) const
1149    _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
1150    -> decltype        (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
1151        { return        _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
1152    typedef void is_transparent;
1153};
1154#endif
1155
1156
1157#if _LIBCPP_STD_VER > 11
1158_LIBCPP_SUPPRESS_DEPRECATED_PUSH
1159template <class _Tp = void>
1160struct _LIBCPP_TEMPLATE_VIS bit_not
1161#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1162    : unary_function<_Tp, _Tp>
1163#endif
1164{
1165_LIBCPP_SUPPRESS_DEPRECATED_POP
1166#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1167    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1168    _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1169#endif
1170    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1171    _Tp operator()(const _Tp& __x) const
1172        {return ~__x;}
1173};
1174
1175template <>
1176struct _LIBCPP_TEMPLATE_VIS bit_not<void>
1177{
1178    template <class _Tp>
1179    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1180    auto operator()(_Tp&& __x) const
1181    _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
1182    -> decltype        (~_VSTD::forward<_Tp>(__x))
1183        { return        ~_VSTD::forward<_Tp>(__x); }
1184    typedef void is_transparent;
1185};
1186#endif
1187
1188#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
1189template <class _Predicate>
1190class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
1191    : public unary_function<typename _Predicate::argument_type, bool>
1192{
1193    _Predicate __pred_;
1194public:
1195    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1196    explicit unary_negate(const _Predicate& __pred)
1197        : __pred_(__pred) {}
1198    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1199    bool operator()(const typename _Predicate::argument_type& __x) const
1200        {return !__pred_(__x);}
1201};
1202
1203template <class _Predicate>
1204_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1205unary_negate<_Predicate>
1206not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1207
1208template <class _Predicate>
1209class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
1210    : public binary_function<typename _Predicate::first_argument_type,
1211                             typename _Predicate::second_argument_type,
1212                             bool>
1213{
1214    _Predicate __pred_;
1215public:
1216    _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1217    binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1218
1219    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1220    bool operator()(const typename _Predicate::first_argument_type& __x,
1221                    const typename _Predicate::second_argument_type& __y) const
1222        {return !__pred_(__x, __y);}
1223};
1224
1225template <class _Predicate>
1226_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1227binary_negate<_Predicate>
1228not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1229#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
1230
1231#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
1232template <class __Operation>
1233class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
1234    : public unary_function<typename __Operation::second_argument_type,
1235                            typename __Operation::result_type>
1236{
1237protected:
1238    __Operation                               op;
1239    typename __Operation::first_argument_type value;
1240public:
1241    _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1242                               const typename __Operation::first_argument_type __y)
1243        : op(__x), value(__y) {}
1244    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1245        (typename __Operation::second_argument_type& __x) const
1246            {return op(value, __x);}
1247    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1248        (const typename __Operation::second_argument_type& __x) const
1249            {return op(value, __x);}
1250};
1251
1252template <class __Operation, class _Tp>
1253_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1254binder1st<__Operation>
1255bind1st(const __Operation& __op, const _Tp& __x)
1256    {return binder1st<__Operation>(__op, __x);}
1257
1258template <class __Operation>
1259class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
1260    : public unary_function<typename __Operation::first_argument_type,
1261                            typename __Operation::result_type>
1262{
1263protected:
1264    __Operation                                op;
1265    typename __Operation::second_argument_type value;
1266public:
1267    _LIBCPP_INLINE_VISIBILITY
1268    binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1269        : op(__x), value(__y) {}
1270    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1271        (      typename __Operation::first_argument_type& __x) const
1272            {return op(__x, value);}
1273    _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1274        (const typename __Operation::first_argument_type& __x) const
1275            {return op(__x, value);}
1276};
1277
1278template <class __Operation, class _Tp>
1279_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1280binder2nd<__Operation>
1281bind2nd(const __Operation& __op, const _Tp& __x)
1282    {return binder2nd<__Operation>(__op, __x);}
1283
1284template <class _Arg, class _Result>
1285class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
1286    : public unary_function<_Arg, _Result>
1287{
1288    _Result (*__f_)(_Arg);
1289public:
1290    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1291        : __f_(__f) {}
1292    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1293        {return __f_(__x);}
1294};
1295
1296template <class _Arg, class _Result>
1297_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1298pointer_to_unary_function<_Arg,_Result>
1299ptr_fun(_Result (*__f)(_Arg))
1300    {return pointer_to_unary_function<_Arg,_Result>(__f);}
1301
1302template <class _Arg1, class _Arg2, class _Result>
1303class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
1304    : public binary_function<_Arg1, _Arg2, _Result>
1305{
1306    _Result (*__f_)(_Arg1, _Arg2);
1307public:
1308    _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1309        : __f_(__f) {}
1310    _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1311        {return __f_(__x, __y);}
1312};
1313
1314template <class _Arg1, class _Arg2, class _Result>
1315_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1316pointer_to_binary_function<_Arg1,_Arg2,_Result>
1317ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1318    {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1319
1320template<class _Sp, class _Tp>
1321class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1322    : public unary_function<_Tp*, _Sp>
1323{
1324    _Sp (_Tp::*__p_)();
1325public:
1326    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1327        : __p_(__p) {}
1328    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1329        {return (__p->*__p_)();}
1330};
1331
1332template<class _Sp, class _Tp, class _Ap>
1333class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1334    : public binary_function<_Tp*, _Ap, _Sp>
1335{
1336    _Sp (_Tp::*__p_)(_Ap);
1337public:
1338    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1339        : __p_(__p) {}
1340    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1341        {return (__p->*__p_)(__x);}
1342};
1343
1344template<class _Sp, class _Tp>
1345_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1346mem_fun_t<_Sp,_Tp>
1347mem_fun(_Sp (_Tp::*__f)())
1348    {return mem_fun_t<_Sp,_Tp>(__f);}
1349
1350template<class _Sp, class _Tp, class _Ap>
1351_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1352mem_fun1_t<_Sp,_Tp,_Ap>
1353mem_fun(_Sp (_Tp::*__f)(_Ap))
1354    {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1355
1356template<class _Sp, class _Tp>
1357class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1358    : public unary_function<_Tp, _Sp>
1359{
1360    _Sp (_Tp::*__p_)();
1361public:
1362    _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1363        : __p_(__p) {}
1364    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1365        {return (__p.*__p_)();}
1366};
1367
1368template<class _Sp, class _Tp, class _Ap>
1369class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1370    : public binary_function<_Tp, _Ap, _Sp>
1371{
1372    _Sp (_Tp::*__p_)(_Ap);
1373public:
1374    _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1375        : __p_(__p) {}
1376    _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1377        {return (__p.*__p_)(__x);}
1378};
1379
1380template<class _Sp, class _Tp>
1381_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1382mem_fun_ref_t<_Sp,_Tp>
1383mem_fun_ref(_Sp (_Tp::*__f)())
1384    {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1385
1386template<class _Sp, class _Tp, class _Ap>
1387_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1388mem_fun1_ref_t<_Sp,_Tp,_Ap>
1389mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1390    {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1391
1392template <class _Sp, class _Tp>
1393class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1394    : public unary_function<const _Tp*, _Sp>
1395{
1396    _Sp (_Tp::*__p_)() const;
1397public:
1398    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1399        : __p_(__p) {}
1400    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1401        {return (__p->*__p_)();}
1402};
1403
1404template <class _Sp, class _Tp, class _Ap>
1405class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1406    : public binary_function<const _Tp*, _Ap, _Sp>
1407{
1408    _Sp (_Tp::*__p_)(_Ap) const;
1409public:
1410    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1411        : __p_(__p) {}
1412    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1413        {return (__p->*__p_)(__x);}
1414};
1415
1416template <class _Sp, class _Tp>
1417_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1418const_mem_fun_t<_Sp,_Tp>
1419mem_fun(_Sp (_Tp::*__f)() const)
1420    {return const_mem_fun_t<_Sp,_Tp>(__f);}
1421
1422template <class _Sp, class _Tp, class _Ap>
1423_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1424const_mem_fun1_t<_Sp,_Tp,_Ap>
1425mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1426    {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1427
1428template <class _Sp, class _Tp>
1429class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1430    : public unary_function<_Tp, _Sp>
1431{
1432    _Sp (_Tp::*__p_)() const;
1433public:
1434    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1435        : __p_(__p) {}
1436    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1437        {return (__p.*__p_)();}
1438};
1439
1440template <class _Sp, class _Tp, class _Ap>
1441class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
1442    : public binary_function<_Tp, _Ap, _Sp>
1443{
1444    _Sp (_Tp::*__p_)(_Ap) const;
1445public:
1446    _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1447        : __p_(__p) {}
1448    _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1449        {return (__p.*__p_)(__x);}
1450};
1451
1452template <class _Sp, class _Tp>
1453_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1454const_mem_fun_ref_t<_Sp,_Tp>
1455mem_fun_ref(_Sp (_Tp::*__f)() const)
1456    {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1457
1458template <class _Sp, class _Tp, class _Ap>
1459_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
1460const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1461mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1462    {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1463#endif
1464
1465////////////////////////////////////////////////////////////////////////////////
1466//                                MEMFUN
1467//==============================================================================
1468
1469template <class _Tp>
1470class __mem_fn
1471#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1472    : public __weak_result_type<_Tp>
1473#endif
1474{
1475public:
1476    // types
1477    typedef _Tp type;
1478private:
1479    type __f_;
1480
1481public:
1482    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1483    __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
1484
1485#ifndef _LIBCPP_CXX03_LANG
1486    // invoke
1487    template <class... _ArgTypes>
1488    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1489    typename __invoke_return<type, _ArgTypes...>::type
1490    operator() (_ArgTypes&&... __args) const {
1491        return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1492    }
1493#else
1494
1495    template <class _A0>
1496    _LIBCPP_INLINE_VISIBILITY
1497    typename __invoke_return0<type, _A0>::type
1498    operator() (_A0& __a0) const {
1499        return _VSTD::__invoke(__f_, __a0);
1500    }
1501
1502    template <class _A0>
1503    _LIBCPP_INLINE_VISIBILITY
1504    typename __invoke_return0<type, _A0 const>::type
1505    operator() (_A0 const& __a0) const {
1506        return _VSTD::__invoke(__f_, __a0);
1507    }
1508
1509    template <class _A0, class _A1>
1510    _LIBCPP_INLINE_VISIBILITY
1511    typename __invoke_return1<type, _A0, _A1>::type
1512    operator() (_A0& __a0, _A1& __a1) const {
1513        return _VSTD::__invoke(__f_, __a0, __a1);
1514    }
1515
1516    template <class _A0, class _A1>
1517    _LIBCPP_INLINE_VISIBILITY
1518    typename __invoke_return1<type, _A0 const, _A1>::type
1519    operator() (_A0 const& __a0, _A1& __a1) const {
1520        return _VSTD::__invoke(__f_, __a0, __a1);
1521    }
1522
1523    template <class _A0, class _A1>
1524    _LIBCPP_INLINE_VISIBILITY
1525    typename __invoke_return1<type, _A0, _A1 const>::type
1526    operator() (_A0& __a0, _A1 const& __a1) const {
1527        return _VSTD::__invoke(__f_, __a0, __a1);
1528    }
1529
1530    template <class _A0, class _A1>
1531    _LIBCPP_INLINE_VISIBILITY
1532    typename __invoke_return1<type, _A0 const, _A1 const>::type
1533    operator() (_A0 const& __a0, _A1 const& __a1) const {
1534        return _VSTD::__invoke(__f_, __a0, __a1);
1535    }
1536
1537    template <class _A0, class _A1, class _A2>
1538    _LIBCPP_INLINE_VISIBILITY
1539    typename __invoke_return2<type, _A0, _A1, _A2>::type
1540    operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1541        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1542    }
1543
1544    template <class _A0, class _A1, class _A2>
1545    _LIBCPP_INLINE_VISIBILITY
1546    typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1547    operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1548        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1549    }
1550
1551    template <class _A0, class _A1, class _A2>
1552    _LIBCPP_INLINE_VISIBILITY
1553    typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1554    operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1555        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1556    }
1557
1558    template <class _A0, class _A1, class _A2>
1559    _LIBCPP_INLINE_VISIBILITY
1560    typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1561    operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1562        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1563    }
1564
1565    template <class _A0, class _A1, class _A2>
1566    _LIBCPP_INLINE_VISIBILITY
1567    typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1568    operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1569        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1570    }
1571
1572    template <class _A0, class _A1, class _A2>
1573    _LIBCPP_INLINE_VISIBILITY
1574    typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1575    operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1576        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1577    }
1578
1579    template <class _A0, class _A1, class _A2>
1580    _LIBCPP_INLINE_VISIBILITY
1581    typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1582    operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1583        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1584    }
1585
1586    template <class _A0, class _A1, class _A2>
1587    _LIBCPP_INLINE_VISIBILITY
1588    typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1589    operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1590        return _VSTD::__invoke(__f_, __a0, __a1, __a2);
1591    }
1592#endif
1593};
1594
1595template<class _Rp, class _Tp>
1596inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1597__mem_fn<_Rp _Tp::*>
1598mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
1599{
1600    return __mem_fn<_Rp _Tp::*>(__pm);
1601}
1602
1603////////////////////////////////////////////////////////////////////////////////
1604//                                FUNCTION
1605//==============================================================================
1606
1607// bad_function_call
1608
1609class _LIBCPP_EXCEPTION_ABI bad_function_call
1610    : public exception
1611{
1612#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1613public:
1614    virtual ~bad_function_call() _NOEXCEPT;
1615
1616    virtual const char* what() const _NOEXCEPT;
1617#endif
1618};
1619
1620_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1621void __throw_bad_function_call()
1622{
1623#ifndef _LIBCPP_NO_EXCEPTIONS
1624    throw bad_function_call();
1625#else
1626    _VSTD::abort();
1627#endif
1628}
1629
1630#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1631#   define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1632        __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1633#else
1634#   define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1635#endif
1636
1637template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
1638
1639namespace __function
1640{
1641
1642template<class _Rp>
1643struct __maybe_derive_from_unary_function
1644{
1645};
1646
1647template<class _Rp, class _A1>
1648struct __maybe_derive_from_unary_function<_Rp(_A1)>
1649    : public unary_function<_A1, _Rp>
1650{
1651};
1652
1653template<class _Rp>
1654struct __maybe_derive_from_binary_function
1655{
1656};
1657
1658template<class _Rp, class _A1, class _A2>
1659struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1660    : public binary_function<_A1, _A2, _Rp>
1661{
1662};
1663
1664template <class _Fp>
1665_LIBCPP_INLINE_VISIBILITY
1666bool __not_null(_Fp const&) { return true; }
1667
1668template <class _Fp>
1669_LIBCPP_INLINE_VISIBILITY
1670bool __not_null(_Fp* __ptr) { return __ptr; }
1671
1672template <class _Ret, class _Class>
1673_LIBCPP_INLINE_VISIBILITY
1674bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1675
1676template <class _Fp>
1677_LIBCPP_INLINE_VISIBILITY
1678bool __not_null(function<_Fp> const& __f) { return !!__f; }
1679
1680#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1681template <class _Rp, class ..._Args>
1682_LIBCPP_INLINE_VISIBILITY
1683bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1684#endif
1685
1686} // namespace __function
1687
1688#ifndef _LIBCPP_CXX03_LANG
1689
1690namespace __function {
1691
1692// __alloc_func holds a functor and an allocator.
1693
1694template <class _Fp, class _Ap, class _FB> class __alloc_func;
1695template <class _Fp, class _FB>
1696class __default_alloc_func;
1697
1698template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1699class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1700{
1701    __compressed_pair<_Fp, _Ap> __f_;
1702
1703  public:
1704    typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1705    typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
1706
1707    _LIBCPP_INLINE_VISIBILITY
1708    const _Target& __target() const { return __f_.first(); }
1709
1710    // WIN32 APIs may define __allocator, so use __get_allocator instead.
1711    _LIBCPP_INLINE_VISIBILITY
1712    const _Alloc& __get_allocator() const { return __f_.second(); }
1713
1714    _LIBCPP_INLINE_VISIBILITY
1715    explicit __alloc_func(_Target&& __f)
1716        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1717               _VSTD::forward_as_tuple())
1718    {
1719    }
1720
1721    _LIBCPP_INLINE_VISIBILITY
1722    explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1723        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1724               _VSTD::forward_as_tuple(__a))
1725    {
1726    }
1727
1728    _LIBCPP_INLINE_VISIBILITY
1729    explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1730        : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1731               _VSTD::forward_as_tuple(_VSTD::move(__a)))
1732    {
1733    }
1734
1735    _LIBCPP_INLINE_VISIBILITY
1736    explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1737        : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1738               _VSTD::forward_as_tuple(_VSTD::move(__a)))
1739    {
1740    }
1741
1742    _LIBCPP_INLINE_VISIBILITY
1743    _Rp operator()(_ArgTypes&&... __arg)
1744    {
1745        typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1746        return _Invoker::__call(__f_.first(),
1747                                _VSTD::forward<_ArgTypes>(__arg)...);
1748    }
1749
1750    _LIBCPP_INLINE_VISIBILITY
1751    __alloc_func* __clone() const
1752    {
1753        typedef allocator_traits<_Alloc> __alloc_traits;
1754        typedef
1755            typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1756                _AA;
1757        _AA __a(__f_.second());
1758        typedef __allocator_destructor<_AA> _Dp;
1759        unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1760        ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1761        return __hold.release();
1762    }
1763
1764    _LIBCPP_INLINE_VISIBILITY
1765    void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
1766
1767    static void __destroy_and_delete(__alloc_func* __f) {
1768      typedef allocator_traits<_Alloc> __alloc_traits;
1769      typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1770          _FunAlloc;
1771      _FunAlloc __a(__f->__get_allocator());
1772      __f->destroy();
1773      __a.deallocate(__f, 1);
1774    }
1775};
1776
1777template <class _Fp, class _Rp, class... _ArgTypes>
1778class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1779  _Fp __f_;
1780
1781public:
1782  typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1783
1784  _LIBCPP_INLINE_VISIBILITY
1785  const _Target& __target() const { return __f_; }
1786
1787  _LIBCPP_INLINE_VISIBILITY
1788  explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {}
1789
1790  _LIBCPP_INLINE_VISIBILITY
1791  explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1792
1793  _LIBCPP_INLINE_VISIBILITY
1794  _Rp operator()(_ArgTypes&&... __arg) {
1795    typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1796    return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1797  }
1798
1799  _LIBCPP_INLINE_VISIBILITY
1800  __default_alloc_func* __clone() const {
1801      __builtin_new_allocator::__holder_t __hold =
1802        __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1803    __default_alloc_func* __res =
1804        ::new ((void*)__hold.get()) __default_alloc_func(__f_);
1805    (void)__hold.release();
1806    return __res;
1807  }
1808
1809  _LIBCPP_INLINE_VISIBILITY
1810  void destroy() _NOEXCEPT { __f_.~_Target(); }
1811
1812  static void __destroy_and_delete(__default_alloc_func* __f) {
1813    __f->destroy();
1814      __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1815  }
1816};
1817
1818// __base provides an abstract interface for copyable functors.
1819
1820template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
1821
1822template<class _Rp, class ..._ArgTypes>
1823class __base<_Rp(_ArgTypes...)>
1824{
1825    __base(const __base&);
1826    __base& operator=(const __base&);
1827public:
1828    _LIBCPP_INLINE_VISIBILITY __base() {}
1829    _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
1830    virtual __base* __clone() const = 0;
1831    virtual void __clone(__base*) const = 0;
1832    virtual void destroy() _NOEXCEPT = 0;
1833    virtual void destroy_deallocate() _NOEXCEPT = 0;
1834    virtual _Rp operator()(_ArgTypes&& ...) = 0;
1835#ifndef _LIBCPP_NO_RTTI
1836    virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1837    virtual const std::type_info& target_type() const _NOEXCEPT = 0;
1838#endif // _LIBCPP_NO_RTTI
1839};
1840
1841// __func implements __base for a given functor type.
1842
1843template<class _FD, class _Alloc, class _FB> class __func;
1844
1845template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1846class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1847    : public  __base<_Rp(_ArgTypes...)>
1848{
1849    __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
1850public:
1851    _LIBCPP_INLINE_VISIBILITY
1852    explicit __func(_Fp&& __f)
1853        : __f_(_VSTD::move(__f)) {}
1854
1855    _LIBCPP_INLINE_VISIBILITY
1856    explicit __func(const _Fp& __f, const _Alloc& __a)
1857        : __f_(__f, __a) {}
1858
1859    _LIBCPP_INLINE_VISIBILITY
1860    explicit __func(const _Fp& __f, _Alloc&& __a)
1861        : __f_(__f, _VSTD::move(__a)) {}
1862
1863    _LIBCPP_INLINE_VISIBILITY
1864    explicit __func(_Fp&& __f, _Alloc&& __a)
1865        : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1866
1867    virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1868    virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
1869    virtual void destroy() _NOEXCEPT;
1870    virtual void destroy_deallocate() _NOEXCEPT;
1871    virtual _Rp operator()(_ArgTypes&&... __arg);
1872#ifndef _LIBCPP_NO_RTTI
1873    virtual const void* target(const type_info&) const _NOEXCEPT;
1874    virtual const std::type_info& target_type() const _NOEXCEPT;
1875#endif // _LIBCPP_NO_RTTI
1876};
1877
1878template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1879__base<_Rp(_ArgTypes...)>*
1880__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
1881{
1882    typedef allocator_traits<_Alloc> __alloc_traits;
1883    typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1884    _Ap __a(__f_.__get_allocator());
1885    typedef __allocator_destructor<_Ap> _Dp;
1886    unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1887    ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
1888    return __hold.release();
1889}
1890
1891template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1892void
1893__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
1894{
1895    ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
1896}
1897
1898template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1899void
1900__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
1901{
1902    __f_.destroy();
1903}
1904
1905template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1906void
1907__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
1908{
1909    typedef allocator_traits<_Alloc> __alloc_traits;
1910    typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1911    _Ap __a(__f_.__get_allocator());
1912    __f_.destroy();
1913    __a.deallocate(this, 1);
1914}
1915
1916template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1917_Rp
1918__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1919{
1920    return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
1921}
1922
1923#ifndef _LIBCPP_NO_RTTI
1924
1925template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1926const void*
1927__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
1928{
1929    if (__ti == typeid(_Fp))
1930        return &__f_.__target();
1931    return nullptr;
1932}
1933
1934template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1935const std::type_info&
1936__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
1937{
1938    return typeid(_Fp);
1939}
1940
1941#endif // _LIBCPP_NO_RTTI
1942
1943// __value_func creates a value-type from a __func.
1944
1945template <class _Fp> class __value_func;
1946
1947template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1948{
1949    typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1950
1951    typedef __base<_Rp(_ArgTypes...)> __func;
1952    __func* __f_;
1953
1954    _LIBCPP_NO_CFI static __func* __as_base(void* p)
1955    {
1956        return reinterpret_cast<__func*>(p);
1957    }
1958
1959  public:
1960    _LIBCPP_INLINE_VISIBILITY
1961    __value_func() _NOEXCEPT : __f_(nullptr) {}
1962
1963    template <class _Fp, class _Alloc>
1964    _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
1965        : __f_(nullptr)
1966    {
1967        typedef allocator_traits<_Alloc> __alloc_traits;
1968        typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1969        typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1970            _FunAlloc;
1971
1972        if (__function::__not_null(__f))
1973        {
1974            _FunAlloc __af(__a);
1975            if (sizeof(_Fun) <= sizeof(__buf_) &&
1976                is_nothrow_copy_constructible<_Fp>::value &&
1977                is_nothrow_copy_constructible<_FunAlloc>::value)
1978            {
1979                __f_ =
1980                    ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1981            }
1982            else
1983            {
1984                typedef __allocator_destructor<_FunAlloc> _Dp;
1985                unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1986                ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1987                __f_ = __hold.release();
1988            }
1989        }
1990    }
1991
1992    template <class _Fp,
1993        class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1994    _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
1995        : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
1996
1997    _LIBCPP_INLINE_VISIBILITY
1998    __value_func(const __value_func& __f)
1999    {
2000        if (__f.__f_ == nullptr)
2001            __f_ = nullptr;
2002        else if ((void*)__f.__f_ == &__f.__buf_)
2003        {
2004            __f_ = __as_base(&__buf_);
2005            __f.__f_->__clone(__f_);
2006        }
2007        else
2008            __f_ = __f.__f_->__clone();
2009    }
2010
2011    _LIBCPP_INLINE_VISIBILITY
2012    __value_func(__value_func&& __f) _NOEXCEPT
2013    {
2014        if (__f.__f_ == nullptr)
2015            __f_ = nullptr;
2016        else if ((void*)__f.__f_ == &__f.__buf_)
2017        {
2018            __f_ = __as_base(&__buf_);
2019            __f.__f_->__clone(__f_);
2020        }
2021        else
2022        {
2023            __f_ = __f.__f_;
2024            __f.__f_ = nullptr;
2025        }
2026    }
2027
2028    _LIBCPP_INLINE_VISIBILITY
2029    ~__value_func()
2030    {
2031        if ((void*)__f_ == &__buf_)
2032            __f_->destroy();
2033        else if (__f_)
2034            __f_->destroy_deallocate();
2035    }
2036
2037    _LIBCPP_INLINE_VISIBILITY
2038    __value_func& operator=(__value_func&& __f)
2039    {
2040        *this = nullptr;
2041        if (__f.__f_ == nullptr)
2042            __f_ = nullptr;
2043        else if ((void*)__f.__f_ == &__f.__buf_)
2044        {
2045            __f_ = __as_base(&__buf_);
2046            __f.__f_->__clone(__f_);
2047        }
2048        else
2049        {
2050            __f_ = __f.__f_;
2051            __f.__f_ = nullptr;
2052        }
2053        return *this;
2054    }
2055
2056    _LIBCPP_INLINE_VISIBILITY
2057    __value_func& operator=(nullptr_t)
2058    {
2059        __func* __f = __f_;
2060        __f_ = nullptr;
2061        if ((void*)__f == &__buf_)
2062            __f->destroy();
2063        else if (__f)
2064            __f->destroy_deallocate();
2065        return *this;
2066    }
2067
2068    _LIBCPP_INLINE_VISIBILITY
2069    _Rp operator()(_ArgTypes&&... __args) const
2070    {
2071        if (__f_ == nullptr)
2072            __throw_bad_function_call();
2073        return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
2074    }
2075
2076    _LIBCPP_INLINE_VISIBILITY
2077    void swap(__value_func& __f) _NOEXCEPT
2078    {
2079        if (&__f == this)
2080            return;
2081        if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
2082        {
2083            typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
2084            __func* __t = __as_base(&__tempbuf);
2085            __f_->__clone(__t);
2086            __f_->destroy();
2087            __f_ = nullptr;
2088            __f.__f_->__clone(__as_base(&__buf_));
2089            __f.__f_->destroy();
2090            __f.__f_ = nullptr;
2091            __f_ = __as_base(&__buf_);
2092            __t->__clone(__as_base(&__f.__buf_));
2093            __t->destroy();
2094            __f.__f_ = __as_base(&__f.__buf_);
2095        }
2096        else if ((void*)__f_ == &__buf_)
2097        {
2098            __f_->__clone(__as_base(&__f.__buf_));
2099            __f_->destroy();
2100            __f_ = __f.__f_;
2101            __f.__f_ = __as_base(&__f.__buf_);
2102        }
2103        else if ((void*)__f.__f_ == &__f.__buf_)
2104        {
2105            __f.__f_->__clone(__as_base(&__buf_));
2106            __f.__f_->destroy();
2107            __f.__f_ = __f_;
2108            __f_ = __as_base(&__buf_);
2109        }
2110        else
2111            _VSTD::swap(__f_, __f.__f_);
2112    }
2113
2114    _LIBCPP_INLINE_VISIBILITY
2115    explicit operator bool() const _NOEXCEPT { return __f_ != nullptr; }
2116
2117#ifndef _LIBCPP_NO_RTTI
2118    _LIBCPP_INLINE_VISIBILITY
2119    const std::type_info& target_type() const _NOEXCEPT
2120    {
2121        if (__f_ == nullptr)
2122            return typeid(void);
2123        return __f_->target_type();
2124    }
2125
2126    template <typename _Tp>
2127    _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2128    {
2129        if (__f_ == nullptr)
2130            return nullptr;
2131        return (const _Tp*)__f_->target(typeid(_Tp));
2132    }
2133#endif // _LIBCPP_NO_RTTI
2134};
2135
2136// Storage for a functor object, to be used with __policy to manage copy and
2137// destruction.
2138union __policy_storage
2139{
2140    mutable char __small[sizeof(void*) * 2];
2141    void* __large;
2142};
2143
2144// True if _Fun can safely be held in __policy_storage.__small.
2145template <typename _Fun>
2146struct __use_small_storage
2147    : public integral_constant<
2148          bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
2149                    _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
2150                    is_trivially_copy_constructible<_Fun>::value &&
2151                    is_trivially_destructible<_Fun>::value> {};
2152
2153// Policy contains information about how to copy, destroy, and move the
2154// underlying functor. You can think of it as a vtable of sorts.
2155struct __policy
2156{
2157    // Used to copy or destroy __large values. null for trivial objects.
2158    void* (*const __clone)(const void*);
2159    void (*const __destroy)(void*);
2160
2161    // True if this is the null policy (no value).
2162    const bool __is_null;
2163
2164    // The target type. May be null if RTTI is disabled.
2165    const std::type_info* const __type_info;
2166
2167    // Returns a pointer to a static policy object suitable for the functor
2168    // type.
2169    template <typename _Fun>
2170    _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
2171    {
2172        return __choose_policy<_Fun>(__use_small_storage<_Fun>());
2173    }
2174
2175    _LIBCPP_INLINE_VISIBILITY
2176    static const __policy* __create_empty()
2177    {
2178        static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
2179                                                             true,
2180#ifndef _LIBCPP_NO_RTTI
2181                                                             &typeid(void)
2182#else
2183                                                             nullptr
2184#endif
2185        };
2186        return &__policy_;
2187    }
2188
2189  private:
2190    template <typename _Fun> static void* __large_clone(const void* __s)
2191    {
2192        const _Fun* __f = static_cast<const _Fun*>(__s);
2193        return __f->__clone();
2194    }
2195
2196    template <typename _Fun>
2197    static void __large_destroy(void* __s) {
2198      _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
2199    }
2200
2201    template <typename _Fun>
2202    _LIBCPP_INLINE_VISIBILITY static const __policy*
2203    __choose_policy(/* is_small = */ false_type) {
2204      static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2205          &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
2206#ifndef _LIBCPP_NO_RTTI
2207          &typeid(typename _Fun::_Target)
2208#else
2209          nullptr
2210#endif
2211      };
2212        return &__policy_;
2213    }
2214
2215    template <typename _Fun>
2216    _LIBCPP_INLINE_VISIBILITY static const __policy*
2217        __choose_policy(/* is_small = */ true_type)
2218    {
2219        static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2220            nullptr, nullptr, false,
2221#ifndef _LIBCPP_NO_RTTI
2222            &typeid(typename _Fun::_Target)
2223#else
2224            nullptr
2225#endif
2226        };
2227        return &__policy_;
2228    }
2229};
2230
2231// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2232// faster for types that can be passed in registers.
2233template <typename _Tp>
2234using __fast_forward =
2235    typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
2236
2237// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2238
2239template <class _Fp> struct __policy_invoker;
2240
2241template <class _Rp, class... _ArgTypes>
2242struct __policy_invoker<_Rp(_ArgTypes...)>
2243{
2244    typedef _Rp (*__Call)(const __policy_storage*,
2245                          __fast_forward<_ArgTypes>...);
2246
2247    __Call __call_;
2248
2249    // Creates an invoker that throws bad_function_call.
2250    _LIBCPP_INLINE_VISIBILITY
2251    __policy_invoker() : __call_(&__call_empty) {}
2252
2253    // Creates an invoker that calls the given instance of __func.
2254    template <typename _Fun>
2255    _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2256    {
2257        return __policy_invoker(&__call_impl<_Fun>);
2258    }
2259
2260  private:
2261    _LIBCPP_INLINE_VISIBILITY
2262    explicit __policy_invoker(__Call __c) : __call_(__c) {}
2263
2264    static _Rp __call_empty(const __policy_storage*,
2265                            __fast_forward<_ArgTypes>...)
2266    {
2267        __throw_bad_function_call();
2268    }
2269
2270    template <typename _Fun>
2271    static _Rp __call_impl(const __policy_storage* __buf,
2272                           __fast_forward<_ArgTypes>... __args)
2273    {
2274        _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2275                                                ? &__buf->__small
2276                                                : __buf->__large);
2277        return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2278    }
2279};
2280
2281// __policy_func uses a __policy and __policy_invoker to create a type-erased,
2282// copyable functor.
2283
2284template <class _Fp> class __policy_func;
2285
2286template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2287{
2288    // Inline storage for small objects.
2289    __policy_storage __buf_;
2290
2291    // Calls the value stored in __buf_. This could technically be part of
2292    // policy, but storing it here eliminates a level of indirection inside
2293    // operator().
2294    typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2295    __invoker __invoker_;
2296
2297    // The policy that describes how to move / copy / destroy __buf_. Never
2298    // null, even if the function is empty.
2299    const __policy* __policy_;
2300
2301  public:
2302    _LIBCPP_INLINE_VISIBILITY
2303    __policy_func() : __policy_(__policy::__create_empty()) {}
2304
2305    template <class _Fp, class _Alloc>
2306    _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2307        : __policy_(__policy::__create_empty())
2308    {
2309        typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2310        typedef allocator_traits<_Alloc> __alloc_traits;
2311        typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2312            _FunAlloc;
2313
2314        if (__function::__not_null(__f))
2315        {
2316            __invoker_ = __invoker::template __create<_Fun>();
2317            __policy_ = __policy::__create<_Fun>();
2318
2319            _FunAlloc __af(__a);
2320            if (__use_small_storage<_Fun>())
2321            {
2322                ::new ((void*)&__buf_.__small)
2323                    _Fun(_VSTD::move(__f), _Alloc(__af));
2324            }
2325            else
2326            {
2327                typedef __allocator_destructor<_FunAlloc> _Dp;
2328                unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2329                ::new ((void*)__hold.get())
2330                    _Fun(_VSTD::move(__f), _Alloc(__af));
2331                __buf_.__large = __hold.release();
2332            }
2333        }
2334    }
2335
2336    template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2337    _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2338        : __policy_(__policy::__create_empty()) {
2339      typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2340
2341      if (__function::__not_null(__f)) {
2342        __invoker_ = __invoker::template __create<_Fun>();
2343        __policy_ = __policy::__create<_Fun>();
2344        if (__use_small_storage<_Fun>()) {
2345          ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2346        } else {
2347          __builtin_new_allocator::__holder_t __hold =
2348              __builtin_new_allocator::__allocate_type<_Fun>(1);
2349          __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f));
2350          (void)__hold.release();
2351        }
2352      }
2353    }
2354
2355    _LIBCPP_INLINE_VISIBILITY
2356    __policy_func(const __policy_func& __f)
2357        : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2358          __policy_(__f.__policy_)
2359    {
2360        if (__policy_->__clone)
2361            __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2362    }
2363
2364    _LIBCPP_INLINE_VISIBILITY
2365    __policy_func(__policy_func&& __f)
2366        : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2367          __policy_(__f.__policy_)
2368    {
2369        if (__policy_->__destroy)
2370        {
2371            __f.__policy_ = __policy::__create_empty();
2372            __f.__invoker_ = __invoker();
2373        }
2374    }
2375
2376    _LIBCPP_INLINE_VISIBILITY
2377    ~__policy_func()
2378    {
2379        if (__policy_->__destroy)
2380            __policy_->__destroy(__buf_.__large);
2381    }
2382
2383    _LIBCPP_INLINE_VISIBILITY
2384    __policy_func& operator=(__policy_func&& __f)
2385    {
2386        *this = nullptr;
2387        __buf_ = __f.__buf_;
2388        __invoker_ = __f.__invoker_;
2389        __policy_ = __f.__policy_;
2390        __f.__policy_ = __policy::__create_empty();
2391        __f.__invoker_ = __invoker();
2392        return *this;
2393    }
2394
2395    _LIBCPP_INLINE_VISIBILITY
2396    __policy_func& operator=(nullptr_t)
2397    {
2398        const __policy* __p = __policy_;
2399        __policy_ = __policy::__create_empty();
2400        __invoker_ = __invoker();
2401        if (__p->__destroy)
2402            __p->__destroy(__buf_.__large);
2403        return *this;
2404    }
2405
2406    _LIBCPP_INLINE_VISIBILITY
2407    _Rp operator()(_ArgTypes&&... __args) const
2408    {
2409        return __invoker_.__call_(_VSTD::addressof(__buf_),
2410                                  _VSTD::forward<_ArgTypes>(__args)...);
2411    }
2412
2413    _LIBCPP_INLINE_VISIBILITY
2414    void swap(__policy_func& __f)
2415    {
2416        _VSTD::swap(__invoker_, __f.__invoker_);
2417        _VSTD::swap(__policy_, __f.__policy_);
2418        _VSTD::swap(__buf_, __f.__buf_);
2419    }
2420
2421    _LIBCPP_INLINE_VISIBILITY
2422    explicit operator bool() const _NOEXCEPT
2423    {
2424        return !__policy_->__is_null;
2425    }
2426
2427#ifndef _LIBCPP_NO_RTTI
2428    _LIBCPP_INLINE_VISIBILITY
2429    const std::type_info& target_type() const _NOEXCEPT
2430    {
2431        return *__policy_->__type_info;
2432    }
2433
2434    template <typename _Tp>
2435    _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2436    {
2437        if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2438            return nullptr;
2439        if (__policy_->__clone) // Out of line storage.
2440            return reinterpret_cast<const _Tp*>(__buf_.__large);
2441        else
2442            return reinterpret_cast<const _Tp*>(&__buf_.__small);
2443    }
2444#endif // _LIBCPP_NO_RTTI
2445};
2446
2447#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
2448
2449extern "C" void *_Block_copy(const void *);
2450extern "C" void _Block_release(const void *);
2451
2452template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2453class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2454    : public  __base<_Rp(_ArgTypes...)>
2455{
2456    typedef _Rp1(^__block_type)(_ArgTypes1...);
2457    __block_type __f_;
2458
2459public:
2460    _LIBCPP_INLINE_VISIBILITY
2461    explicit __func(__block_type const& __f)
2462        : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
2463    { }
2464
2465    // [TODO] add && to save on a retain
2466
2467    _LIBCPP_INLINE_VISIBILITY
2468    explicit __func(__block_type __f, const _Alloc& /* unused */)
2469        : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
2470    { }
2471
2472    virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2473        _LIBCPP_ASSERT(false,
2474            "Block pointers are just pointers, so they should always fit into "
2475            "std::function's small buffer optimization. This function should "
2476            "never be invoked.");
2477        return nullptr;
2478    }
2479
2480    virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
2481        ::new ((void*)__p) __func(__f_);
2482    }
2483
2484    virtual void destroy() _NOEXCEPT {
2485        if (__f_)
2486            _Block_release(__f_);
2487        __f_ = 0;
2488    }
2489
2490    virtual void destroy_deallocate() _NOEXCEPT {
2491        _LIBCPP_ASSERT(false,
2492            "Block pointers are just pointers, so they should always fit into "
2493            "std::function's small buffer optimization. This function should "
2494            "never be invoked.");
2495    }
2496
2497    virtual _Rp operator()(_ArgTypes&& ... __arg) {
2498        return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
2499    }
2500
2501#ifndef _LIBCPP_NO_RTTI
2502    virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2503        if (__ti == typeid(__func::__block_type))
2504            return &__f_;
2505        return (const void*)nullptr;
2506    }
2507
2508    virtual const std::type_info& target_type() const _NOEXCEPT {
2509        return typeid(__func::__block_type);
2510    }
2511#endif // _LIBCPP_NO_RTTI
2512};
2513
2514#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
2515
2516}  // __function
2517
2518template<class _Rp, class ..._ArgTypes>
2519class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
2520#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
2521    : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2522      public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
2523#endif
2524{
2525#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
2526    typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
2527#else
2528    typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2529#endif
2530
2531    __func __f_;
2532
2533    template <class _Fp, bool = _And<
2534        _IsNotSame<__uncvref_t<_Fp>, function>,
2535        __invokable<_Fp, _ArgTypes...>
2536    >::value>
2537    struct __callable;
2538    template <class _Fp>
2539        struct __callable<_Fp, true>
2540        {
2541            static const bool value = is_void<_Rp>::value ||
2542                __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
2543                                      _Rp>::value;
2544        };
2545    template <class _Fp>
2546        struct __callable<_Fp, false>
2547        {
2548            static const bool value = false;
2549        };
2550
2551  template <class _Fp>
2552  using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
2553public:
2554    typedef _Rp result_type;
2555
2556    // construct/copy/destroy:
2557    _LIBCPP_INLINE_VISIBILITY
2558    function() _NOEXCEPT { }
2559    _LIBCPP_INLINE_VISIBILITY
2560    function(nullptr_t) _NOEXCEPT {}
2561    function(const function&);
2562    function(function&&) _NOEXCEPT;
2563    template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
2564    function(_Fp);
2565
2566#if _LIBCPP_STD_VER <= 14
2567    template<class _Alloc>
2568      _LIBCPP_INLINE_VISIBILITY
2569      function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
2570    template<class _Alloc>
2571      _LIBCPP_INLINE_VISIBILITY
2572      function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
2573    template<class _Alloc>
2574      function(allocator_arg_t, const _Alloc&, const function&);
2575    template<class _Alloc>
2576      function(allocator_arg_t, const _Alloc&, function&&);
2577    template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
2578      function(allocator_arg_t, const _Alloc& __a, _Fp __f);
2579#endif
2580
2581    function& operator=(const function&);
2582    function& operator=(function&&) _NOEXCEPT;
2583    function& operator=(nullptr_t) _NOEXCEPT;
2584    template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
2585    function& operator=(_Fp&&);
2586
2587    ~function();
2588
2589    // function modifiers:
2590    void swap(function&) _NOEXCEPT;
2591
2592#if _LIBCPP_STD_VER <= 14
2593    template<class _Fp, class _Alloc>
2594      _LIBCPP_INLINE_VISIBILITY
2595      void assign(_Fp&& __f, const _Alloc& __a)
2596        {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
2597#endif
2598
2599    // function capacity:
2600    _LIBCPP_INLINE_VISIBILITY
2601    explicit operator bool() const _NOEXCEPT {
2602      return static_cast<bool>(__f_);
2603    }
2604
2605    // deleted overloads close possible hole in the type system
2606    template<class _R2, class... _ArgTypes2>
2607      bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
2608    template<class _R2, class... _ArgTypes2>
2609      bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
2610public:
2611    // function invocation:
2612    _Rp operator()(_ArgTypes...) const;
2613
2614#ifndef _LIBCPP_NO_RTTI
2615    // function target access:
2616    const std::type_info& target_type() const _NOEXCEPT;
2617    template <typename _Tp> _Tp* target() _NOEXCEPT;
2618    template <typename _Tp> const _Tp* target() const _NOEXCEPT;
2619#endif // _LIBCPP_NO_RTTI
2620};
2621
2622#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2623template<class _Rp, class ..._Ap>
2624function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
2625
2626template<class _Fp>
2627struct __strip_signature;
2628
2629template<class _Rp, class _Gp, class ..._Ap>
2630struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
2631template<class _Rp, class _Gp, class ..._Ap>
2632struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
2633template<class _Rp, class _Gp, class ..._Ap>
2634struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
2635template<class _Rp, class _Gp, class ..._Ap>
2636struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
2637
2638template<class _Rp, class _Gp, class ..._Ap>
2639struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
2640template<class _Rp, class _Gp, class ..._Ap>
2641struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
2642template<class _Rp, class _Gp, class ..._Ap>
2643struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
2644template<class _Rp, class _Gp, class ..._Ap>
2645struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
2646
2647template<class _Rp, class _Gp, class ..._Ap>
2648struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
2649template<class _Rp, class _Gp, class ..._Ap>
2650struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
2651template<class _Rp, class _Gp, class ..._Ap>
2652struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
2653template<class _Rp, class _Gp, class ..._Ap>
2654struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
2655
2656template<class _Rp, class _Gp, class ..._Ap>
2657struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
2658template<class _Rp, class _Gp, class ..._Ap>
2659struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
2660template<class _Rp, class _Gp, class ..._Ap>
2661struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
2662template<class _Rp, class _Gp, class ..._Ap>
2663struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
2664
2665template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
2666function(_Fp) -> function<_Stripped>;
2667#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
2668
2669template<class _Rp, class ..._ArgTypes>
2670function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
2671
2672#if _LIBCPP_STD_VER <= 14
2673template<class _Rp, class ..._ArgTypes>
2674template <class _Alloc>
2675function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
2676                                     const function& __f) : __f_(__f.__f_) {}
2677#endif
2678
2679template <class _Rp, class... _ArgTypes>
2680function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
2681    : __f_(_VSTD::move(__f.__f_)) {}
2682
2683#if _LIBCPP_STD_VER <= 14
2684template<class _Rp, class ..._ArgTypes>
2685template <class _Alloc>
2686function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
2687                                      function&& __f)
2688    : __f_(_VSTD::move(__f.__f_)) {}
2689#endif
2690
2691template <class _Rp, class... _ArgTypes>
2692template <class _Fp, class>
2693function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
2694
2695#if _LIBCPP_STD_VER <= 14
2696template <class _Rp, class... _ArgTypes>
2697template <class _Fp, class _Alloc, class>
2698function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2699                                      _Fp __f)
2700    : __f_(_VSTD::move(__f), __a) {}
2701#endif
2702
2703template<class _Rp, class ..._ArgTypes>
2704function<_Rp(_ArgTypes...)>&
2705function<_Rp(_ArgTypes...)>::operator=(const function& __f)
2706{
2707    function(__f).swap(*this);
2708    return *this;
2709}
2710
2711template<class _Rp, class ..._ArgTypes>
2712function<_Rp(_ArgTypes...)>&
2713function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
2714{
2715    __f_ = _VSTD::move(__f.__f_);
2716    return *this;
2717}
2718
2719template<class _Rp, class ..._ArgTypes>
2720function<_Rp(_ArgTypes...)>&
2721function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
2722{
2723    __f_ = nullptr;
2724    return *this;
2725}
2726
2727template<class _Rp, class ..._ArgTypes>
2728template <class _Fp, class>
2729function<_Rp(_ArgTypes...)>&
2730function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
2731{
2732    function(_VSTD::forward<_Fp>(__f)).swap(*this);
2733    return *this;
2734}
2735
2736template<class _Rp, class ..._ArgTypes>
2737function<_Rp(_ArgTypes...)>::~function() {}
2738
2739template<class _Rp, class ..._ArgTypes>
2740void
2741function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
2742{
2743    __f_.swap(__f.__f_);
2744}
2745
2746template<class _Rp, class ..._ArgTypes>
2747_Rp
2748function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
2749{
2750    return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
2751}
2752
2753#ifndef _LIBCPP_NO_RTTI
2754
2755template<class _Rp, class ..._ArgTypes>
2756const std::type_info&
2757function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
2758{
2759    return __f_.target_type();
2760}
2761
2762template<class _Rp, class ..._ArgTypes>
2763template <typename _Tp>
2764_Tp*
2765function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
2766{
2767    return (_Tp*)(__f_.template target<_Tp>());
2768}
2769
2770template<class _Rp, class ..._ArgTypes>
2771template <typename _Tp>
2772const _Tp*
2773function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
2774{
2775    return __f_.template target<_Tp>();
2776}
2777
2778#endif // _LIBCPP_NO_RTTI
2779
2780template <class _Rp, class... _ArgTypes>
2781inline _LIBCPP_INLINE_VISIBILITY
2782bool
2783operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
2784
2785template <class _Rp, class... _ArgTypes>
2786inline _LIBCPP_INLINE_VISIBILITY
2787bool
2788operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
2789
2790template <class _Rp, class... _ArgTypes>
2791inline _LIBCPP_INLINE_VISIBILITY
2792bool
2793operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
2794
2795template <class _Rp, class... _ArgTypes>
2796inline _LIBCPP_INLINE_VISIBILITY
2797bool
2798operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
2799
2800template <class _Rp, class... _ArgTypes>
2801inline _LIBCPP_INLINE_VISIBILITY
2802void
2803swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
2804{return __x.swap(__y);}
2805
2806#else // _LIBCPP_CXX03_LANG
2807
2808#include <__functional_03>
2809
2810#endif
2811
2812////////////////////////////////////////////////////////////////////////////////
2813//                                  BIND
2814//==============================================================================
2815
2816template<class _Tp> struct __is_bind_expression : public false_type {};
2817template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
2818    : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2819
2820#if _LIBCPP_STD_VER > 14
2821template <class _Tp>
2822_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
2823#endif
2824
2825template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
2826template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
2827    : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2828
2829#if _LIBCPP_STD_VER > 14
2830template <class _Tp>
2831_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
2832#endif
2833
2834namespace placeholders
2835{
2836
2837template <int _Np> struct __ph {};
2838
2839#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
2840_LIBCPP_FUNC_VIS extern const __ph<1>   _1;
2841_LIBCPP_FUNC_VIS extern const __ph<2>   _2;
2842_LIBCPP_FUNC_VIS extern const __ph<3>   _3;
2843_LIBCPP_FUNC_VIS extern const __ph<4>   _4;
2844_LIBCPP_FUNC_VIS extern const __ph<5>   _5;
2845_LIBCPP_FUNC_VIS extern const __ph<6>   _6;
2846_LIBCPP_FUNC_VIS extern const __ph<7>   _7;
2847_LIBCPP_FUNC_VIS extern const __ph<8>   _8;
2848_LIBCPP_FUNC_VIS extern const __ph<9>   _9;
2849_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2850#else
2851/* _LIBCPP_INLINE_VAR */ constexpr __ph<1>   _1{};
2852/* _LIBCPP_INLINE_VAR */ constexpr __ph<2>   _2{};
2853/* _LIBCPP_INLINE_VAR */ constexpr __ph<3>   _3{};
2854/* _LIBCPP_INLINE_VAR */ constexpr __ph<4>   _4{};
2855/* _LIBCPP_INLINE_VAR */ constexpr __ph<5>   _5{};
2856/* _LIBCPP_INLINE_VAR */ constexpr __ph<6>   _6{};
2857/* _LIBCPP_INLINE_VAR */ constexpr __ph<7>   _7{};
2858/* _LIBCPP_INLINE_VAR */ constexpr __ph<8>   _8{};
2859/* _LIBCPP_INLINE_VAR */ constexpr __ph<9>   _9{};
2860/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
2861#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
2862
2863}  // placeholders
2864
2865template<int _Np>
2866struct __is_placeholder<placeholders::__ph<_Np> >
2867    : public integral_constant<int, _Np> {};
2868
2869
2870#ifndef _LIBCPP_CXX03_LANG
2871
2872template <class _Tp, class _Uj>
2873inline _LIBCPP_INLINE_VISIBILITY
2874_Tp&
2875__mu(reference_wrapper<_Tp> __t, _Uj&)
2876{
2877    return __t.get();
2878}
2879
2880template <class _Ti, class ..._Uj, size_t ..._Indx>
2881inline _LIBCPP_INLINE_VISIBILITY
2882typename __invoke_of<_Ti&, _Uj...>::type
2883__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
2884{
2885    return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
2886}
2887
2888template <class _Ti, class ..._Uj>
2889inline _LIBCPP_INLINE_VISIBILITY
2890typename _EnableIf
2891<
2892    is_bind_expression<_Ti>::value,
2893    __invoke_of<_Ti&, _Uj...>
2894>::type
2895__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2896{
2897    typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2898    return _VSTD::__mu_expand(__ti, __uj, __indices());
2899}
2900
2901template <bool IsPh, class _Ti, class _Uj>
2902struct __mu_return2 {};
2903
2904template <class _Ti, class _Uj>
2905struct __mu_return2<true, _Ti, _Uj>
2906{
2907    typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2908};
2909
2910template <class _Ti, class _Uj>
2911inline _LIBCPP_INLINE_VISIBILITY
2912typename enable_if
2913<
2914    0 < is_placeholder<_Ti>::value,
2915    typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2916>::type
2917__mu(_Ti&, _Uj& __uj)
2918{
2919    const size_t _Indx = is_placeholder<_Ti>::value - 1;
2920    return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
2921}
2922
2923template <class _Ti, class _Uj>
2924inline _LIBCPP_INLINE_VISIBILITY
2925typename enable_if
2926<
2927    !is_bind_expression<_Ti>::value &&
2928    is_placeholder<_Ti>::value == 0 &&
2929    !__is_reference_wrapper<_Ti>::value,
2930    _Ti&
2931>::type
2932__mu(_Ti& __ti, _Uj&)
2933{
2934    return __ti;
2935}
2936
2937template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2938          class _TupleUj>
2939struct __mu_return_impl;
2940
2941template <bool _Invokable, class _Ti, class ..._Uj>
2942struct __mu_return_invokable  // false
2943{
2944    typedef __nat type;
2945};
2946
2947template <class _Ti, class ..._Uj>
2948struct __mu_return_invokable<true, _Ti, _Uj...>
2949{
2950    typedef typename __invoke_of<_Ti&, _Uj...>::type type;
2951};
2952
2953template <class _Ti, class ..._Uj>
2954struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2955    : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2956{
2957};
2958
2959template <class _Ti, class _TupleUj>
2960struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
2961{
2962    typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2963                                   _TupleUj>::type&& type;
2964};
2965
2966template <class _Ti, class _TupleUj>
2967struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
2968{
2969    typedef typename _Ti::type& type;
2970};
2971
2972template <class _Ti, class _TupleUj>
2973struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
2974{
2975    typedef _Ti& type;
2976};
2977
2978template <class _Ti, class _TupleUj>
2979struct __mu_return
2980    : public __mu_return_impl<_Ti,
2981                              __is_reference_wrapper<_Ti>::value,
2982                              is_bind_expression<_Ti>::value,
2983                              0 < is_placeholder<_Ti>::value &&
2984                              is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2985                              _TupleUj>
2986{
2987};
2988
2989template <class _Fp, class _BoundArgs, class _TupleUj>
2990struct __is_valid_bind_return
2991{
2992    static const bool value = false;
2993};
2994
2995template <class _Fp, class ..._BoundArgs, class _TupleUj>
2996struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
2997{
2998    static const bool value = __invokable<_Fp,
2999                    typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
3000};
3001
3002template <class _Fp, class ..._BoundArgs, class _TupleUj>
3003struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
3004{
3005    static const bool value = __invokable<_Fp,
3006                    typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
3007};
3008
3009template <class _Fp, class _BoundArgs, class _TupleUj,
3010          bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
3011struct __bind_return;
3012
3013template <class _Fp, class ..._BoundArgs, class _TupleUj>
3014struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
3015{
3016    typedef typename __invoke_of
3017    <
3018        _Fp&,
3019        typename __mu_return
3020        <
3021            _BoundArgs,
3022            _TupleUj
3023        >::type...
3024    >::type type;
3025};
3026
3027template <class _Fp, class ..._BoundArgs, class _TupleUj>
3028struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
3029{
3030    typedef typename __invoke_of
3031    <
3032        _Fp&,
3033        typename __mu_return
3034        <
3035            const _BoundArgs,
3036            _TupleUj
3037        >::type...
3038    >::type type;
3039};
3040
3041template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
3042inline _LIBCPP_INLINE_VISIBILITY
3043typename __bind_return<_Fp, _BoundArgs, _Args>::type
3044__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
3045                _Args&& __args)
3046{
3047    return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
3048}
3049
3050template<class _Fp, class ..._BoundArgs>
3051class __bind
3052#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
3053    : public __weak_result_type<typename decay<_Fp>::type>
3054#endif
3055{
3056protected:
3057    typedef typename decay<_Fp>::type _Fd;
3058    typedef tuple<typename decay<_BoundArgs>::type...> _Td;
3059private:
3060    _Fd __f_;
3061    _Td __bound_args_;
3062
3063    typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
3064public:
3065    template <class _Gp, class ..._BA,
3066              class = typename enable_if
3067                               <
3068                                  is_constructible<_Fd, _Gp>::value &&
3069                                  !is_same<typename remove_reference<_Gp>::type,
3070                                           __bind>::value
3071                               >::type>
3072      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3073      explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
3074        : __f_(_VSTD::forward<_Gp>(__f)),
3075          __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
3076
3077    template <class ..._Args>
3078        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3079        typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
3080        operator()(_Args&& ...__args)
3081        {
3082            return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
3083                                  tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
3084        }
3085
3086    template <class ..._Args>
3087        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3088        typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
3089        operator()(_Args&& ...__args) const
3090        {
3091            return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
3092                                   tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
3093        }
3094};
3095
3096template<class _Fp, class ..._BoundArgs>
3097struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
3098
3099template<class _Rp, class _Fp, class ..._BoundArgs>
3100class __bind_r
3101    : public __bind<_Fp, _BoundArgs...>
3102{
3103    typedef __bind<_Fp, _BoundArgs...> base;
3104    typedef typename base::_Fd _Fd;
3105    typedef typename base::_Td _Td;
3106public:
3107    typedef _Rp result_type;
3108
3109
3110    template <class _Gp, class ..._BA,
3111              class = typename enable_if
3112                               <
3113                                  is_constructible<_Fd, _Gp>::value &&
3114                                  !is_same<typename remove_reference<_Gp>::type,
3115                                           __bind_r>::value
3116                               >::type>
3117      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3118      explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
3119        : base(_VSTD::forward<_Gp>(__f),
3120               _VSTD::forward<_BA>(__bound_args)...) {}
3121
3122    template <class ..._Args>
3123        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3124        typename enable_if
3125        <
3126            is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
3127                           result_type>::value || is_void<_Rp>::value,
3128            result_type
3129        >::type
3130        operator()(_Args&& ...__args)
3131        {
3132            typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3133            return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
3134        }
3135
3136    template <class ..._Args>
3137        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3138        typename enable_if
3139        <
3140            is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
3141                           result_type>::value || is_void<_Rp>::value,
3142            result_type
3143        >::type
3144        operator()(_Args&& ...__args) const
3145        {
3146            typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3147            return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
3148        }
3149};
3150
3151template<class _Rp, class _Fp, class ..._BoundArgs>
3152struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
3153
3154template<class _Fp, class ..._BoundArgs>
3155inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3156__bind<_Fp, _BoundArgs...>
3157bind(_Fp&& __f, _BoundArgs&&... __bound_args)
3158{
3159    typedef __bind<_Fp, _BoundArgs...> type;
3160    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
3161}
3162
3163template<class _Rp, class _Fp, class ..._BoundArgs>
3164inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3165__bind_r<_Rp, _Fp, _BoundArgs...>
3166bind(_Fp&& __f, _BoundArgs&&... __bound_args)
3167{
3168    typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
3169    return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
3170}
3171
3172#endif // _LIBCPP_CXX03_LANG
3173
3174#if _LIBCPP_STD_VER > 14
3175
3176template<class _Op, class _Tuple,
3177         class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
3178struct __perfect_forward_impl;
3179
3180template<class _Op, class... _Bound, size_t... _Idxs>
3181struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
3182{
3183    tuple<_Bound...> __bound_;
3184
3185    template<class... _Args>
3186    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
3187    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3188    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3189    {return           _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
3190
3191    template<class... _Args>
3192    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
3193    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3194    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3195    {return           _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
3196
3197    template<class... _Args>
3198    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
3199    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3200                                  _VSTD::forward<_Args>(__args)...)))
3201    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3202                                  _VSTD::forward<_Args>(__args)...))
3203    {return           _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3204                                  _VSTD::forward<_Args>(__args)...);}
3205
3206    template<class... _Args>
3207    _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
3208    noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3209                                  _VSTD::forward<_Args>(__args)...)))
3210    -> decltype(      _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3211                                  _VSTD::forward<_Args>(__args)...))
3212    {return           _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3213                                  _VSTD::forward<_Args>(__args)...);}
3214
3215    template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3216             class = _EnableIf<is_copy_constructible_v<_Fn>>>
3217    constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
3218        : __bound_(__other.__bound_) {}
3219
3220    template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3221             class = _EnableIf<is_move_constructible_v<_Fn>>>
3222    constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
3223        : __bound_(_VSTD::move(__other.__bound_)) {}
3224
3225    template<class... _BoundArgs>
3226    explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
3227        __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
3228};
3229
3230template<class _Op, class... _Args>
3231using __perfect_forward =
3232    __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
3233
3234struct __not_fn_op
3235{
3236    template<class... _Args>
3237    static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
3238    noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3239    -> decltype(      !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3240    { return          !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3241};
3242
3243template<class _Fn,
3244         class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
3245                           is_move_constructible_v<_Fn>>>
3246_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
3247{
3248    return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
3249}
3250
3251#endif // _LIBCPP_STD_VER > 14
3252
3253#if _LIBCPP_STD_VER > 17
3254
3255struct __bind_front_op
3256{
3257    template<class... _Args>
3258    constexpr static auto __call(_Args&&... __args)
3259    noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3260    -> decltype(      _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3261    { return          _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3262};
3263
3264template<class _Fn, class... _Args,
3265         class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
3266                                       is_move_constructible<decay_t<_Fn>>,
3267                                       is_constructible<decay_t<_Args>, _Args>...,
3268                                       is_move_constructible<decay_t<_Args>>...
3269                                       >::value>>
3270constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
3271{
3272    return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
3273                                                             _VSTD::forward<_Args>(__args)...);
3274}
3275
3276#endif // _LIBCPP_STD_VER > 17
3277
3278// struct hash<T*> in <memory>
3279
3280#if _LIBCPP_STD_VER > 14
3281
3282// default searcher
3283template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
3284class _LIBCPP_TEMPLATE_VIS default_searcher {
3285public:
3286    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3287    default_searcher(_ForwardIterator __f, _ForwardIterator __l,
3288                       _BinaryPredicate __p = _BinaryPredicate())
3289        : __first_(__f), __last_(__l), __pred_(__p) {}
3290
3291    template <typename _ForwardIterator2>
3292    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
3293    pair<_ForwardIterator2, _ForwardIterator2>
3294    operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3295    {
3296        return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
3297            typename iterator_traits<_ForwardIterator>::iterator_category(),
3298            typename iterator_traits<_ForwardIterator2>::iterator_category());
3299    }
3300
3301private:
3302    _ForwardIterator __first_;
3303    _ForwardIterator __last_;
3304    _BinaryPredicate __pred_;
3305    };
3306
3307#endif // _LIBCPP_STD_VER > 14
3308
3309#if _LIBCPP_STD_VER > 17
3310template <class _Tp>
3311using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3312
3313template <class _Tp>
3314using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3315#endif // > C++17
3316
3317#if _LIBCPP_STD_VER > 17
3318// [func.identity]
3319struct identity {
3320    template<class _Tp>
3321    _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept
3322    {
3323        return _VSTD::forward<_Tp>(__t);
3324    }
3325
3326    using is_transparent = void;
3327};
3328#endif // _LIBCPP_STD_VER > 17
3329
3330#if !defined(_LIBCPP_HAS_NO_RANGES)
3331
3332namespace ranges {
3333
3334struct equal_to {
3335  template <class _Tp, class _Up>
3336  requires equality_comparable_with<_Tp, _Up>
3337  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3338      noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
3339    return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
3340  }
3341
3342  using is_transparent = void;
3343};
3344
3345struct not_equal_to {
3346  template <class _Tp, class _Up>
3347  requires equality_comparable_with<_Tp, _Up>
3348  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3349      noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
3350    return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
3351  }
3352
3353  using is_transparent = void;
3354};
3355
3356struct greater {
3357  template <class _Tp, class _Up>
3358  requires totally_ordered_with<_Tp, _Up>
3359  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3360      noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
3361    return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
3362  }
3363
3364  using is_transparent = void;
3365};
3366
3367struct less {
3368  template <class _Tp, class _Up>
3369  requires totally_ordered_with<_Tp, _Up>
3370  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3371      noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
3372    return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
3373  }
3374
3375  using is_transparent = void;
3376};
3377
3378struct greater_equal {
3379  template <class _Tp, class _Up>
3380  requires totally_ordered_with<_Tp, _Up>
3381  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3382      noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
3383    return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
3384  }
3385
3386  using is_transparent = void;
3387};
3388
3389struct less_equal {
3390  template <class _Tp, class _Up>
3391  requires totally_ordered_with<_Tp, _Up>
3392  [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3393      noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
3394    return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
3395  }
3396
3397  using is_transparent = void;
3398};
3399
3400} // namespace ranges
3401
3402#endif // !defined(_LIBCPP_HAS_NO_RANGES)
3403
3404_LIBCPP_END_NAMESPACE_STD
3405
3406#endif // _LIBCPP_FUNCTIONAL
3407