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