Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------ functional ----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_FUNCTIONAL |
| 12 | #define _LIBCPP_FUNCTIONAL |
| 13 | |
| 14 | /* |
| 15 | functional synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class Arg, class Result> |
| 21 | struct unary_function |
| 22 | { |
| 23 | typedef Arg argument_type; |
| 24 | typedef Result result_type; |
| 25 | }; |
| 26 | |
| 27 | template <class Arg1, class Arg2, class Result> |
| 28 | struct binary_function |
| 29 | { |
| 30 | typedef Arg1 first_argument_type; |
| 31 | typedef Arg2 second_argument_type; |
| 32 | typedef Result result_type; |
| 33 | }; |
| 34 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 35 | template <class T> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | class reference_wrapper |
| 37 | : public unary_function<T1, R> // if wrapping a unary functor |
| 38 | : public binary_function<T1, T2, R> // if wraping a binary functor |
| 39 | { |
| 40 | public: |
| 41 | // types |
| 42 | typedef T type; |
| 43 | typedef see below result_type; // Not always defined |
| 44 | |
| 45 | // construct/copy/destroy |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 46 | reference_wrapper(T&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | reference_wrapper(T&&) = delete; // do not bind to temps |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 48 | reference_wrapper(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | |
| 50 | // assignment |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 51 | reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | |
| 53 | // access |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 54 | operator T& () const noexcept; |
| 55 | T& get() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | |
| 57 | // invoke |
| 58 | template <class... ArgTypes> |
Howard Hinnant | 23e470c | 2013-09-21 17:58:58 +0000 | [diff] [blame] | 59 | typename result_of<T&(ArgTypes&&...)>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | operator() (ArgTypes&&...) const; |
| 61 | }; |
| 62 | |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 63 | template <class T> reference_wrapper<T> ref(T& t) noexcept; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 64 | template <class T> void ref(const T&& t) = delete; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 65 | template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 67 | template <class T> reference_wrapper<const T> cref(const T& t) noexcept; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 68 | template <class T> void cref(const T&& t) = delete; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 69 | template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 70 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 71 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | struct plus : binary_function<T, T, T> |
| 73 | { |
| 74 | T operator()(const T& x, const T& y) const; |
| 75 | }; |
| 76 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 77 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 78 | struct minus : binary_function<T, T, T> |
| 79 | { |
| 80 | T operator()(const T& x, const T& y) const; |
| 81 | }; |
| 82 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 83 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | struct multiplies : binary_function<T, T, T> |
| 85 | { |
| 86 | T operator()(const T& x, const T& y) const; |
| 87 | }; |
| 88 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 89 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | struct divides : binary_function<T, T, T> |
| 91 | { |
| 92 | T operator()(const T& x, const T& y) const; |
| 93 | }; |
| 94 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 95 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 96 | struct modulus : binary_function<T, T, T> |
| 97 | { |
| 98 | T operator()(const T& x, const T& y) const; |
| 99 | }; |
| 100 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 101 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 102 | struct negate : unary_function<T, T> |
| 103 | { |
| 104 | T operator()(const T& x) const; |
| 105 | }; |
| 106 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 107 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 108 | struct equal_to : binary_function<T, T, bool> |
| 109 | { |
| 110 | bool operator()(const T& x, const T& y) const; |
| 111 | }; |
| 112 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 113 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 114 | struct not_equal_to : binary_function<T, T, bool> |
| 115 | { |
| 116 | bool operator()(const T& x, const T& y) const; |
| 117 | }; |
| 118 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 119 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | struct greater : binary_function<T, T, bool> |
| 121 | { |
| 122 | bool operator()(const T& x, const T& y) const; |
| 123 | }; |
| 124 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 125 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | struct less : binary_function<T, T, bool> |
| 127 | { |
| 128 | bool operator()(const T& x, const T& y) const; |
| 129 | }; |
| 130 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 131 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | struct greater_equal : binary_function<T, T, bool> |
| 133 | { |
| 134 | bool operator()(const T& x, const T& y) const; |
| 135 | }; |
| 136 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 137 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 138 | struct less_equal : binary_function<T, T, bool> |
| 139 | { |
| 140 | bool operator()(const T& x, const T& y) const; |
| 141 | }; |
| 142 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 143 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | struct logical_and : binary_function<T, T, bool> |
| 145 | { |
| 146 | bool operator()(const T& x, const T& y) const; |
| 147 | }; |
| 148 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 149 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 150 | struct logical_or : binary_function<T, T, bool> |
| 151 | { |
| 152 | bool operator()(const T& x, const T& y) const; |
| 153 | }; |
| 154 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 155 | template <class T> // <class T=void> in C++14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | struct logical_not : unary_function<T, bool> |
| 157 | { |
| 158 | bool operator()(const T& x) const; |
| 159 | }; |
| 160 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 161 | template <class T> // <class T=void> in C++14 |
| 162 | struct bit_and : unary_function<T, bool> |
| 163 | { |
| 164 | bool operator()(const T& x, const T& y) const; |
| 165 | }; |
| 166 | |
| 167 | template <class T> // <class T=void> in C++14 |
| 168 | struct bit_or : unary_function<T, bool> |
| 169 | { |
| 170 | bool operator()(const T& x, const T& y) const; |
| 171 | }; |
| 172 | |
| 173 | template <class T> // <class T=void> in C++14 |
| 174 | struct bit_xor : unary_function<T, bool> |
| 175 | { |
| 176 | bool operator()(const T& x, const T& y) const; |
| 177 | }; |
| 178 | |
| 179 | template <class T=void> // C++14 |
| 180 | struct bit_xor : unary_function<T, bool> |
| 181 | { |
| 182 | bool operator()(const T& x) const; |
| 183 | }; |
| 184 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 185 | template <class Predicate> |
| 186 | class unary_negate |
| 187 | : public unary_function<typename Predicate::argument_type, bool> |
| 188 | { |
| 189 | public: |
| 190 | explicit unary_negate(const Predicate& pred); |
| 191 | bool operator()(const typename Predicate::argument_type& x) const; |
| 192 | }; |
| 193 | |
| 194 | template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred); |
| 195 | |
| 196 | template <class Predicate> |
| 197 | class binary_negate |
| 198 | : public binary_function<typename Predicate::first_argument_type, |
| 199 | typename Predicate::second_argument_type, |
| 200 | bool> |
| 201 | { |
| 202 | public: |
| 203 | explicit binary_negate(const Predicate& pred); |
| 204 | bool operator()(const typename Predicate::first_argument_type& x, |
| 205 | const typename Predicate::second_argument_type& y) const; |
| 206 | }; |
| 207 | |
| 208 | template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred); |
| 209 | |
Eric Fiselier | c230822 | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 210 | template <class F> unspecified not_fn(F&& f); // C++17 |
| 211 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 212 | template<class T> struct is_bind_expression; |
| 213 | template<class T> struct is_placeholder; |
| 214 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 215 | template<class Fn, class... BoundArgs> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 216 | unspecified bind(Fn&&, BoundArgs&&...); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 217 | template<class R, class Fn, class... BoundArgs> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 218 | unspecified bind(Fn&&, BoundArgs&&...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 219 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 220 | namespace placeholders { |
| 221 | // M is the implementation-defined number of placeholders |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 222 | extern unspecified _1; |
| 223 | extern unspecified _2; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 224 | . |
| 225 | . |
| 226 | . |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 227 | extern unspecified _Mp; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | template <class Operation> |
| 231 | class binder1st |
| 232 | : public unary_function<typename Operation::second_argument_type, |
| 233 | typename Operation::result_type> |
| 234 | { |
| 235 | protected: |
| 236 | Operation op; |
| 237 | typename Operation::first_argument_type value; |
| 238 | public: |
| 239 | binder1st(const Operation& x, const typename Operation::first_argument_type y); |
| 240 | typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; |
| 241 | typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; |
| 242 | }; |
| 243 | |
| 244 | template <class Operation, class T> |
| 245 | binder1st<Operation> bind1st(const Operation& op, const T& x); |
| 246 | |
| 247 | template <class Operation> |
| 248 | class binder2nd |
| 249 | : public unary_function<typename Operation::first_argument_type, |
| 250 | typename Operation::result_type> |
| 251 | { |
| 252 | protected: |
| 253 | Operation op; |
| 254 | typename Operation::second_argument_type value; |
| 255 | public: |
| 256 | binder2nd(const Operation& x, const typename Operation::second_argument_type y); |
| 257 | typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; |
| 258 | typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; |
| 259 | }; |
| 260 | |
| 261 | template <class Operation, class T> |
| 262 | binder2nd<Operation> bind2nd(const Operation& op, const T& x); |
| 263 | |
| 264 | template <class Arg, class Result> |
| 265 | class pointer_to_unary_function : public unary_function<Arg, Result> |
| 266 | { |
| 267 | public: |
| 268 | explicit pointer_to_unary_function(Result (*f)(Arg)); |
| 269 | Result operator()(Arg x) const; |
| 270 | }; |
| 271 | |
| 272 | template <class Arg, class Result> |
| 273 | pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); |
| 274 | |
| 275 | template <class Arg1, class Arg2, class Result> |
| 276 | class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> |
| 277 | { |
| 278 | public: |
| 279 | explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); |
| 280 | Result operator()(Arg1 x, Arg2 y) const; |
| 281 | }; |
| 282 | |
| 283 | template <class Arg1, class Arg2, class Result> |
| 284 | pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); |
| 285 | |
| 286 | template<class S, class T> |
| 287 | class mem_fun_t : public unary_function<T*, S> |
| 288 | { |
| 289 | public: |
| 290 | explicit mem_fun_t(S (T::*p)()); |
| 291 | S operator()(T* p) const; |
| 292 | }; |
| 293 | |
| 294 | template<class S, class T, class A> |
| 295 | class mem_fun1_t : public binary_function<T*, A, S> |
| 296 | { |
| 297 | public: |
| 298 | explicit mem_fun1_t(S (T::*p)(A)); |
| 299 | S operator()(T* p, A x) const; |
| 300 | }; |
| 301 | |
| 302 | template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); |
| 303 | template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); |
| 304 | |
| 305 | template<class S, class T> |
| 306 | class mem_fun_ref_t : public unary_function<T, S> |
| 307 | { |
| 308 | public: |
| 309 | explicit mem_fun_ref_t(S (T::*p)()); |
| 310 | S operator()(T& p) const; |
| 311 | }; |
| 312 | |
| 313 | template<class S, class T, class A> |
| 314 | class mem_fun1_ref_t : public binary_function<T, A, S> |
| 315 | { |
| 316 | public: |
| 317 | explicit mem_fun1_ref_t(S (T::*p)(A)); |
| 318 | S operator()(T& p, A x) const; |
| 319 | }; |
| 320 | |
| 321 | template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); |
| 322 | template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); |
| 323 | |
| 324 | template <class S, class T> |
| 325 | class const_mem_fun_t : public unary_function<const T*, S> |
| 326 | { |
| 327 | public: |
| 328 | explicit const_mem_fun_t(S (T::*p)() const); |
| 329 | S operator()(const T* p) const; |
| 330 | }; |
| 331 | |
| 332 | template <class S, class T, class A> |
| 333 | class const_mem_fun1_t : public binary_function<const T*, A, S> |
| 334 | { |
| 335 | public: |
| 336 | explicit const_mem_fun1_t(S (T::*p)(A) const); |
| 337 | S operator()(const T* p, A x) const; |
| 338 | }; |
| 339 | |
| 340 | template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); |
| 341 | template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); |
| 342 | |
| 343 | template <class S, class T> |
| 344 | class const_mem_fun_ref_t : public unary_function<T, S> |
| 345 | { |
| 346 | public: |
| 347 | explicit const_mem_fun_ref_t(S (T::*p)() const); |
| 348 | S operator()(const T& p) const; |
| 349 | }; |
| 350 | |
| 351 | template <class S, class T, class A> |
| 352 | class const_mem_fun1_ref_t : public binary_function<T, A, S> |
| 353 | { |
| 354 | public: |
| 355 | explicit const_mem_fun1_ref_t(S (T::*p)(A) const); |
| 356 | S operator()(const T& p, A x) const; |
| 357 | }; |
| 358 | |
| 359 | template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); |
| 360 | template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); |
| 361 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 362 | template<class R, class T> unspecified mem_fn(R T::*); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 363 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 364 | class bad_function_call |
| 365 | : public exception |
| 366 | { |
| 367 | }; |
| 368 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 369 | template<class> class function; // undefined |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 370 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 371 | template<class R, class... ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 372 | class function<R(ArgTypes...)> |
| 373 | : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and |
| 374 | // ArgTypes contains T1 |
| 375 | : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and |
| 376 | // ArgTypes contains T1 and T2 |
| 377 | { |
| 378 | public: |
| 379 | typedef R result_type; |
| 380 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 381 | // construct/copy/destroy: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 382 | function() noexcept; |
| 383 | function(nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | function(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 385 | function(function&&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | template<class F> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | function(F); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 388 | template<Allocator Alloc> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 389 | function(allocator_arg_t, const Alloc&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | template<Allocator Alloc> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 391 | function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 392 | template<Allocator Alloc> |
| 393 | function(allocator_arg_t, const Alloc&, const function&); |
| 394 | template<Allocator Alloc> |
| 395 | function(allocator_arg_t, const Alloc&, function&&); |
| 396 | template<class F, Allocator Alloc> |
| 397 | function(allocator_arg_t, const Alloc&, F); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 398 | |
| 399 | function& operator=(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 400 | function& operator=(function&&) noexcept; |
Howard Hinnant | ad1a5cc | 2011-05-29 13:53:56 +0000 | [diff] [blame] | 401 | function& operator=(nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 402 | template<class F> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 403 | function& operator=(F&&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | template<class F> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 405 | function& operator=(reference_wrapper<F>) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 406 | |
| 407 | ~function(); |
| 408 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 409 | // function modifiers: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 410 | void swap(function&) noexcept; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 411 | template<class F, class Alloc> |
Marshall Clow | 73de880 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 412 | void assign(F&&, const Alloc&); // Removed in C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 414 | // function capacity: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 415 | explicit operator bool() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 417 | // function invocation: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | R operator()(ArgTypes...) const; |
| 419 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 420 | // function target access: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 421 | const std::type_info& target_type() const noexcept; |
| 422 | template <typename T> T* target() noexcept; |
| 423 | template <typename T> const T* target() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | }; |
| 425 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 426 | // Null pointer comparisons: |
| 427 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 428 | bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 430 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 431 | bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 432 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 433 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 434 | bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 435 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 436 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 437 | bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 438 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 439 | // specialized algorithms: |
| 440 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 441 | void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 442 | |
| 443 | template <class T> struct hash; |
| 444 | |
| 445 | template <> struct hash<bool>; |
| 446 | template <> struct hash<char>; |
| 447 | template <> struct hash<signed char>; |
| 448 | template <> struct hash<unsigned char>; |
| 449 | template <> struct hash<char16_t>; |
| 450 | template <> struct hash<char32_t>; |
| 451 | template <> struct hash<wchar_t>; |
| 452 | template <> struct hash<short>; |
| 453 | template <> struct hash<unsigned short>; |
| 454 | template <> struct hash<int>; |
| 455 | template <> struct hash<unsigned int>; |
| 456 | template <> struct hash<long>; |
| 457 | template <> struct hash<long long>; |
| 458 | template <> struct hash<unsigned long>; |
| 459 | template <> struct hash<unsigned long long>; |
| 460 | |
| 461 | template <> struct hash<float>; |
| 462 | template <> struct hash<double>; |
| 463 | template <> struct hash<long double>; |
| 464 | |
| 465 | template<class T> struct hash<T*>; |
| 466 | |
| 467 | } // std |
| 468 | |
| 469 | POLICY: For non-variadic implementations, the number of arguments is limited |
| 470 | to 3. It is hoped that the need for non-variadic implementations |
| 471 | will be minimal. |
| 472 | |
| 473 | */ |
| 474 | |
| 475 | #include <__config> |
| 476 | #include <type_traits> |
| 477 | #include <typeinfo> |
| 478 | #include <exception> |
| 479 | #include <memory> |
| 480 | #include <tuple> |
| 481 | |
| 482 | #include <__functional_base> |
| 483 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 484 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 486 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 487 | |
| 488 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 489 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 490 | #if _LIBCPP_STD_VER > 11 |
| 491 | template <class _Tp = void> |
| 492 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 493 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 494 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 495 | struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 496 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 497 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 498 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 499 | {return __x + __y;} |
| 500 | }; |
| 501 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 502 | #if _LIBCPP_STD_VER > 11 |
| 503 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 504 | struct _LIBCPP_TYPE_VIS_ONLY plus<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 505 | { |
| 506 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 507 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 508 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 509 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) |
| 510 | -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) |
| 511 | { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 512 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 513 | }; |
| 514 | #endif |
| 515 | |
| 516 | |
| 517 | #if _LIBCPP_STD_VER > 11 |
| 518 | template <class _Tp = void> |
| 519 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 521 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 522 | struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 524 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 525 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 526 | {return __x - __y;} |
| 527 | }; |
| 528 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 529 | #if _LIBCPP_STD_VER > 11 |
| 530 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 531 | struct _LIBCPP_TYPE_VIS_ONLY minus<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 532 | { |
| 533 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 534 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 535 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 536 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))) |
| 537 | -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)) |
| 538 | { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 539 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 540 | }; |
| 541 | #endif |
| 542 | |
| 543 | |
| 544 | #if _LIBCPP_STD_VER > 11 |
| 545 | template <class _Tp = void> |
| 546 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 547 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 548 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 549 | struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 551 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 552 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 553 | {return __x * __y;} |
| 554 | }; |
| 555 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 556 | #if _LIBCPP_STD_VER > 11 |
| 557 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 558 | struct _LIBCPP_TYPE_VIS_ONLY multiplies<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 559 | { |
| 560 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 561 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 562 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 563 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) |
| 564 | -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) |
| 565 | { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 566 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 567 | }; |
| 568 | #endif |
| 569 | |
| 570 | |
| 571 | #if _LIBCPP_STD_VER > 11 |
| 572 | template <class _Tp = void> |
| 573 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 574 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 575 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 576 | struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 578 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 579 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | {return __x / __y;} |
| 581 | }; |
| 582 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 583 | #if _LIBCPP_STD_VER > 11 |
| 584 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 585 | struct _LIBCPP_TYPE_VIS_ONLY divides<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 586 | { |
| 587 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 588 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 589 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 590 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) |
| 591 | -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) |
| 592 | { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 593 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 594 | }; |
| 595 | #endif |
| 596 | |
| 597 | |
| 598 | #if _LIBCPP_STD_VER > 11 |
| 599 | template <class _Tp = void> |
| 600 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 601 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 602 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 603 | struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 605 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 606 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 607 | {return __x % __y;} |
| 608 | }; |
| 609 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 610 | #if _LIBCPP_STD_VER > 11 |
| 611 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 612 | struct _LIBCPP_TYPE_VIS_ONLY modulus<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 613 | { |
| 614 | template <class _T1, class _T2> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 615 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 616 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 617 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) |
| 618 | -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) |
| 619 | { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 620 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 621 | }; |
| 622 | #endif |
| 623 | |
| 624 | |
| 625 | #if _LIBCPP_STD_VER > 11 |
| 626 | template <class _Tp = void> |
| 627 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 628 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 629 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 630 | struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 631 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 632 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 633 | _Tp operator()(const _Tp& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | {return -__x;} |
| 635 | }; |
| 636 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 637 | #if _LIBCPP_STD_VER > 11 |
| 638 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 639 | struct _LIBCPP_TYPE_VIS_ONLY negate<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 640 | { |
| 641 | template <class _Tp> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 642 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 643 | auto operator()(_Tp&& __x) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 644 | _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x))) |
| 645 | -> decltype (- _VSTD::forward<_Tp>(__x)) |
| 646 | { return - _VSTD::forward<_Tp>(__x); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 647 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 648 | }; |
| 649 | #endif |
| 650 | |
| 651 | |
| 652 | #if _LIBCPP_STD_VER > 11 |
| 653 | template <class _Tp = void> |
| 654 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 656 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 657 | struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 659 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 660 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 661 | {return __x == __y;} |
| 662 | }; |
| 663 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 664 | #if _LIBCPP_STD_VER > 11 |
| 665 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 666 | struct _LIBCPP_TYPE_VIS_ONLY equal_to<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 667 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 668 | template <class _T1, class _T2> |
| 669 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 670 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 671 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) |
| 672 | -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) |
| 673 | { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 674 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 675 | }; |
| 676 | #endif |
| 677 | |
| 678 | |
| 679 | #if _LIBCPP_STD_VER > 11 |
| 680 | template <class _Tp = void> |
| 681 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 682 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 683 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 684 | struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 685 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 686 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 687 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 688 | {return __x != __y;} |
| 689 | }; |
| 690 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 691 | #if _LIBCPP_STD_VER > 11 |
| 692 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 693 | struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 694 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 695 | template <class _T1, class _T2> |
| 696 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 697 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 698 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) |
| 699 | -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) |
| 700 | { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 701 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 702 | }; |
| 703 | #endif |
| 704 | |
| 705 | |
| 706 | #if _LIBCPP_STD_VER > 11 |
| 707 | template <class _Tp = void> |
| 708 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 709 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 710 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 711 | struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 712 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 713 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 714 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | {return __x > __y;} |
| 716 | }; |
| 717 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 718 | #if _LIBCPP_STD_VER > 11 |
| 719 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 720 | struct _LIBCPP_TYPE_VIS_ONLY greater<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 721 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 722 | template <class _T1, class _T2> |
| 723 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 724 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 725 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) |
| 726 | -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) |
| 727 | { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 728 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 729 | }; |
| 730 | #endif |
| 731 | |
| 732 | |
Howard Hinnant | 3fadda3 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 733 | // less in <__functional_base> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 734 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 735 | #if _LIBCPP_STD_VER > 11 |
| 736 | template <class _Tp = void> |
| 737 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 738 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 739 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 740 | struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 741 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 742 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 743 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 744 | {return __x >= __y;} |
| 745 | }; |
| 746 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 747 | #if _LIBCPP_STD_VER > 11 |
| 748 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 749 | struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 750 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 751 | template <class _T1, class _T2> |
| 752 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 753 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 754 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) |
| 755 | -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) |
| 756 | { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 757 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 758 | }; |
| 759 | #endif |
| 760 | |
| 761 | |
| 762 | #if _LIBCPP_STD_VER > 11 |
| 763 | template <class _Tp = void> |
| 764 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 765 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 766 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 767 | struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 768 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 769 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 770 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 771 | {return __x <= __y;} |
| 772 | }; |
| 773 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 774 | #if _LIBCPP_STD_VER > 11 |
| 775 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 776 | struct _LIBCPP_TYPE_VIS_ONLY less_equal<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 777 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 778 | template <class _T1, class _T2> |
| 779 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 780 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 781 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) |
| 782 | -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) |
| 783 | { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 784 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 785 | }; |
| 786 | #endif |
| 787 | |
| 788 | |
| 789 | #if _LIBCPP_STD_VER > 11 |
| 790 | template <class _Tp = void> |
| 791 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 792 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 793 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 794 | struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 795 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 796 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 797 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 798 | {return __x && __y;} |
| 799 | }; |
| 800 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 801 | #if _LIBCPP_STD_VER > 11 |
| 802 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 803 | struct _LIBCPP_TYPE_VIS_ONLY logical_and<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 804 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 805 | template <class _T1, class _T2> |
| 806 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 807 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 808 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) |
| 809 | -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) |
| 810 | { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 811 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 812 | }; |
| 813 | #endif |
| 814 | |
| 815 | |
| 816 | #if _LIBCPP_STD_VER > 11 |
| 817 | template <class _Tp = void> |
| 818 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 819 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 820 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 821 | struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 822 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 823 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 824 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 825 | {return __x || __y;} |
| 826 | }; |
| 827 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 828 | #if _LIBCPP_STD_VER > 11 |
| 829 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 830 | struct _LIBCPP_TYPE_VIS_ONLY logical_or<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 831 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 832 | template <class _T1, class _T2> |
| 833 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 834 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 835 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) |
| 836 | -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) |
| 837 | { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 838 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 839 | }; |
| 840 | #endif |
| 841 | |
| 842 | |
| 843 | #if _LIBCPP_STD_VER > 11 |
| 844 | template <class _Tp = void> |
| 845 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 846 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 847 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 848 | struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 849 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 850 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 851 | bool operator()(const _Tp& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 852 | {return !__x;} |
| 853 | }; |
| 854 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 855 | #if _LIBCPP_STD_VER > 11 |
| 856 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 857 | struct _LIBCPP_TYPE_VIS_ONLY logical_not<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 858 | { |
| 859 | template <class _Tp> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 860 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 861 | auto operator()(_Tp&& __x) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 862 | _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x))) |
| 863 | -> decltype (!_VSTD::forward<_Tp>(__x)) |
| 864 | { return !_VSTD::forward<_Tp>(__x); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 865 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 866 | }; |
| 867 | #endif |
| 868 | |
| 869 | |
| 870 | #if _LIBCPP_STD_VER > 11 |
| 871 | template <class _Tp = void> |
| 872 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 873 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 874 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 875 | struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 876 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 877 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 878 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 879 | {return __x & __y;} |
| 880 | }; |
| 881 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 882 | #if _LIBCPP_STD_VER > 11 |
| 883 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 884 | struct _LIBCPP_TYPE_VIS_ONLY bit_and<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 885 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 886 | template <class _T1, class _T2> |
| 887 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 888 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 889 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) |
| 890 | -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) |
| 891 | { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 892 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 893 | }; |
| 894 | #endif |
| 895 | |
| 896 | |
| 897 | #if _LIBCPP_STD_VER > 11 |
| 898 | template <class _Tp = void> |
| 899 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 900 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 901 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 902 | struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 903 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 904 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 905 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 906 | {return __x | __y;} |
| 907 | }; |
| 908 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 909 | #if _LIBCPP_STD_VER > 11 |
| 910 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 911 | struct _LIBCPP_TYPE_VIS_ONLY bit_or<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 912 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 913 | template <class _T1, class _T2> |
| 914 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 915 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 916 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) |
| 917 | -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) |
| 918 | { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 919 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 920 | }; |
| 921 | #endif |
| 922 | |
| 923 | |
| 924 | #if _LIBCPP_STD_VER > 11 |
| 925 | template <class _Tp = void> |
| 926 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 927 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 928 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 929 | struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 930 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 931 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 932 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 933 | {return __x ^ __y;} |
| 934 | }; |
| 935 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 936 | #if _LIBCPP_STD_VER > 11 |
| 937 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 938 | struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 939 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 940 | template <class _T1, class _T2> |
| 941 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 942 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 943 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) |
| 944 | -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) |
| 945 | { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 946 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 947 | }; |
| 948 | #endif |
| 949 | |
| 950 | |
| 951 | #if _LIBCPP_STD_VER > 11 |
| 952 | template <class _Tp = void> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 953 | struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 954 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 955 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 956 | _Tp operator()(const _Tp& __x) const |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 957 | {return ~__x;} |
| 958 | }; |
| 959 | |
| 960 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 961 | struct _LIBCPP_TYPE_VIS_ONLY bit_not<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 962 | { |
| 963 | template <class _Tp> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 964 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 965 | auto operator()(_Tp&& __x) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 966 | _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x))) |
| 967 | -> decltype (~_VSTD::forward<_Tp>(__x)) |
| 968 | { return ~_VSTD::forward<_Tp>(__x); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 969 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 970 | }; |
| 971 | #endif |
| 972 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 973 | template <class _Predicate> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 974 | class _LIBCPP_TYPE_VIS_ONLY unary_negate |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 975 | : public unary_function<typename _Predicate::argument_type, bool> |
| 976 | { |
| 977 | _Predicate __pred_; |
| 978 | public: |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 979 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 980 | explicit unary_negate(const _Predicate& __pred) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 981 | : __pred_(__pred) {} |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 982 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 983 | bool operator()(const typename _Predicate::argument_type& __x) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 984 | {return !__pred_(__x);} |
| 985 | }; |
| 986 | |
| 987 | template <class _Predicate> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 988 | inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 989 | unary_negate<_Predicate> |
| 990 | not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} |
| 991 | |
| 992 | template <class _Predicate> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 993 | class _LIBCPP_TYPE_VIS_ONLY binary_negate |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | : public binary_function<typename _Predicate::first_argument_type, |
| 995 | typename _Predicate::second_argument_type, |
| 996 | bool> |
| 997 | { |
| 998 | _Predicate __pred_; |
| 999 | public: |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1000 | _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 1001 | binary_negate(const _Predicate& __pred) : __pred_(__pred) {} |
| 1002 | |
| 1003 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1004 | bool operator()(const typename _Predicate::first_argument_type& __x, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1005 | const typename _Predicate::second_argument_type& __y) const |
| 1006 | {return !__pred_(__x, __y);} |
| 1007 | }; |
| 1008 | |
| 1009 | template <class _Predicate> |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1010 | inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1011 | binary_negate<_Predicate> |
| 1012 | not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} |
| 1013 | |
| 1014 | template <class __Operation> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1015 | class _LIBCPP_TYPE_VIS_ONLY binder1st |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1016 | : public unary_function<typename __Operation::second_argument_type, |
| 1017 | typename __Operation::result_type> |
| 1018 | { |
| 1019 | protected: |
| 1020 | __Operation op; |
| 1021 | typename __Operation::first_argument_type value; |
| 1022 | public: |
| 1023 | _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, |
| 1024 | const typename __Operation::first_argument_type __y) |
| 1025 | : op(__x), value(__y) {} |
| 1026 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1027 | (typename __Operation::second_argument_type& __x) const |
| 1028 | {return op(value, __x);} |
| 1029 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1030 | (const typename __Operation::second_argument_type& __x) const |
| 1031 | {return op(value, __x);} |
| 1032 | }; |
| 1033 | |
| 1034 | template <class __Operation, class _Tp> |
| 1035 | inline _LIBCPP_INLINE_VISIBILITY |
| 1036 | binder1st<__Operation> |
| 1037 | bind1st(const __Operation& __op, const _Tp& __x) |
| 1038 | {return binder1st<__Operation>(__op, __x);} |
| 1039 | |
| 1040 | template <class __Operation> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1041 | class _LIBCPP_TYPE_VIS_ONLY binder2nd |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1042 | : public unary_function<typename __Operation::first_argument_type, |
| 1043 | typename __Operation::result_type> |
| 1044 | { |
| 1045 | protected: |
| 1046 | __Operation op; |
| 1047 | typename __Operation::second_argument_type value; |
| 1048 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1049 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1050 | binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) |
| 1051 | : op(__x), value(__y) {} |
| 1052 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1053 | ( typename __Operation::first_argument_type& __x) const |
| 1054 | {return op(__x, value);} |
| 1055 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1056 | (const typename __Operation::first_argument_type& __x) const |
| 1057 | {return op(__x, value);} |
| 1058 | }; |
| 1059 | |
| 1060 | template <class __Operation, class _Tp> |
| 1061 | inline _LIBCPP_INLINE_VISIBILITY |
| 1062 | binder2nd<__Operation> |
| 1063 | bind2nd(const __Operation& __op, const _Tp& __x) |
| 1064 | {return binder2nd<__Operation>(__op, __x);} |
| 1065 | |
| 1066 | template <class _Arg, class _Result> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1067 | class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1068 | : public unary_function<_Arg, _Result> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1069 | { |
| 1070 | _Result (*__f_)(_Arg); |
| 1071 | public: |
| 1072 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) |
| 1073 | : __f_(__f) {} |
| 1074 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const |
| 1075 | {return __f_(__x);} |
| 1076 | }; |
| 1077 | |
| 1078 | template <class _Arg, class _Result> |
| 1079 | inline _LIBCPP_INLINE_VISIBILITY |
| 1080 | pointer_to_unary_function<_Arg,_Result> |
| 1081 | ptr_fun(_Result (*__f)(_Arg)) |
| 1082 | {return pointer_to_unary_function<_Arg,_Result>(__f);} |
| 1083 | |
| 1084 | template <class _Arg1, class _Arg2, class _Result> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1085 | class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1086 | : public binary_function<_Arg1, _Arg2, _Result> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1087 | { |
| 1088 | _Result (*__f_)(_Arg1, _Arg2); |
| 1089 | public: |
| 1090 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) |
| 1091 | : __f_(__f) {} |
| 1092 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const |
| 1093 | {return __f_(__x, __y);} |
| 1094 | }; |
| 1095 | |
| 1096 | template <class _Arg1, class _Arg2, class _Result> |
| 1097 | inline _LIBCPP_INLINE_VISIBILITY |
| 1098 | pointer_to_binary_function<_Arg1,_Arg2,_Result> |
| 1099 | ptr_fun(_Result (*__f)(_Arg1,_Arg2)) |
| 1100 | {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} |
| 1101 | |
| 1102 | template<class _Sp, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1103 | class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1104 | { |
| 1105 | _Sp (_Tp::*__p_)(); |
| 1106 | public: |
| 1107 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) |
| 1108 | : __p_(__p) {} |
| 1109 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const |
| 1110 | {return (__p->*__p_)();} |
| 1111 | }; |
| 1112 | |
| 1113 | template<class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1114 | class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1115 | { |
| 1116 | _Sp (_Tp::*__p_)(_Ap); |
| 1117 | public: |
| 1118 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) |
| 1119 | : __p_(__p) {} |
| 1120 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const |
| 1121 | {return (__p->*__p_)(__x);} |
| 1122 | }; |
| 1123 | |
| 1124 | template<class _Sp, class _Tp> |
| 1125 | inline _LIBCPP_INLINE_VISIBILITY |
| 1126 | mem_fun_t<_Sp,_Tp> |
| 1127 | mem_fun(_Sp (_Tp::*__f)()) |
| 1128 | {return mem_fun_t<_Sp,_Tp>(__f);} |
| 1129 | |
| 1130 | template<class _Sp, class _Tp, class _Ap> |
| 1131 | inline _LIBCPP_INLINE_VISIBILITY |
| 1132 | mem_fun1_t<_Sp,_Tp,_Ap> |
| 1133 | mem_fun(_Sp (_Tp::*__f)(_Ap)) |
| 1134 | {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 1135 | |
| 1136 | template<class _Sp, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1137 | class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1138 | { |
| 1139 | _Sp (_Tp::*__p_)(); |
| 1140 | public: |
| 1141 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) |
| 1142 | : __p_(__p) {} |
| 1143 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const |
| 1144 | {return (__p.*__p_)();} |
| 1145 | }; |
| 1146 | |
| 1147 | template<class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1148 | class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1149 | { |
| 1150 | _Sp (_Tp::*__p_)(_Ap); |
| 1151 | public: |
| 1152 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) |
| 1153 | : __p_(__p) {} |
| 1154 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const |
| 1155 | {return (__p.*__p_)(__x);} |
| 1156 | }; |
| 1157 | |
| 1158 | template<class _Sp, class _Tp> |
| 1159 | inline _LIBCPP_INLINE_VISIBILITY |
| 1160 | mem_fun_ref_t<_Sp,_Tp> |
| 1161 | mem_fun_ref(_Sp (_Tp::*__f)()) |
| 1162 | {return mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 1163 | |
| 1164 | template<class _Sp, class _Tp, class _Ap> |
| 1165 | inline _LIBCPP_INLINE_VISIBILITY |
| 1166 | mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 1167 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) |
| 1168 | {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 1169 | |
| 1170 | template <class _Sp, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1171 | class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1172 | { |
| 1173 | _Sp (_Tp::*__p_)() const; |
| 1174 | public: |
| 1175 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) |
| 1176 | : __p_(__p) {} |
| 1177 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const |
| 1178 | {return (__p->*__p_)();} |
| 1179 | }; |
| 1180 | |
| 1181 | template <class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1182 | class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 | { |
| 1184 | _Sp (_Tp::*__p_)(_Ap) const; |
| 1185 | public: |
| 1186 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) |
| 1187 | : __p_(__p) {} |
| 1188 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const |
| 1189 | {return (__p->*__p_)(__x);} |
| 1190 | }; |
| 1191 | |
| 1192 | template <class _Sp, class _Tp> |
| 1193 | inline _LIBCPP_INLINE_VISIBILITY |
| 1194 | const_mem_fun_t<_Sp,_Tp> |
| 1195 | mem_fun(_Sp (_Tp::*__f)() const) |
| 1196 | {return const_mem_fun_t<_Sp,_Tp>(__f);} |
| 1197 | |
| 1198 | template <class _Sp, class _Tp, class _Ap> |
| 1199 | inline _LIBCPP_INLINE_VISIBILITY |
| 1200 | const_mem_fun1_t<_Sp,_Tp,_Ap> |
| 1201 | mem_fun(_Sp (_Tp::*__f)(_Ap) const) |
| 1202 | {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 1203 | |
| 1204 | template <class _Sp, class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1205 | class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1206 | { |
| 1207 | _Sp (_Tp::*__p_)() const; |
| 1208 | public: |
| 1209 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) |
| 1210 | : __p_(__p) {} |
| 1211 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const |
| 1212 | {return (__p.*__p_)();} |
| 1213 | }; |
| 1214 | |
| 1215 | template <class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1216 | class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1217 | : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1218 | { |
| 1219 | _Sp (_Tp::*__p_)(_Ap) const; |
| 1220 | public: |
| 1221 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) |
| 1222 | : __p_(__p) {} |
| 1223 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const |
| 1224 | {return (__p.*__p_)(__x);} |
| 1225 | }; |
| 1226 | |
| 1227 | template <class _Sp, class _Tp> |
| 1228 | inline _LIBCPP_INLINE_VISIBILITY |
| 1229 | const_mem_fun_ref_t<_Sp,_Tp> |
| 1230 | mem_fun_ref(_Sp (_Tp::*__f)() const) |
| 1231 | {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 1232 | |
| 1233 | template <class _Sp, class _Tp, class _Ap> |
| 1234 | inline _LIBCPP_INLINE_VISIBILITY |
| 1235 | const_mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 1236 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) |
| 1237 | {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 1238 | |
Eric Fiselier | 45f63bc | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1239 | //////////////////////////////////////////////////////////////////////////////// |
| 1240 | // MEMFUN |
| 1241 | //============================================================================== |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1242 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1243 | template <class _Tp> |
| 1244 | class __mem_fn |
| 1245 | : public __weak_result_type<_Tp> |
| 1246 | { |
| 1247 | public: |
| 1248 | // types |
| 1249 | typedef _Tp type; |
| 1250 | private: |
| 1251 | type __f_; |
| 1252 | |
| 1253 | public: |
Marshall Clow | fb7b97c | 2015-10-25 20:12:16 +0000 | [diff] [blame] | 1254 | _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1255 | |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1256 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1257 | // invoke |
| 1258 | template <class... _ArgTypes> |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1259 | _LIBCPP_INLINE_VISIBILITY |
| 1260 | typename __invoke_return<type, _ArgTypes...>::type |
| 1261 | operator() (_ArgTypes&&... __args) const { |
| 1262 | return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); |
| 1263 | } |
| 1264 | #else |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1265 | |
| 1266 | template <class _A0> |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1267 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1268 | typename __invoke_return0<type, _A0>::type |
| 1269 | operator() (_A0& __a0) const { |
| 1270 | return __invoke(__f_, __a0); |
| 1271 | } |
| 1272 | |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1273 | template <class _A0> |
| 1274 | _LIBCPP_INLINE_VISIBILITY |
| 1275 | typename __invoke_return0<type, _A0 const>::type |
| 1276 | operator() (_A0 const& __a0) const { |
| 1277 | return __invoke(__f_, __a0); |
| 1278 | } |
| 1279 | |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1280 | template <class _A0, class _A1> |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1281 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1282 | typename __invoke_return1<type, _A0, _A1>::type |
| 1283 | operator() (_A0& __a0, _A1& __a1) const { |
| 1284 | return __invoke(__f_, __a0, __a1); |
| 1285 | } |
| 1286 | |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1287 | template <class _A0, class _A1> |
| 1288 | _LIBCPP_INLINE_VISIBILITY |
| 1289 | typename __invoke_return1<type, _A0 const, _A1>::type |
| 1290 | operator() (_A0 const& __a0, _A1& __a1) const { |
| 1291 | return __invoke(__f_, __a0, __a1); |
| 1292 | } |
| 1293 | |
| 1294 | template <class _A0, class _A1> |
| 1295 | _LIBCPP_INLINE_VISIBILITY |
| 1296 | typename __invoke_return1<type, _A0, _A1 const>::type |
| 1297 | operator() (_A0& __a0, _A1 const& __a1) const { |
| 1298 | return __invoke(__f_, __a0, __a1); |
| 1299 | } |
| 1300 | |
| 1301 | template <class _A0, class _A1> |
| 1302 | _LIBCPP_INLINE_VISIBILITY |
| 1303 | typename __invoke_return1<type, _A0 const, _A1 const>::type |
| 1304 | operator() (_A0 const& __a0, _A1 const& __a1) const { |
| 1305 | return __invoke(__f_, __a0, __a1); |
| 1306 | } |
| 1307 | |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1308 | template <class _A0, class _A1, class _A2> |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1309 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1310 | typename __invoke_return2<type, _A0, _A1, _A2>::type |
| 1311 | operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { |
| 1312 | return __invoke(__f_, __a0, __a1, __a2); |
| 1313 | } |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1314 | |
| 1315 | template <class _A0, class _A1, class _A2> |
| 1316 | _LIBCPP_INLINE_VISIBILITY |
| 1317 | typename __invoke_return2<type, _A0 const, _A1, _A2>::type |
| 1318 | operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { |
| 1319 | return __invoke(__f_, __a0, __a1, __a2); |
| 1320 | } |
| 1321 | |
| 1322 | template <class _A0, class _A1, class _A2> |
| 1323 | _LIBCPP_INLINE_VISIBILITY |
| 1324 | typename __invoke_return2<type, _A0, _A1 const, _A2>::type |
| 1325 | operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { |
| 1326 | return __invoke(__f_, __a0, __a1, __a2); |
| 1327 | } |
| 1328 | |
| 1329 | template <class _A0, class _A1, class _A2> |
| 1330 | _LIBCPP_INLINE_VISIBILITY |
| 1331 | typename __invoke_return2<type, _A0, _A1, _A2 const>::type |
| 1332 | operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { |
| 1333 | return __invoke(__f_, __a0, __a1, __a2); |
| 1334 | } |
| 1335 | |
| 1336 | template <class _A0, class _A1, class _A2> |
| 1337 | _LIBCPP_INLINE_VISIBILITY |
| 1338 | typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type |
| 1339 | operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { |
| 1340 | return __invoke(__f_, __a0, __a1, __a2); |
| 1341 | } |
| 1342 | |
| 1343 | template <class _A0, class _A1, class _A2> |
| 1344 | _LIBCPP_INLINE_VISIBILITY |
| 1345 | typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type |
| 1346 | operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { |
| 1347 | return __invoke(__f_, __a0, __a1, __a2); |
| 1348 | } |
| 1349 | |
| 1350 | template <class _A0, class _A1, class _A2> |
| 1351 | _LIBCPP_INLINE_VISIBILITY |
| 1352 | typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type |
| 1353 | operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { |
| 1354 | return __invoke(__f_, __a0, __a1, __a2); |
| 1355 | } |
| 1356 | |
| 1357 | template <class _A0, class _A1, class _A2> |
| 1358 | _LIBCPP_INLINE_VISIBILITY |
| 1359 | typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type |
| 1360 | operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { |
| 1361 | return __invoke(__f_, __a0, __a1, __a2); |
| 1362 | } |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1363 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1364 | }; |
| 1365 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1366 | template<class _Rp, class _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1367 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1368 | __mem_fn<_Rp _Tp::*> |
Marshall Clow | fb7b97c | 2015-10-25 20:12:16 +0000 | [diff] [blame] | 1369 | mem_fn(_Rp _Tp::* __pm) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1370 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1371 | return __mem_fn<_Rp _Tp::*>(__pm); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Eric Fiselier | 45f63bc | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1374 | //////////////////////////////////////////////////////////////////////////////// |
| 1375 | // FUNCTION |
| 1376 | //============================================================================== |
| 1377 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1378 | // bad_function_call |
| 1379 | |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1380 | class _LIBCPP_EXCEPTION_ABI bad_function_call |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1381 | : public exception |
| 1382 | { |
| 1383 | }; |
| 1384 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1385 | template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1386 | |
| 1387 | namespace __function |
| 1388 | { |
| 1389 | |
Eric Fiselier | 45f63bc | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1390 | template<class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1391 | struct __maybe_derive_from_unary_function |
| 1392 | { |
| 1393 | }; |
| 1394 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1395 | template<class _Rp, class _A1> |
| 1396 | struct __maybe_derive_from_unary_function<_Rp(_A1)> |
| 1397 | : public unary_function<_A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1398 | { |
| 1399 | }; |
| 1400 | |
Eric Fiselier | 45f63bc | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1401 | template<class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1402 | struct __maybe_derive_from_binary_function |
| 1403 | { |
| 1404 | }; |
| 1405 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1406 | template<class _Rp, class _A1, class _A2> |
| 1407 | struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> |
| 1408 | : public binary_function<_A1, _A2, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1409 | { |
| 1410 | }; |
| 1411 | |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1412 | template <class _Fp> |
| 1413 | _LIBCPP_INLINE_VISIBILITY |
| 1414 | bool __not_null(_Fp const&) { return true; } |
| 1415 | |
| 1416 | template <class _Fp> |
| 1417 | _LIBCPP_INLINE_VISIBILITY |
| 1418 | bool __not_null(_Fp* __ptr) { return __ptr; } |
| 1419 | |
| 1420 | template <class _Ret, class _Class> |
| 1421 | _LIBCPP_INLINE_VISIBILITY |
| 1422 | bool __not_null(_Ret _Class::*__ptr) { return __ptr; } |
| 1423 | |
| 1424 | template <class _Fp> |
| 1425 | _LIBCPP_INLINE_VISIBILITY |
| 1426 | bool __not_null(function<_Fp> const& __f) { return !!__f; } |
| 1427 | |
Eric Fiselier | 45f63bc | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1428 | } // namespace __function |
| 1429 | |
| 1430 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1431 | |
| 1432 | namespace __function { |
| 1433 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1434 | template<class _Fp> class __base; |
| 1435 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1436 | template<class _Rp, class ..._ArgTypes> |
| 1437 | class __base<_Rp(_ArgTypes...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | { |
| 1439 | __base(const __base&); |
| 1440 | __base& operator=(const __base&); |
| 1441 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1442 | _LIBCPP_INLINE_VISIBILITY __base() {} |
| 1443 | _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1444 | virtual __base* __clone() const = 0; |
| 1445 | virtual void __clone(__base*) const = 0; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1446 | virtual void destroy() _NOEXCEPT = 0; |
| 1447 | virtual void destroy_deallocate() _NOEXCEPT = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1448 | virtual _Rp operator()(_ArgTypes&& ...) = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1449 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1450 | virtual const void* target(const type_info&) const _NOEXCEPT = 0; |
| 1451 | virtual const std::type_info& target_type() const _NOEXCEPT = 0; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1452 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1453 | }; |
| 1454 | |
| 1455 | template<class _FD, class _Alloc, class _FB> class __func; |
| 1456 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1457 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1458 | class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> |
| 1459 | : public __base<_Rp(_ArgTypes...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1460 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1461 | __compressed_pair<_Fp, _Alloc> __f_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1463 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4a13b2d | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1464 | explicit __func(_Fp&& __f) |
| 1465 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), |
| 1466 | _VSTD::forward_as_tuple()) {} |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1467 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4a13b2d | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1468 | explicit __func(const _Fp& __f, const _Alloc& __a) |
| 1469 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), |
| 1470 | _VSTD::forward_as_tuple(__a)) {} |
| 1471 | |
| 1472 | _LIBCPP_INLINE_VISIBILITY |
| 1473 | explicit __func(const _Fp& __f, _Alloc&& __a) |
| 1474 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), |
| 1475 | _VSTD::forward_as_tuple(_VSTD::move(__a))) {} |
| 1476 | |
| 1477 | _LIBCPP_INLINE_VISIBILITY |
| 1478 | explicit __func(_Fp&& __f, _Alloc&& __a) |
| 1479 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), |
| 1480 | _VSTD::forward_as_tuple(_VSTD::move(__a))) {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1481 | virtual __base<_Rp(_ArgTypes...)>* __clone() const; |
| 1482 | virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1483 | virtual void destroy() _NOEXCEPT; |
| 1484 | virtual void destroy_deallocate() _NOEXCEPT; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1485 | virtual _Rp operator()(_ArgTypes&& ... __arg); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1486 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1487 | virtual const void* target(const type_info&) const _NOEXCEPT; |
| 1488 | virtual const std::type_info& target_type() const _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1489 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1490 | }; |
| 1491 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1492 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1493 | __base<_Rp(_ArgTypes...)>* |
| 1494 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1495 | { |
Eric Fiselier | 71aa376 | 2015-03-18 22:56:50 +0000 | [diff] [blame] | 1496 | typedef allocator_traits<_Alloc> __alloc_traits; |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1497 | typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1498 | _Ap __a(__f_.second()); |
| 1499 | typedef __allocator_destructor<_Ap> _Dp; |
| 1500 | unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1501 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 1502 | return __hold.release(); |
| 1503 | } |
| 1504 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1505 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1506 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1507 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1508 | { |
| 1509 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 1510 | } |
| 1511 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1512 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1513 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1514 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1515 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1516 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1519 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1520 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1521 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1522 | { |
Eric Fiselier | 71aa376 | 2015-03-18 22:56:50 +0000 | [diff] [blame] | 1523 | typedef allocator_traits<_Alloc> __alloc_traits; |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1524 | typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1525 | _Ap __a(__f_.second()); |
| 1526 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1527 | __a.deallocate(this, 1); |
| 1528 | } |
| 1529 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1530 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1531 | _Rp |
| 1532 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1533 | { |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 1534 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 1535 | return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1538 | #ifndef _LIBCPP_NO_RTTI |
| 1539 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1540 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1541 | const void* |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1542 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1543 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1544 | if (__ti == typeid(_Fp)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1545 | return &__f_.first(); |
| 1546 | return (const void*)0; |
| 1547 | } |
| 1548 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1549 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1550 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1551 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1552 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1553 | return typeid(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1556 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1557 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1558 | } // __function |
| 1559 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1560 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1561 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1562 | : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, |
| 1563 | public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1564 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1565 | typedef __function::__base<_Rp(_ArgTypes...)> __base; |
Howard Hinnant | 78f0de2 | 2013-01-21 17:26:55 +0000 | [diff] [blame] | 1566 | typename aligned_storage<3*sizeof(void*)>::type __buf_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1567 | __base* __f_; |
| 1568 | |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1569 | _LIBCPP_NO_CFI static __base *__as_base(void *p) { |
| 1570 | return reinterpret_cast<__base*>(p); |
| 1571 | } |
| 1572 | |
Howard Hinnant | e41f475 | 2012-07-20 18:56:07 +0000 | [diff] [blame] | 1573 | template <class _Fp, bool = !is_same<_Fp, function>::value && |
| 1574 | __invokable<_Fp&, _ArgTypes...>::value> |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1575 | struct __callable; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1576 | template <class _Fp> |
| 1577 | struct __callable<_Fp, true> |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1578 | { |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 1579 | static const bool value = is_same<void, _Rp>::value || |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1580 | is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, |
| 1581 | _Rp>::value; |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1582 | }; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1583 | template <class _Fp> |
| 1584 | struct __callable<_Fp, false> |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1585 | { |
| 1586 | static const bool value = false; |
| 1587 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1588 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1589 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1590 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1591 | // construct/copy/destroy: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1592 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1593 | function() _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1594 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1595 | function(nullptr_t) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1596 | function(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1597 | function(function&&) _NOEXCEPT; |
Eric Fiselier | 16ed718 | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 1598 | template<class _Fp, class = typename enable_if< |
| 1599 | __callable<_Fp>::value && !is_same<_Fp, function>::value |
| 1600 | >::type> |
| 1601 | function(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1602 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1603 | template<class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1604 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1605 | function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1606 | template<class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1607 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1608 | function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1609 | template<class _Alloc> |
| 1610 | function(allocator_arg_t, const _Alloc&, const function&); |
| 1611 | template<class _Alloc> |
| 1612 | function(allocator_arg_t, const _Alloc&, function&&); |
Eric Fiselier | 16ed718 | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 1613 | template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type> |
| 1614 | function(allocator_arg_t, const _Alloc& __a, _Fp __f); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1615 | |
| 1616 | function& operator=(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1617 | function& operator=(function&&) _NOEXCEPT; |
| 1618 | function& operator=(nullptr_t) _NOEXCEPT; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1619 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1620 | typename enable_if |
| 1621 | < |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 1622 | __callable<typename decay<_Fp>::type>::value && |
| 1623 | !is_same<typename remove_reference<_Fp>::type, function>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1624 | function& |
| 1625 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1626 | operator=(_Fp&&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1627 | |
| 1628 | ~function(); |
| 1629 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1630 | // function modifiers: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1631 | void swap(function&) _NOEXCEPT; |
Marshall Clow | 73de880 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 1632 | |
| 1633 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1634 | template<class _Fp, class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1635 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1636 | void assign(_Fp&& __f, const _Alloc& __a) |
| 1637 | {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} |
Marshall Clow | 73de880 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 1638 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1639 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1640 | // function capacity: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1641 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7786188 | 2012-02-21 21:46:43 +0000 | [diff] [blame] | 1642 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1644 | // deleted overloads close possible hole in the type system |
| 1645 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | a0f1dc9 | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 1646 | bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1647 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | a0f1dc9 | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 1648 | bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1649 | public: |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1650 | // function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1651 | _Rp operator()(_ArgTypes...) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1652 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1653 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1654 | // function target access: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1655 | const std::type_info& target_type() const _NOEXCEPT; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1656 | template <typename _Tp> _Tp* target() _NOEXCEPT; |
| 1657 | template <typename _Tp> const _Tp* target() const _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1658 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1659 | }; |
| 1660 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1661 | template<class _Rp, class ..._ArgTypes> |
| 1662 | function<_Rp(_ArgTypes...)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1663 | { |
| 1664 | if (__f.__f_ == 0) |
| 1665 | __f_ = 0; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1666 | else if ((void *)__f.__f_ == &__f.__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1667 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1668 | __f_ = __as_base(&__buf_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1669 | __f.__f_->__clone(__f_); |
| 1670 | } |
| 1671 | else |
| 1672 | __f_ = __f.__f_->__clone(); |
| 1673 | } |
| 1674 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1675 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1676 | template <class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1677 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1678 | const function& __f) |
| 1679 | { |
| 1680 | if (__f.__f_ == 0) |
| 1681 | __f_ = 0; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1682 | else if ((void *)__f.__f_ == &__f.__buf_) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1683 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1684 | __f_ = __as_base(&__buf_); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1685 | __f.__f_->__clone(__f_); |
| 1686 | } |
| 1687 | else |
| 1688 | __f_ = __f.__f_->__clone(); |
| 1689 | } |
| 1690 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1691 | template<class _Rp, class ..._ArgTypes> |
| 1692 | function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1693 | { |
| 1694 | if (__f.__f_ == 0) |
| 1695 | __f_ = 0; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1696 | else if ((void *)__f.__f_ == &__f.__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1697 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1698 | __f_ = __as_base(&__buf_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1699 | __f.__f_->__clone(__f_); |
| 1700 | } |
| 1701 | else |
| 1702 | { |
| 1703 | __f_ = __f.__f_; |
| 1704 | __f.__f_ = 0; |
| 1705 | } |
| 1706 | } |
| 1707 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1708 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1709 | template <class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1710 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1711 | function&& __f) |
| 1712 | { |
| 1713 | if (__f.__f_ == 0) |
| 1714 | __f_ = 0; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1715 | else if ((void *)__f.__f_ == &__f.__buf_) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1716 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1717 | __f_ = __as_base(&__buf_); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1718 | __f.__f_->__clone(__f_); |
| 1719 | } |
| 1720 | else |
| 1721 | { |
| 1722 | __f_ = __f.__f_; |
| 1723 | __f.__f_ = 0; |
| 1724 | } |
| 1725 | } |
| 1726 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1727 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | 16ed718 | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 1728 | template <class _Fp, class> |
| 1729 | function<_Rp(_ArgTypes...)>::function(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1730 | : __f_(0) |
| 1731 | { |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1732 | if (__function::__not_null(__f)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1734 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; |
| 1735 | if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1736 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1737 | __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1738 | } |
| 1739 | else |
| 1740 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1741 | typedef allocator<_FF> _Ap; |
| 1742 | _Ap __a; |
| 1743 | typedef __allocator_destructor<_Ap> _Dp; |
| 1744 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1745 | ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1746 | __f_ = __hold.release(); |
| 1747 | } |
| 1748 | } |
| 1749 | } |
| 1750 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1751 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | 16ed718 | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 1752 | template <class _Fp, class _Alloc, class> |
| 1753 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1754 | : __f_(0) |
| 1755 | { |
| 1756 | typedef allocator_traits<_Alloc> __alloc_traits; |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1757 | if (__function::__not_null(__f)) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1758 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1759 | typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1760 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Marshall Clow | a178c13 | 2014-04-18 17:23:36 +0000 | [diff] [blame] | 1761 | _Ap __a(__a0); |
| 1762 | if (sizeof(_FF) <= sizeof(__buf_) && |
| 1763 | is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1764 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1765 | __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1766 | } |
| 1767 | else |
| 1768 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1769 | typedef __allocator_destructor<_Ap> _Dp; |
| 1770 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1771 | ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1772 | __f_ = __hold.release(); |
| 1773 | } |
| 1774 | } |
| 1775 | } |
| 1776 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1777 | template<class _Rp, class ..._ArgTypes> |
| 1778 | function<_Rp(_ArgTypes...)>& |
| 1779 | function<_Rp(_ArgTypes...)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1780 | { |
| 1781 | function(__f).swap(*this); |
| 1782 | return *this; |
| 1783 | } |
| 1784 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1785 | template<class _Rp, class ..._ArgTypes> |
| 1786 | function<_Rp(_ArgTypes...)>& |
| 1787 | function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1788 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1789 | if ((void *)__f_ == &__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1790 | __f_->destroy(); |
| 1791 | else if (__f_) |
| 1792 | __f_->destroy_deallocate(); |
| 1793 | __f_ = 0; |
| 1794 | if (__f.__f_ == 0) |
| 1795 | __f_ = 0; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1796 | else if ((void *)__f.__f_ == &__f.__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1797 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1798 | __f_ = __as_base(&__buf_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1799 | __f.__f_->__clone(__f_); |
| 1800 | } |
| 1801 | else |
| 1802 | { |
| 1803 | __f_ = __f.__f_; |
| 1804 | __f.__f_ = 0; |
| 1805 | } |
Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 1806 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1809 | template<class _Rp, class ..._ArgTypes> |
| 1810 | function<_Rp(_ArgTypes...)>& |
| 1811 | function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1812 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1813 | if ((void *)__f_ == &__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1814 | __f_->destroy(); |
| 1815 | else if (__f_) |
| 1816 | __f_->destroy_deallocate(); |
| 1817 | __f_ = 0; |
Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 1818 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1821 | template<class _Rp, class ..._ArgTypes> |
| 1822 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1823 | typename enable_if |
| 1824 | < |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 1825 | function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value && |
| 1826 | !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1827 | function<_Rp(_ArgTypes...)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1828 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1829 | function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1830 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1831 | function(_VSTD::forward<_Fp>(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1832 | return *this; |
| 1833 | } |
| 1834 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1835 | template<class _Rp, class ..._ArgTypes> |
| 1836 | function<_Rp(_ArgTypes...)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1838 | if ((void *)__f_ == &__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1839 | __f_->destroy(); |
| 1840 | else if (__f_) |
| 1841 | __f_->destroy_deallocate(); |
| 1842 | } |
| 1843 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1844 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1845 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1846 | function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1847 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1848 | if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1849 | { |
| 1850 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1851 | __base* __t = __as_base(&__tempbuf); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1852 | __f_->__clone(__t); |
| 1853 | __f_->destroy(); |
| 1854 | __f_ = 0; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1855 | __f.__f_->__clone(__as_base(&__buf_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1856 | __f.__f_->destroy(); |
| 1857 | __f.__f_ = 0; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1858 | __f_ = __as_base(&__buf_); |
| 1859 | __t->__clone(__as_base(&__f.__buf_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1860 | __t->destroy(); |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1861 | __f.__f_ = __as_base(&__f.__buf_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 | } |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1863 | else if ((void *)__f_ == &__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1864 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1865 | __f_->__clone(__as_base(&__f.__buf_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1866 | __f_->destroy(); |
| 1867 | __f_ = __f.__f_; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1868 | __f.__f_ = __as_base(&__f.__buf_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1869 | } |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1870 | else if ((void *)__f.__f_ == &__f.__buf_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1871 | { |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1872 | __f.__f_->__clone(__as_base(&__buf_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1873 | __f.__f_->destroy(); |
| 1874 | __f.__f_ = __f_; |
Evgeniy Stepanov | 45dca2c | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 1875 | __f_ = __as_base(&__buf_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1876 | } |
| 1877 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1878 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1881 | template<class _Rp, class ..._ArgTypes> |
| 1882 | _Rp |
| 1883 | function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1884 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1885 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1886 | if (__f_ == 0) |
| 1887 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1888 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1889 | return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1892 | #ifndef _LIBCPP_NO_RTTI |
| 1893 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1894 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1895 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1896 | function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1897 | { |
| 1898 | if (__f_ == 0) |
| 1899 | return typeid(void); |
| 1900 | return __f_->target_type(); |
| 1901 | } |
| 1902 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1903 | template<class _Rp, class ..._ArgTypes> |
| 1904 | template <typename _Tp> |
| 1905 | _Tp* |
| 1906 | function<_Rp(_ArgTypes...)>::target() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1907 | { |
| 1908 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1909 | return (_Tp*)0; |
| 1910 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1913 | template<class _Rp, class ..._ArgTypes> |
| 1914 | template <typename _Tp> |
| 1915 | const _Tp* |
| 1916 | function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1917 | { |
| 1918 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1919 | return (const _Tp*)0; |
| 1920 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1923 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1924 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1925 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1926 | inline _LIBCPP_INLINE_VISIBILITY |
| 1927 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1928 | operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1929 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1930 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1931 | inline _LIBCPP_INLINE_VISIBILITY |
| 1932 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1933 | operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1934 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1935 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1936 | inline _LIBCPP_INLINE_VISIBILITY |
| 1937 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1938 | operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1939 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1940 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1941 | inline _LIBCPP_INLINE_VISIBILITY |
| 1942 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1943 | operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1944 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1945 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1946 | inline _LIBCPP_INLINE_VISIBILITY |
| 1947 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1948 | swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1949 | {return __x.swap(__y);} |
| 1950 | |
Eric Fiselier | db8c4fd | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1951 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 1952 | |
| 1953 | #include <__functional_03> |
| 1954 | |
| 1955 | #endif |
Eric Fiselier | 45f63bc | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1956 | |
| 1957 | //////////////////////////////////////////////////////////////////////////////// |
| 1958 | // BIND |
| 1959 | //============================================================================== |
| 1960 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1961 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1962 | template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1963 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 1964 | |
| 1965 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1966 | template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1967 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 1968 | |
| 1969 | namespace placeholders |
| 1970 | { |
| 1971 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1972 | template <int _Np> struct __ph {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1973 | |
Eric Fiselier | abd892a | 2016-06-26 21:01:34 +0000 | [diff] [blame] | 1974 | #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) |
| 1975 | _LIBCPP_FUNC_VIS extern const __ph<1> _1; |
| 1976 | _LIBCPP_FUNC_VIS extern const __ph<2> _2; |
| 1977 | _LIBCPP_FUNC_VIS extern const __ph<3> _3; |
| 1978 | _LIBCPP_FUNC_VIS extern const __ph<4> _4; |
| 1979 | _LIBCPP_FUNC_VIS extern const __ph<5> _5; |
| 1980 | _LIBCPP_FUNC_VIS extern const __ph<6> _6; |
| 1981 | _LIBCPP_FUNC_VIS extern const __ph<7> _7; |
| 1982 | _LIBCPP_FUNC_VIS extern const __ph<8> _8; |
| 1983 | _LIBCPP_FUNC_VIS extern const __ph<9> _9; |
| 1984 | _LIBCPP_FUNC_VIS extern const __ph<10> _10; |
| 1985 | #else |
| 1986 | constexpr __ph<1> _1{}; |
| 1987 | constexpr __ph<2> _2{}; |
| 1988 | constexpr __ph<3> _3{}; |
| 1989 | constexpr __ph<4> _4{}; |
| 1990 | constexpr __ph<5> _5{}; |
| 1991 | constexpr __ph<6> _6{}; |
| 1992 | constexpr __ph<7> _7{}; |
| 1993 | constexpr __ph<8> _8{}; |
| 1994 | constexpr __ph<9> _9{}; |
| 1995 | constexpr __ph<10> _10{}; |
| 1996 | #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | |
| 1998 | } // placeholders |
| 1999 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2000 | template<int _Np> |
| 2001 | struct __is_placeholder<placeholders::__ph<_Np> > |
| 2002 | : public integral_constant<int, _Np> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2003 | |
Eric Fiselier | 45f63bc | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 2004 | |
| 2005 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 2006 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2007 | template <class _Tp, class _Uj> |
| 2008 | inline _LIBCPP_INLINE_VISIBILITY |
| 2009 | _Tp& |
| 2010 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 2011 | { |
| 2012 | return __t.get(); |
| 2013 | } |
| 2014 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2015 | template <class _Ti, class ..._Uj, size_t ..._Indx> |
| 2016 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2017 | typename __invoke_of<_Ti&, _Uj...>::type |
| 2018 | __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2019 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2020 | return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | template <class _Ti, class ..._Uj> |
| 2024 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 60b3df4 | 2014-12-23 05:54:34 +0000 | [diff] [blame] | 2025 | typename __lazy_enable_if |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2026 | < |
| 2027 | is_bind_expression<_Ti>::value, |
Eric Fiselier | 60b3df4 | 2014-12-23 05:54:34 +0000 | [diff] [blame] | 2028 | __invoke_of<_Ti&, _Uj...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2029 | >::type |
| 2030 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) |
| 2031 | { |
| 2032 | typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; |
| 2033 | return __mu_expand(__ti, __uj, __indices()); |
| 2034 | } |
| 2035 | |
| 2036 | template <bool IsPh, class _Ti, class _Uj> |
| 2037 | struct __mu_return2 {}; |
| 2038 | |
| 2039 | template <class _Ti, class _Uj> |
| 2040 | struct __mu_return2<true, _Ti, _Uj> |
| 2041 | { |
| 2042 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; |
| 2043 | }; |
| 2044 | |
| 2045 | template <class _Ti, class _Uj> |
| 2046 | inline _LIBCPP_INLINE_VISIBILITY |
| 2047 | typename enable_if |
| 2048 | < |
| 2049 | 0 < is_placeholder<_Ti>::value, |
| 2050 | typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type |
| 2051 | >::type |
| 2052 | __mu(_Ti&, _Uj& __uj) |
| 2053 | { |
| 2054 | const size_t _Indx = is_placeholder<_Ti>::value - 1; |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2055 | return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
| 2058 | template <class _Ti, class _Uj> |
| 2059 | inline _LIBCPP_INLINE_VISIBILITY |
| 2060 | typename enable_if |
| 2061 | < |
| 2062 | !is_bind_expression<_Ti>::value && |
| 2063 | is_placeholder<_Ti>::value == 0 && |
| 2064 | !__is_reference_wrapper<_Ti>::value, |
| 2065 | _Ti& |
| 2066 | >::type |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2067 | __mu(_Ti& __ti, _Uj&) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2068 | { |
| 2069 | return __ti; |
| 2070 | } |
| 2071 | |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 2072 | template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, |
| 2073 | class _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2074 | struct ____mu_return; |
| 2075 | |
Howard Hinnant | c05e986 | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2076 | template <bool _Invokable, class _Ti, class ..._Uj> |
| 2077 | struct ____mu_return_invokable // false |
| 2078 | { |
| 2079 | typedef __nat type; |
| 2080 | }; |
| 2081 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2082 | template <class _Ti, class ..._Uj> |
Howard Hinnant | c05e986 | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2083 | struct ____mu_return_invokable<true, _Ti, _Uj...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2084 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2085 | typedef typename __invoke_of<_Ti&, _Uj...>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2086 | }; |
| 2087 | |
Howard Hinnant | c05e986 | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2088 | template <class _Ti, class ..._Uj> |
| 2089 | struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > |
| 2090 | : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> |
| 2091 | { |
| 2092 | }; |
| 2093 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2094 | template <class _Ti, class _TupleUj> |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 2095 | struct ____mu_return<_Ti, false, false, true, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2096 | { |
| 2097 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 2098 | _TupleUj>::type&& type; |
| 2099 | }; |
| 2100 | |
| 2101 | template <class _Ti, class _TupleUj> |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 2102 | struct ____mu_return<_Ti, true, false, false, _TupleUj> |
| 2103 | { |
| 2104 | typedef typename _Ti::type& type; |
| 2105 | }; |
| 2106 | |
| 2107 | template <class _Ti, class _TupleUj> |
| 2108 | struct ____mu_return<_Ti, false, false, false, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2109 | { |
| 2110 | typedef _Ti& type; |
| 2111 | }; |
| 2112 | |
| 2113 | template <class _Ti, class _TupleUj> |
| 2114 | struct __mu_return |
| 2115 | : public ____mu_return<_Ti, |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 2116 | __is_reference_wrapper<_Ti>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | is_bind_expression<_Ti>::value, |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2118 | 0 < is_placeholder<_Ti>::value && |
| 2119 | is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2120 | _TupleUj> |
| 2121 | { |
| 2122 | }; |
| 2123 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2124 | template <class _Fp, class _BoundArgs, class _TupleUj> |
Eric Fiselier | 5486fac | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2125 | struct __is_valid_bind_return |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2126 | { |
| 2127 | static const bool value = false; |
| 2128 | }; |
| 2129 | |
| 2130 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Eric Fiselier | 5486fac | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2131 | struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2132 | { |
| 2133 | static const bool value = __invokable<_Fp, |
| 2134 | typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; |
| 2135 | }; |
| 2136 | |
| 2137 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Eric Fiselier | 5486fac | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2138 | struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2139 | { |
| 2140 | static const bool value = __invokable<_Fp, |
| 2141 | typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; |
| 2142 | }; |
| 2143 | |
| 2144 | template <class _Fp, class _BoundArgs, class _TupleUj, |
Eric Fiselier | 5486fac | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2145 | bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2146 | struct __bind_return; |
| 2147 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2148 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2149 | struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2150 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2151 | typedef typename __invoke_of |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2152 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2153 | _Fp&, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2154 | typename __mu_return |
| 2155 | < |
| 2156 | _BoundArgs, |
| 2157 | _TupleUj |
| 2158 | >::type... |
| 2159 | >::type type; |
| 2160 | }; |
| 2161 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2162 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2163 | struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2164 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2165 | typedef typename __invoke_of |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2166 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2167 | _Fp&, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2168 | typename __mu_return |
| 2169 | < |
| 2170 | const _BoundArgs, |
| 2171 | _TupleUj |
| 2172 | >::type... |
| 2173 | >::type type; |
| 2174 | }; |
| 2175 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2176 | template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2177 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2178 | typename __bind_return<_Fp, _BoundArgs, _Args>::type |
| 2179 | __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2180 | _Args&& __args) |
| 2181 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2182 | return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2185 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2186 | class __bind |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2187 | : public __weak_result_type<typename decay<_Fp>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2188 | { |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2189 | protected: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2190 | typedef typename decay<_Fp>::type _Fd; |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2191 | typedef tuple<typename decay<_BoundArgs>::type...> _Td; |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2192 | private: |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2193 | _Fd __f_; |
| 2194 | _Td __bound_args_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2195 | |
| 2196 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 2197 | public: |
Howard Hinnant | 90d7785 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2198 | #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS |
| 2199 | |
| 2200 | _LIBCPP_INLINE_VISIBILITY |
| 2201 | __bind(const __bind& __b) |
| 2202 | : __f_(__b.__f_), |
| 2203 | __bound_args_(__b.__bound_args_) {} |
| 2204 | |
| 2205 | _LIBCPP_INLINE_VISIBILITY |
| 2206 | __bind& operator=(const __bind& __b) |
| 2207 | { |
| 2208 | __f_ = __b.__f_; |
| 2209 | __bound_args_ = __b.__bound_args_; |
| 2210 | return *this; |
| 2211 | } |
| 2212 | |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2213 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2214 | __bind(__bind&& __b) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2215 | : __f_(_VSTD::move(__b.__f_)), |
| 2216 | __bound_args_(_VSTD::move(__b.__bound_args_)) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2217 | |
Howard Hinnant | 90d7785 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2218 | _LIBCPP_INLINE_VISIBILITY |
| 2219 | __bind& operator=(__bind&& __b) |
| 2220 | { |
| 2221 | __f_ = _VSTD::move(__b.__f_); |
| 2222 | __bound_args_ = _VSTD::move(__b.__bound_args_); |
| 2223 | return *this; |
| 2224 | } |
| 2225 | |
| 2226 | #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS |
| 2227 | |
Howard Hinnant | d2da6d2 | 2012-05-04 17:21:02 +0000 | [diff] [blame] | 2228 | template <class _Gp, class ..._BA, |
| 2229 | class = typename enable_if |
| 2230 | < |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 2231 | is_constructible<_Fd, _Gp>::value && |
| 2232 | !is_same<typename remove_reference<_Gp>::type, |
| 2233 | __bind>::value |
Howard Hinnant | d2da6d2 | 2012-05-04 17:21:02 +0000 | [diff] [blame] | 2234 | >::type> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2235 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2236 | explicit __bind(_Gp&& __f, _BA&& ...__bound_args) |
| 2237 | : __f_(_VSTD::forward<_Gp>(__f)), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2238 | __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2239 | |
| 2240 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2241 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2242 | typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2243 | operator()(_Args&& ...__args) |
| 2244 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2245 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2246 | tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2251 | typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2252 | operator()(_Args&& ...__args) const |
| 2253 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2254 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2255 | tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2256 | } |
| 2257 | }; |
| 2258 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2259 | template<class _Fp, class ..._BoundArgs> |
| 2260 | struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2261 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2262 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2263 | class __bind_r |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2264 | : public __bind<_Fp, _BoundArgs...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2265 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2266 | typedef __bind<_Fp, _BoundArgs...> base; |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2267 | typedef typename base::_Fd _Fd; |
| 2268 | typedef typename base::_Td _Td; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2269 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2270 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2271 | |
Howard Hinnant | 90d7785 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2272 | #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS |
| 2273 | |
| 2274 | _LIBCPP_INLINE_VISIBILITY |
| 2275 | __bind_r(const __bind_r& __b) |
| 2276 | : base(_VSTD::forward<const base&>(__b)) {} |
| 2277 | |
| 2278 | _LIBCPP_INLINE_VISIBILITY |
| 2279 | __bind_r& operator=(const __bind_r& __b) |
| 2280 | { |
| 2281 | base::operator=(_VSTD::forward<const base&>(__b)); |
| 2282 | return *this; |
| 2283 | } |
| 2284 | |
Howard Hinnant | 496934a | 2011-05-16 16:19:01 +0000 | [diff] [blame] | 2285 | _LIBCPP_INLINE_VISIBILITY |
| 2286 | __bind_r(__bind_r&& __b) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2287 | : base(_VSTD::forward<base>(__b)) {} |
Howard Hinnant | 496934a | 2011-05-16 16:19:01 +0000 | [diff] [blame] | 2288 | |
Howard Hinnant | 90d7785 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 2289 | _LIBCPP_INLINE_VISIBILITY |
| 2290 | __bind_r& operator=(__bind_r&& __b) |
| 2291 | { |
| 2292 | base::operator=(_VSTD::forward<base>(__b)); |
| 2293 | return *this; |
| 2294 | } |
| 2295 | |
| 2296 | #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS |
| 2297 | |
Howard Hinnant | 099dec1 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 2298 | template <class _Gp, class ..._BA, |
| 2299 | class = typename enable_if |
| 2300 | < |
| 2301 | is_constructible<_Fd, _Gp>::value && |
| 2302 | !is_same<typename remove_reference<_Gp>::type, |
| 2303 | __bind_r>::value |
| 2304 | >::type> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2306 | explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) |
| 2307 | : base(_VSTD::forward<_Gp>(__f), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2308 | _VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2309 | |
| 2310 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2311 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2312 | typename enable_if |
| 2313 | < |
| 2314 | is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, |
Eric Fiselier | f301a11 | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 2315 | result_type>::value || is_void<_Rp>::value, |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2316 | result_type |
| 2317 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2318 | operator()(_Args&& ...__args) |
| 2319 | { |
Eric Fiselier | f301a11 | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 2320 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 2321 | return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2325 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2326 | typename enable_if |
| 2327 | < |
| 2328 | is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, |
Eric Fiselier | f301a11 | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 2329 | result_type>::value || is_void<_Rp>::value, |
Howard Hinnant | 0560f78 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2330 | result_type |
| 2331 | >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2332 | operator()(_Args&& ...__args) const |
| 2333 | { |
Eric Fiselier | f301a11 | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 2334 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 2335 | return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2336 | } |
| 2337 | }; |
| 2338 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2339 | template<class _Rp, class _Fp, class ..._BoundArgs> |
| 2340 | struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2341 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2342 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2344 | __bind<_Fp, _BoundArgs...> |
| 2345 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2346 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2347 | typedef __bind<_Fp, _BoundArgs...> type; |
| 2348 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2351 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2352 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2353 | __bind_r<_Rp, _Fp, _BoundArgs...> |
| 2354 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2355 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2356 | typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; |
| 2357 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 2361 | |
| 2362 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2363 | struct _LIBCPP_TYPE_VIS_ONLY hash<bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2364 | : public unary_function<bool, size_t> |
| 2365 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2366 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2367 | size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2368 | }; |
| 2369 | |
| 2370 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2371 | struct _LIBCPP_TYPE_VIS_ONLY hash<char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2372 | : public unary_function<char, size_t> |
| 2373 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2374 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2375 | size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2376 | }; |
| 2377 | |
| 2378 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2379 | struct _LIBCPP_TYPE_VIS_ONLY hash<signed char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2380 | : public unary_function<signed char, size_t> |
| 2381 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2382 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2383 | size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2384 | }; |
| 2385 | |
| 2386 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2387 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2388 | : public unary_function<unsigned char, size_t> |
| 2389 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2390 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2391 | size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2392 | }; |
| 2393 | |
| 2394 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 2395 | |
| 2396 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2397 | struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2398 | : public unary_function<char16_t, size_t> |
| 2399 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2400 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2401 | size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2402 | }; |
| 2403 | |
| 2404 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2405 | struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2406 | : public unary_function<char32_t, size_t> |
| 2407 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2408 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2409 | size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | }; |
| 2411 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2412 | #endif // _LIBCPP_HAS_NO_UNICODE_CHARS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2413 | |
| 2414 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2415 | struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2416 | : public unary_function<wchar_t, size_t> |
| 2417 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2418 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2419 | size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2420 | }; |
| 2421 | |
| 2422 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2423 | struct _LIBCPP_TYPE_VIS_ONLY hash<short> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2424 | : public unary_function<short, size_t> |
| 2425 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2426 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2427 | size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2428 | }; |
| 2429 | |
| 2430 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2431 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2432 | : public unary_function<unsigned short, size_t> |
| 2433 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2434 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2435 | size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2436 | }; |
| 2437 | |
| 2438 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2439 | struct _LIBCPP_TYPE_VIS_ONLY hash<int> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2440 | : public unary_function<int, size_t> |
| 2441 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2442 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2443 | size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2444 | }; |
| 2445 | |
| 2446 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2447 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2448 | : public unary_function<unsigned int, size_t> |
| 2449 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2450 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2451 | size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2452 | }; |
| 2453 | |
| 2454 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2455 | struct _LIBCPP_TYPE_VIS_ONLY hash<long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2456 | : public unary_function<long, size_t> |
| 2457 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2458 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2459 | size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2460 | }; |
| 2461 | |
| 2462 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2463 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2464 | : public unary_function<unsigned long, size_t> |
| 2465 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2466 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2467 | size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2468 | }; |
| 2469 | |
| 2470 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2471 | struct _LIBCPP_TYPE_VIS_ONLY hash<long long> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2472 | : public __scalar_hash<long long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2473 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2474 | }; |
| 2475 | |
| 2476 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2477 | struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2478 | : public __scalar_hash<unsigned long long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2479 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2480 | }; |
| 2481 | |
Eric Fiselier | b952822 | 2016-04-18 02:54:00 +0000 | [diff] [blame] | 2482 | #ifndef _LIBCPP_HAS_NO_INT128 |
| 2483 | |
| 2484 | template <> |
| 2485 | struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t> |
| 2486 | : public __scalar_hash<__int128_t> |
| 2487 | { |
| 2488 | }; |
| 2489 | |
| 2490 | template <> |
| 2491 | struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t> |
| 2492 | : public __scalar_hash<__uint128_t> |
| 2493 | { |
| 2494 | }; |
| 2495 | |
| 2496 | #endif |
| 2497 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2498 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2499 | struct _LIBCPP_TYPE_VIS_ONLY hash<float> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2500 | : public __scalar_hash<float> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2501 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2502 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2503 | size_t operator()(float __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2504 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2505 | // -0.0 and 0.0 should return same hash |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2506 | if (__v == 0) |
| 2507 | return 0; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2508 | return __scalar_hash<float>::operator()(__v); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2509 | } |
| 2510 | }; |
| 2511 | |
| 2512 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2513 | struct _LIBCPP_TYPE_VIS_ONLY hash<double> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2514 | : public __scalar_hash<double> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2515 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2517 | size_t operator()(double __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2518 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2519 | // -0.0 and 0.0 should return same hash |
| 2520 | if (__v == 0) |
| 2521 | return 0; |
| 2522 | return __scalar_hash<double>::operator()(__v); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2523 | } |
| 2524 | }; |
| 2525 | |
| 2526 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2527 | struct _LIBCPP_TYPE_VIS_ONLY hash<long double> |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2528 | : public __scalar_hash<long double> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2529 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2530 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2531 | size_t operator()(long double __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2532 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2533 | // -0.0 and 0.0 should return same hash |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2534 | if (__v == 0) |
| 2535 | return 0; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2536 | #if defined(__i386__) |
| 2537 | // Zero out padding bits |
| 2538 | union |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2539 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2540 | long double __t; |
| 2541 | struct |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2542 | { |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2543 | size_t __a; |
| 2544 | size_t __b; |
| 2545 | size_t __c; |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2546 | size_t __d; |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2547 | } __s; |
Howard Hinnant | 2891675 | 2011-12-02 23:45:22 +0000 | [diff] [blame] | 2548 | } __u; |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2549 | __u.__s.__a = 0; |
| 2550 | __u.__s.__b = 0; |
| 2551 | __u.__s.__c = 0; |
| 2552 | __u.__s.__d = 0; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2553 | __u.__t = __v; |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2554 | return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2555 | #elif defined(__x86_64__) |
| 2556 | // Zero out padding bits |
| 2557 | union |
| 2558 | { |
| 2559 | long double __t; |
| 2560 | struct |
| 2561 | { |
| 2562 | size_t __a; |
| 2563 | size_t __b; |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2564 | } __s; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2565 | } __u; |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2566 | __u.__s.__a = 0; |
| 2567 | __u.__s.__b = 0; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2568 | __u.__t = __v; |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 2569 | return __u.__s.__a ^ __u.__s.__b; |
Howard Hinnant | cf2654b | 2011-12-03 21:11:36 +0000 | [diff] [blame] | 2570 | #else |
| 2571 | return __scalar_hash<long double>::operator()(__v); |
| 2572 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2573 | } |
| 2574 | }; |
| 2575 | |
Marshall Clow | 9e613ca | 2013-09-03 17:55:32 +0000 | [diff] [blame] | 2576 | #if _LIBCPP_STD_VER > 11 |
| 2577 | template <class _Tp> |
| 2578 | struct _LIBCPP_TYPE_VIS_ONLY hash |
| 2579 | : public unary_function<_Tp, size_t> |
| 2580 | { |
| 2581 | static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types"); |
| 2582 | |
| 2583 | _LIBCPP_INLINE_VISIBILITY |
| 2584 | size_t operator()(_Tp __v) const _NOEXCEPT |
| 2585 | { |
| 2586 | typedef typename underlying_type<_Tp>::type type; |
| 2587 | return hash<type>{}(static_cast<type>(__v)); |
| 2588 | } |
| 2589 | }; |
| 2590 | #endif |
| 2591 | |
Eric Fiselier | 22dff53 | 2015-07-14 20:16:15 +0000 | [diff] [blame] | 2592 | |
| 2593 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | c230822 | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 2594 | |
Eric Fiselier | 22dff53 | 2015-07-14 20:16:15 +0000 | [diff] [blame] | 2595 | template <class _Fn, class ..._Args> |
| 2596 | result_of_t<_Fn&&(_Args&&...)> |
Eric Fiselier | c230822 | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 2597 | invoke(_Fn&& __f, _Args&&... __args) |
| 2598 | noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...))) |
| 2599 | { |
| 2600 | return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); |
Eric Fiselier | 22dff53 | 2015-07-14 20:16:15 +0000 | [diff] [blame] | 2601 | } |
Eric Fiselier | c230822 | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 2602 | |
| 2603 | template <class _DecayFunc> |
| 2604 | class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp { |
| 2605 | _DecayFunc __fd; |
| 2606 | |
| 2607 | public: |
| 2608 | __not_fn_imp() = delete; |
| 2609 | |
| 2610 | template <class ..._Args> |
| 2611 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 715ca51 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 2612 | auto operator()(_Args&& ...__args) & |
Eric Fiselier | c230822 | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 2613 | noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) |
| 2614 | -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) |
| 2615 | { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } |
| 2616 | |
| 2617 | template <class ..._Args> |
| 2618 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 715ca51 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 2619 | auto operator()(_Args&& ...__args) && |
| 2620 | noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) |
| 2621 | -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) |
| 2622 | { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } |
| 2623 | |
| 2624 | template <class ..._Args> |
| 2625 | _LIBCPP_INLINE_VISIBILITY |
| 2626 | auto operator()(_Args&& ...__args) const& |
Eric Fiselier | c230822 | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 2627 | noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) |
| 2628 | -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) |
| 2629 | { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } |
| 2630 | |
Eric Fiselier | 715ca51 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 2631 | |
| 2632 | template <class ..._Args> |
| 2633 | _LIBCPP_INLINE_VISIBILITY |
| 2634 | auto operator()(_Args&& ...__args) const&& |
| 2635 | noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) |
| 2636 | -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) |
| 2637 | { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } |
| 2638 | |
Eric Fiselier | c230822 | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 2639 | private: |
| 2640 | template <class _RawFunc, |
| 2641 | class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>> |
| 2642 | _LIBCPP_INLINE_VISIBILITY |
| 2643 | explicit __not_fn_imp(_RawFunc&& __rf) |
| 2644 | : __fd(_VSTD::forward<_RawFunc>(__rf)) {} |
| 2645 | |
| 2646 | template <class _RawFunc> |
| 2647 | friend inline _LIBCPP_INLINE_VISIBILITY |
| 2648 | __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&); |
| 2649 | }; |
| 2650 | |
| 2651 | template <class _RawFunc> |
| 2652 | inline _LIBCPP_INLINE_VISIBILITY |
| 2653 | __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) { |
| 2654 | return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn)); |
| 2655 | } |
| 2656 | |
Eric Fiselier | 22dff53 | 2015-07-14 20:16:15 +0000 | [diff] [blame] | 2657 | #endif |
| 2658 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 2659 | // struct hash<T*> in <memory> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2660 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2661 | _LIBCPP_END_NAMESPACE_STD |
| 2662 | |
| 2663 | #endif // _LIBCPP_FUNCTIONAL |