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