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 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 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 |
| 46 | reference_wrapper(T&); |
| 47 | reference_wrapper(T&&) = delete; // do not bind to temps |
| 48 | reference_wrapper(const reference_wrapper<T>& x); |
| 49 | |
| 50 | // assignment |
| 51 | reference_wrapper& operator=(const reference_wrapper<T>& x); |
| 52 | |
| 53 | // access |
| 54 | operator T& () const; |
| 55 | T& get() const; |
| 56 | |
| 57 | // invoke |
| 58 | template <class... ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +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 | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 63 | template <class T> reference_wrapper<T> ref(T& t); |
| 64 | template <class T> void ref(const T&& t) = delete; |
| 65 | template <class T> reference_wrapper<T> ref(reference_wrapper<T>t); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 67 | template <class T> reference_wrapper<const T> cref(const T& t); |
| 68 | template <class T> void cref(const T&& t) = delete; |
| 69 | template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 70 | |
| 71 | template <class T> |
| 72 | struct plus : binary_function<T, T, T> |
| 73 | { |
| 74 | T operator()(const T& x, const T& y) const; |
| 75 | }; |
| 76 | |
| 77 | template <class T> |
| 78 | struct minus : binary_function<T, T, T> |
| 79 | { |
| 80 | T operator()(const T& x, const T& y) const; |
| 81 | }; |
| 82 | |
| 83 | template <class T> |
| 84 | struct multiplies : binary_function<T, T, T> |
| 85 | { |
| 86 | T operator()(const T& x, const T& y) const; |
| 87 | }; |
| 88 | |
| 89 | template <class T> |
| 90 | struct divides : binary_function<T, T, T> |
| 91 | { |
| 92 | T operator()(const T& x, const T& y) const; |
| 93 | }; |
| 94 | |
| 95 | template <class T> |
| 96 | struct modulus : binary_function<T, T, T> |
| 97 | { |
| 98 | T operator()(const T& x, const T& y) const; |
| 99 | }; |
| 100 | |
| 101 | template <class T> |
| 102 | struct negate : unary_function<T, T> |
| 103 | { |
| 104 | T operator()(const T& x) const; |
| 105 | }; |
| 106 | |
| 107 | template <class T> |
| 108 | struct equal_to : binary_function<T, T, bool> |
| 109 | { |
| 110 | bool operator()(const T& x, const T& y) const; |
| 111 | }; |
| 112 | |
| 113 | template <class T> |
| 114 | struct not_equal_to : binary_function<T, T, bool> |
| 115 | { |
| 116 | bool operator()(const T& x, const T& y) const; |
| 117 | }; |
| 118 | |
| 119 | template <class T> |
| 120 | struct greater : binary_function<T, T, bool> |
| 121 | { |
| 122 | bool operator()(const T& x, const T& y) const; |
| 123 | }; |
| 124 | |
| 125 | template <class T> |
| 126 | struct less : binary_function<T, T, bool> |
| 127 | { |
| 128 | bool operator()(const T& x, const T& y) const; |
| 129 | }; |
| 130 | |
| 131 | template <class T> |
| 132 | struct greater_equal : binary_function<T, T, bool> |
| 133 | { |
| 134 | bool operator()(const T& x, const T& y) const; |
| 135 | }; |
| 136 | |
| 137 | template <class T> |
| 138 | struct less_equal : binary_function<T, T, bool> |
| 139 | { |
| 140 | bool operator()(const T& x, const T& y) const; |
| 141 | }; |
| 142 | |
| 143 | template <class T> |
| 144 | struct logical_and : binary_function<T, T, bool> |
| 145 | { |
| 146 | bool operator()(const T& x, const T& y) const; |
| 147 | }; |
| 148 | |
| 149 | template <class T> |
| 150 | struct logical_or : binary_function<T, T, bool> |
| 151 | { |
| 152 | bool operator()(const T& x, const T& y) const; |
| 153 | }; |
| 154 | |
| 155 | template <class T> |
| 156 | struct logical_not : unary_function<T, bool> |
| 157 | { |
| 158 | bool operator()(const T& x) const; |
| 159 | }; |
| 160 | |
| 161 | template <class Predicate> |
| 162 | class unary_negate |
| 163 | : public unary_function<typename Predicate::argument_type, bool> |
| 164 | { |
| 165 | public: |
| 166 | explicit unary_negate(const Predicate& pred); |
| 167 | bool operator()(const typename Predicate::argument_type& x) const; |
| 168 | }; |
| 169 | |
| 170 | template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred); |
| 171 | |
| 172 | template <class Predicate> |
| 173 | class binary_negate |
| 174 | : public binary_function<typename Predicate::first_argument_type, |
| 175 | typename Predicate::second_argument_type, |
| 176 | bool> |
| 177 | { |
| 178 | public: |
| 179 | explicit binary_negate(const Predicate& pred); |
| 180 | bool operator()(const typename Predicate::first_argument_type& x, |
| 181 | const typename Predicate::second_argument_type& y) const; |
| 182 | }; |
| 183 | |
| 184 | template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred); |
| 185 | |
| 186 | template<class T> struct is_bind_expression; |
| 187 | template<class T> struct is_placeholder; |
| 188 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 189 | template<class Fn, class... BoundArgs> |
| 190 | unspecified bind(Fn&&, BoundArgs&&...); |
| 191 | template<class R, class Fn, class... BoundArgs> |
| 192 | unspecified bind(Fn&&, BoundArgs&&...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | |
| 194 | namespace placeholders { |
| 195 | // M is the implementation-defined number of placeholders |
| 196 | extern unspecified _1; |
| 197 | extern unspecified _2; |
| 198 | . |
| 199 | . |
| 200 | . |
| 201 | extern unspecified _M; |
| 202 | } |
| 203 | |
| 204 | template <class Operation> |
| 205 | class binder1st |
| 206 | : public unary_function<typename Operation::second_argument_type, |
| 207 | typename Operation::result_type> |
| 208 | { |
| 209 | protected: |
| 210 | Operation op; |
| 211 | typename Operation::first_argument_type value; |
| 212 | public: |
| 213 | binder1st(const Operation& x, const typename Operation::first_argument_type y); |
| 214 | typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; |
| 215 | typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; |
| 216 | }; |
| 217 | |
| 218 | template <class Operation, class T> |
| 219 | binder1st<Operation> bind1st(const Operation& op, const T& x); |
| 220 | |
| 221 | template <class Operation> |
| 222 | class binder2nd |
| 223 | : public unary_function<typename Operation::first_argument_type, |
| 224 | typename Operation::result_type> |
| 225 | { |
| 226 | protected: |
| 227 | Operation op; |
| 228 | typename Operation::second_argument_type value; |
| 229 | public: |
| 230 | binder2nd(const Operation& x, const typename Operation::second_argument_type y); |
| 231 | typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; |
| 232 | typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; |
| 233 | }; |
| 234 | |
| 235 | template <class Operation, class T> |
| 236 | binder2nd<Operation> bind2nd(const Operation& op, const T& x); |
| 237 | |
| 238 | template <class Arg, class Result> |
| 239 | class pointer_to_unary_function : public unary_function<Arg, Result> |
| 240 | { |
| 241 | public: |
| 242 | explicit pointer_to_unary_function(Result (*f)(Arg)); |
| 243 | Result operator()(Arg x) const; |
| 244 | }; |
| 245 | |
| 246 | template <class Arg, class Result> |
| 247 | pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); |
| 248 | |
| 249 | template <class Arg1, class Arg2, class Result> |
| 250 | class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> |
| 251 | { |
| 252 | public: |
| 253 | explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); |
| 254 | Result operator()(Arg1 x, Arg2 y) const; |
| 255 | }; |
| 256 | |
| 257 | template <class Arg1, class Arg2, class Result> |
| 258 | pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); |
| 259 | |
| 260 | template<class S, class T> |
| 261 | class mem_fun_t : public unary_function<T*, S> |
| 262 | { |
| 263 | public: |
| 264 | explicit mem_fun_t(S (T::*p)()); |
| 265 | S operator()(T* p) const; |
| 266 | }; |
| 267 | |
| 268 | template<class S, class T, class A> |
| 269 | class mem_fun1_t : public binary_function<T*, A, S> |
| 270 | { |
| 271 | public: |
| 272 | explicit mem_fun1_t(S (T::*p)(A)); |
| 273 | S operator()(T* p, A x) const; |
| 274 | }; |
| 275 | |
| 276 | template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); |
| 277 | template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); |
| 278 | |
| 279 | template<class S, class T> |
| 280 | class mem_fun_ref_t : public unary_function<T, S> |
| 281 | { |
| 282 | public: |
| 283 | explicit mem_fun_ref_t(S (T::*p)()); |
| 284 | S operator()(T& p) const; |
| 285 | }; |
| 286 | |
| 287 | template<class S, class T, class A> |
| 288 | class mem_fun1_ref_t : public binary_function<T, A, S> |
| 289 | { |
| 290 | public: |
| 291 | explicit mem_fun1_ref_t(S (T::*p)(A)); |
| 292 | S operator()(T& p, A x) const; |
| 293 | }; |
| 294 | |
| 295 | template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); |
| 296 | template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); |
| 297 | |
| 298 | template <class S, class T> |
| 299 | class const_mem_fun_t : public unary_function<const T*, S> |
| 300 | { |
| 301 | public: |
| 302 | explicit const_mem_fun_t(S (T::*p)() const); |
| 303 | S operator()(const T* p) const; |
| 304 | }; |
| 305 | |
| 306 | template <class S, class T, class A> |
| 307 | class const_mem_fun1_t : public binary_function<const T*, A, S> |
| 308 | { |
| 309 | public: |
| 310 | explicit const_mem_fun1_t(S (T::*p)(A) const); |
| 311 | S operator()(const T* p, A x) const; |
| 312 | }; |
| 313 | |
| 314 | template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); |
| 315 | template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); |
| 316 | |
| 317 | template <class S, class T> |
| 318 | class const_mem_fun_ref_t : public unary_function<T, S> |
| 319 | { |
| 320 | public: |
| 321 | explicit const_mem_fun_ref_t(S (T::*p)() const); |
| 322 | S operator()(const T& p) const; |
| 323 | }; |
| 324 | |
| 325 | template <class S, class T, class A> |
| 326 | class const_mem_fun1_ref_t : public binary_function<T, A, S> |
| 327 | { |
| 328 | public: |
| 329 | explicit const_mem_fun1_ref_t(S (T::*p)(A) const); |
| 330 | S operator()(const T& p, A x) const; |
| 331 | }; |
| 332 | |
| 333 | template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); |
| 334 | template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); |
| 335 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 336 | template<class R, class T> unspecified mem_fn(R T::*); |
| 337 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...)); |
| 338 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const); |
| 339 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile); |
| 340 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile); |
| 341 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &); |
| 342 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &); |
| 343 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &); |
| 344 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &); |
| 345 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &&); |
| 346 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &&); |
| 347 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &&); |
| 348 | template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &&); |
| 349 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | class bad_function_call |
| 351 | : public exception |
| 352 | { |
| 353 | }; |
| 354 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 355 | template<class> class function; // undefined |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 356 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 357 | template<class R, class... ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 358 | class function<R(ArgTypes...)> |
| 359 | : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and |
| 360 | // ArgTypes contains T1 |
| 361 | : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and |
| 362 | // ArgTypes contains T1 and T2 |
| 363 | { |
| 364 | public: |
| 365 | typedef R result_type; |
| 366 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 367 | // construct/copy/destroy: |
| 368 | function(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | function(nullptr_t); |
| 370 | function(const function&); |
| 371 | function(function&&); |
| 372 | template<class F> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | function(F); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | template<Allocator Alloc> |
| 375 | function(allocator_arg_t, const Alloc&); |
| 376 | template<Allocator Alloc> |
| 377 | function(allocator_arg_t, const Alloc&, nullptr_t); |
| 378 | template<Allocator Alloc> |
| 379 | function(allocator_arg_t, const Alloc&, const function&); |
| 380 | template<Allocator Alloc> |
| 381 | function(allocator_arg_t, const Alloc&, function&&); |
| 382 | template<class F, Allocator Alloc> |
| 383 | function(allocator_arg_t, const Alloc&, F); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | |
| 385 | function& operator=(const function&); |
| 386 | function& operator=(function&&); |
| 387 | function& operator=(nullptr_t); |
| 388 | template<class F> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 389 | function& operator=(F&&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | template<class F> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | function& operator=(reference_wrapper<F>); |
| 392 | |
| 393 | ~function(); |
| 394 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 395 | // function modifiers: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 396 | void swap(function&); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 397 | template<class F, class Alloc> |
| 398 | void assign(F&&, const Alloc&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 399 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 400 | // function capacity: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | explicit operator bool() const; |
| 402 | |
| 403 | // deleted overloads close possible hole in the type system |
| 404 | template<class R2, class... ArgTypes2> |
| 405 | bool operator==(const function<R2(ArgTypes2...)>&) = delete; |
| 406 | template<class R2, class... ArgTypes2> |
| 407 | bool operator!=(const function<R2(ArgTypes2...)>&) = delete; |
| 408 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 409 | // function invocation: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | R operator()(ArgTypes...) const; |
| 411 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 412 | // function target access: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 413 | const std::type_info& target_type() const; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 414 | template <typename T> T* target(); |
| 415 | template <typename T> const T* target() const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | }; |
| 417 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 418 | // Null pointer comparisons: |
| 419 | template <class R, class ... ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 420 | bool operator==(const function<R(ArgTypes...)>&, nullptr_t); |
| 421 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 422 | template <class R, class ... ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | bool operator==(nullptr_t, const function<R(ArgTypes...)>&); |
| 424 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 425 | template <class R, class ... ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 426 | bool operator!=(const function<R(ArgTypes...)>&, nullptr_t); |
| 427 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 428 | template <class R, class ... ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | bool operator!=(nullptr_t, const function<R(ArgTypes...)>&); |
| 430 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 431 | // specialized algorithms: |
| 432 | template <class R, class ... ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 433 | void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&); |
| 434 | |
| 435 | template <class T> struct hash; |
| 436 | |
| 437 | template <> struct hash<bool>; |
| 438 | template <> struct hash<char>; |
| 439 | template <> struct hash<signed char>; |
| 440 | template <> struct hash<unsigned char>; |
| 441 | template <> struct hash<char16_t>; |
| 442 | template <> struct hash<char32_t>; |
| 443 | template <> struct hash<wchar_t>; |
| 444 | template <> struct hash<short>; |
| 445 | template <> struct hash<unsigned short>; |
| 446 | template <> struct hash<int>; |
| 447 | template <> struct hash<unsigned int>; |
| 448 | template <> struct hash<long>; |
| 449 | template <> struct hash<long long>; |
| 450 | template <> struct hash<unsigned long>; |
| 451 | template <> struct hash<unsigned long long>; |
| 452 | |
| 453 | template <> struct hash<float>; |
| 454 | template <> struct hash<double>; |
| 455 | template <> struct hash<long double>; |
| 456 | |
| 457 | template<class T> struct hash<T*>; |
| 458 | |
| 459 | } // std |
| 460 | |
| 461 | POLICY: For non-variadic implementations, the number of arguments is limited |
| 462 | to 3. It is hoped that the need for non-variadic implementations |
| 463 | will be minimal. |
| 464 | |
| 465 | */ |
| 466 | |
| 467 | #include <__config> |
| 468 | #include <type_traits> |
| 469 | #include <typeinfo> |
| 470 | #include <exception> |
| 471 | #include <memory> |
| 472 | #include <tuple> |
| 473 | |
| 474 | #include <__functional_base> |
| 475 | |
| 476 | #pragma GCC system_header |
| 477 | |
| 478 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 479 | |
| 480 | template <class _Tp> |
| 481 | struct plus : binary_function<_Tp, _Tp, _Tp> |
| 482 | { |
| 483 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 484 | {return __x + __y;} |
| 485 | }; |
| 486 | |
| 487 | template <class _Tp> |
| 488 | struct minus : binary_function<_Tp, _Tp, _Tp> |
| 489 | { |
| 490 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 491 | {return __x - __y;} |
| 492 | }; |
| 493 | |
| 494 | template <class _Tp> |
| 495 | struct multiplies : binary_function<_Tp, _Tp, _Tp> |
| 496 | { |
| 497 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 498 | {return __x * __y;} |
| 499 | }; |
| 500 | |
| 501 | template <class _Tp> |
| 502 | struct divides : binary_function<_Tp, _Tp, _Tp> |
| 503 | { |
| 504 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 505 | {return __x / __y;} |
| 506 | }; |
| 507 | |
| 508 | template <class _Tp> |
| 509 | struct modulus : binary_function<_Tp, _Tp, _Tp> |
| 510 | { |
| 511 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 512 | {return __x % __y;} |
| 513 | }; |
| 514 | |
| 515 | template <class _Tp> |
| 516 | struct negate : unary_function<_Tp, _Tp> |
| 517 | { |
| 518 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const |
| 519 | {return -__x;} |
| 520 | }; |
| 521 | |
| 522 | template <class _Tp> |
| 523 | struct equal_to : binary_function<_Tp, _Tp, bool> |
| 524 | { |
| 525 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 526 | {return __x == __y;} |
| 527 | }; |
| 528 | |
| 529 | template <class _Tp> |
| 530 | struct not_equal_to : binary_function<_Tp, _Tp, bool> |
| 531 | { |
| 532 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 533 | {return __x != __y;} |
| 534 | }; |
| 535 | |
| 536 | template <class _Tp> |
| 537 | struct greater : binary_function<_Tp, _Tp, bool> |
| 538 | { |
| 539 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 540 | {return __x > __y;} |
| 541 | }; |
| 542 | |
| 543 | template <class _Tp> |
| 544 | struct less : binary_function<_Tp, _Tp, bool> |
| 545 | { |
| 546 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 547 | {return __x < __y;} |
| 548 | }; |
| 549 | |
| 550 | template <class _Tp> |
| 551 | struct greater_equal : binary_function<_Tp, _Tp, bool> |
| 552 | { |
| 553 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 554 | {return __x >= __y;} |
| 555 | }; |
| 556 | |
| 557 | template <class _Tp> |
| 558 | struct less_equal : binary_function<_Tp, _Tp, bool> |
| 559 | { |
| 560 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 561 | {return __x <= __y;} |
| 562 | }; |
| 563 | |
| 564 | template <class _Tp> |
| 565 | struct logical_and : binary_function<_Tp, _Tp, bool> |
| 566 | { |
| 567 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 568 | {return __x && __y;} |
| 569 | }; |
| 570 | |
| 571 | template <class _Tp> |
| 572 | struct logical_or : binary_function<_Tp, _Tp, bool> |
| 573 | { |
| 574 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 575 | {return __x || __y;} |
| 576 | }; |
| 577 | |
| 578 | template <class _Tp> |
| 579 | struct logical_not : unary_function<_Tp, bool> |
| 580 | { |
| 581 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const |
| 582 | {return !__x;} |
| 583 | }; |
| 584 | |
| 585 | template <class _Tp> |
| 586 | struct bit_and : binary_function<_Tp, _Tp, _Tp> |
| 587 | { |
| 588 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 589 | {return __x & __y;} |
| 590 | }; |
| 591 | |
| 592 | template <class _Tp> |
| 593 | struct bit_or : binary_function<_Tp, _Tp, _Tp> |
| 594 | { |
| 595 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 596 | {return __x | __y;} |
| 597 | }; |
| 598 | |
| 599 | template <class _Tp> |
| 600 | struct bit_xor : binary_function<_Tp, _Tp, _Tp> |
| 601 | { |
| 602 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 603 | {return __x ^ __y;} |
| 604 | }; |
| 605 | |
| 606 | template <class _Predicate> |
| 607 | class unary_negate |
| 608 | : public unary_function<typename _Predicate::argument_type, bool> |
| 609 | { |
| 610 | _Predicate __pred_; |
| 611 | public: |
| 612 | _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred) |
| 613 | : __pred_(__pred) {} |
| 614 | _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const |
| 615 | {return !__pred_(__x);} |
| 616 | }; |
| 617 | |
| 618 | template <class _Predicate> |
| 619 | inline _LIBCPP_INLINE_VISIBILITY |
| 620 | unary_negate<_Predicate> |
| 621 | not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} |
| 622 | |
| 623 | template <class _Predicate> |
| 624 | class binary_negate |
| 625 | : public binary_function<typename _Predicate::first_argument_type, |
| 626 | typename _Predicate::second_argument_type, |
| 627 | bool> |
| 628 | { |
| 629 | _Predicate __pred_; |
| 630 | public: |
| 631 | _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred) |
| 632 | : __pred_(__pred) {} |
| 633 | _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x, |
| 634 | const typename _Predicate::second_argument_type& __y) const |
| 635 | {return !__pred_(__x, __y);} |
| 636 | }; |
| 637 | |
| 638 | template <class _Predicate> |
| 639 | inline _LIBCPP_INLINE_VISIBILITY |
| 640 | binary_negate<_Predicate> |
| 641 | not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} |
| 642 | |
| 643 | template <class __Operation> |
| 644 | class binder1st |
| 645 | : public unary_function<typename __Operation::second_argument_type, |
| 646 | typename __Operation::result_type> |
| 647 | { |
| 648 | protected: |
| 649 | __Operation op; |
| 650 | typename __Operation::first_argument_type value; |
| 651 | public: |
| 652 | _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, |
| 653 | const typename __Operation::first_argument_type __y) |
| 654 | : op(__x), value(__y) {} |
| 655 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 656 | (typename __Operation::second_argument_type& __x) const |
| 657 | {return op(value, __x);} |
| 658 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 659 | (const typename __Operation::second_argument_type& __x) const |
| 660 | {return op(value, __x);} |
| 661 | }; |
| 662 | |
| 663 | template <class __Operation, class _Tp> |
| 664 | inline _LIBCPP_INLINE_VISIBILITY |
| 665 | binder1st<__Operation> |
| 666 | bind1st(const __Operation& __op, const _Tp& __x) |
| 667 | {return binder1st<__Operation>(__op, __x);} |
| 668 | |
| 669 | template <class __Operation> |
| 670 | class binder2nd |
| 671 | : public unary_function<typename __Operation::first_argument_type, |
| 672 | typename __Operation::result_type> |
| 673 | { |
| 674 | protected: |
| 675 | __Operation op; |
| 676 | typename __Operation::second_argument_type value; |
| 677 | public: |
| 678 | binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) |
| 679 | : op(__x), value(__y) {} |
| 680 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 681 | ( typename __Operation::first_argument_type& __x) const |
| 682 | {return op(__x, value);} |
| 683 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 684 | (const typename __Operation::first_argument_type& __x) const |
| 685 | {return op(__x, value);} |
| 686 | }; |
| 687 | |
| 688 | template <class __Operation, class _Tp> |
| 689 | inline _LIBCPP_INLINE_VISIBILITY |
| 690 | binder2nd<__Operation> |
| 691 | bind2nd(const __Operation& __op, const _Tp& __x) |
| 692 | {return binder2nd<__Operation>(__op, __x);} |
| 693 | |
| 694 | template <class _Arg, class _Result> |
| 695 | class pointer_to_unary_function : public unary_function<_Arg, _Result> |
| 696 | { |
| 697 | _Result (*__f_)(_Arg); |
| 698 | public: |
| 699 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) |
| 700 | : __f_(__f) {} |
| 701 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const |
| 702 | {return __f_(__x);} |
| 703 | }; |
| 704 | |
| 705 | template <class _Arg, class _Result> |
| 706 | inline _LIBCPP_INLINE_VISIBILITY |
| 707 | pointer_to_unary_function<_Arg,_Result> |
| 708 | ptr_fun(_Result (*__f)(_Arg)) |
| 709 | {return pointer_to_unary_function<_Arg,_Result>(__f);} |
| 710 | |
| 711 | template <class _Arg1, class _Arg2, class _Result> |
| 712 | class pointer_to_binary_function : public binary_function<_Arg1, _Arg2, _Result> |
| 713 | { |
| 714 | _Result (*__f_)(_Arg1, _Arg2); |
| 715 | public: |
| 716 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) |
| 717 | : __f_(__f) {} |
| 718 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const |
| 719 | {return __f_(__x, __y);} |
| 720 | }; |
| 721 | |
| 722 | template <class _Arg1, class _Arg2, class _Result> |
| 723 | inline _LIBCPP_INLINE_VISIBILITY |
| 724 | pointer_to_binary_function<_Arg1,_Arg2,_Result> |
| 725 | ptr_fun(_Result (*__f)(_Arg1,_Arg2)) |
| 726 | {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} |
| 727 | |
| 728 | template<class _Sp, class _Tp> |
| 729 | class mem_fun_t : public unary_function<_Tp*, _Sp> |
| 730 | { |
| 731 | _Sp (_Tp::*__p_)(); |
| 732 | public: |
| 733 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) |
| 734 | : __p_(__p) {} |
| 735 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const |
| 736 | {return (__p->*__p_)();} |
| 737 | }; |
| 738 | |
| 739 | template<class _Sp, class _Tp, class _Ap> |
| 740 | class mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> |
| 741 | { |
| 742 | _Sp (_Tp::*__p_)(_Ap); |
| 743 | public: |
| 744 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) |
| 745 | : __p_(__p) {} |
| 746 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const |
| 747 | {return (__p->*__p_)(__x);} |
| 748 | }; |
| 749 | |
| 750 | template<class _Sp, class _Tp> |
| 751 | inline _LIBCPP_INLINE_VISIBILITY |
| 752 | mem_fun_t<_Sp,_Tp> |
| 753 | mem_fun(_Sp (_Tp::*__f)()) |
| 754 | {return mem_fun_t<_Sp,_Tp>(__f);} |
| 755 | |
| 756 | template<class _Sp, class _Tp, class _Ap> |
| 757 | inline _LIBCPP_INLINE_VISIBILITY |
| 758 | mem_fun1_t<_Sp,_Tp,_Ap> |
| 759 | mem_fun(_Sp (_Tp::*__f)(_Ap)) |
| 760 | {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 761 | |
| 762 | template<class _Sp, class _Tp> |
| 763 | class mem_fun_ref_t : public unary_function<_Tp, _Sp> |
| 764 | { |
| 765 | _Sp (_Tp::*__p_)(); |
| 766 | public: |
| 767 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) |
| 768 | : __p_(__p) {} |
| 769 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const |
| 770 | {return (__p.*__p_)();} |
| 771 | }; |
| 772 | |
| 773 | template<class _Sp, class _Tp, class _Ap> |
| 774 | class mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> |
| 775 | { |
| 776 | _Sp (_Tp::*__p_)(_Ap); |
| 777 | public: |
| 778 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) |
| 779 | : __p_(__p) {} |
| 780 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const |
| 781 | {return (__p.*__p_)(__x);} |
| 782 | }; |
| 783 | |
| 784 | template<class _Sp, class _Tp> |
| 785 | inline _LIBCPP_INLINE_VISIBILITY |
| 786 | mem_fun_ref_t<_Sp,_Tp> |
| 787 | mem_fun_ref(_Sp (_Tp::*__f)()) |
| 788 | {return mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 789 | |
| 790 | template<class _Sp, class _Tp, class _Ap> |
| 791 | inline _LIBCPP_INLINE_VISIBILITY |
| 792 | mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 793 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) |
| 794 | {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 795 | |
| 796 | template <class _Sp, class _Tp> |
| 797 | class const_mem_fun_t : public unary_function<const _Tp*, _Sp> |
| 798 | { |
| 799 | _Sp (_Tp::*__p_)() const; |
| 800 | public: |
| 801 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) |
| 802 | : __p_(__p) {} |
| 803 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const |
| 804 | {return (__p->*__p_)();} |
| 805 | }; |
| 806 | |
| 807 | template <class _Sp, class _Tp, class _Ap> |
| 808 | class const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> |
| 809 | { |
| 810 | _Sp (_Tp::*__p_)(_Ap) const; |
| 811 | public: |
| 812 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) |
| 813 | : __p_(__p) {} |
| 814 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const |
| 815 | {return (__p->*__p_)(__x);} |
| 816 | }; |
| 817 | |
| 818 | template <class _Sp, class _Tp> |
| 819 | inline _LIBCPP_INLINE_VISIBILITY |
| 820 | const_mem_fun_t<_Sp,_Tp> |
| 821 | mem_fun(_Sp (_Tp::*__f)() const) |
| 822 | {return const_mem_fun_t<_Sp,_Tp>(__f);} |
| 823 | |
| 824 | template <class _Sp, class _Tp, class _Ap> |
| 825 | inline _LIBCPP_INLINE_VISIBILITY |
| 826 | const_mem_fun1_t<_Sp,_Tp,_Ap> |
| 827 | mem_fun(_Sp (_Tp::*__f)(_Ap) const) |
| 828 | {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 829 | |
| 830 | template <class _Sp, class _Tp> |
| 831 | class const_mem_fun_ref_t : public unary_function<_Tp, _Sp> |
| 832 | { |
| 833 | _Sp (_Tp::*__p_)() const; |
| 834 | public: |
| 835 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) |
| 836 | : __p_(__p) {} |
| 837 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const |
| 838 | {return (__p.*__p_)();} |
| 839 | }; |
| 840 | |
| 841 | template <class _Sp, class _Tp, class _Ap> |
| 842 | class const_mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> |
| 843 | { |
| 844 | _Sp (_Tp::*__p_)(_Ap) const; |
| 845 | public: |
| 846 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) |
| 847 | : __p_(__p) {} |
| 848 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const |
| 849 | {return (__p.*__p_)(__x);} |
| 850 | }; |
| 851 | |
| 852 | template <class _Sp, class _Tp> |
| 853 | inline _LIBCPP_INLINE_VISIBILITY |
| 854 | const_mem_fun_ref_t<_Sp,_Tp> |
| 855 | mem_fun_ref(_Sp (_Tp::*__f)() const) |
| 856 | {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 857 | |
| 858 | template <class _Sp, class _Tp, class _Ap> |
| 859 | inline _LIBCPP_INLINE_VISIBILITY |
| 860 | const_mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 861 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) |
| 862 | {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 863 | |
| 864 | |
| 865 | #ifdef _LIBCPP_HAS_NO_VARIADICS |
| 866 | |
| 867 | #include <__functional_03> |
| 868 | |
| 869 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 870 | |
| 871 | template <class _Tp> |
| 872 | class __mem_fn |
| 873 | : public __weak_result_type<_Tp> |
| 874 | { |
| 875 | public: |
| 876 | // types |
| 877 | typedef _Tp type; |
| 878 | private: |
| 879 | type __f_; |
| 880 | |
| 881 | public: |
| 882 | _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} |
| 883 | |
| 884 | // invoke |
| 885 | template <class... _ArgTypes> |
| 886 | typename __invoke_return<type, _ArgTypes...>::type |
| 887 | operator() (_ArgTypes&&... __args) |
| 888 | { |
| 889 | return __invoke(__f_, _STD::forward<_ArgTypes>(__args)...); |
| 890 | } |
| 891 | }; |
| 892 | |
| 893 | template<class _R, class _T> |
| 894 | inline _LIBCPP_INLINE_VISIBILITY |
| 895 | __mem_fn<_R _T::*> |
| 896 | mem_fn(_R _T::* __pm) |
| 897 | { |
| 898 | return __mem_fn<_R _T::*>(__pm); |
| 899 | } |
| 900 | |
| 901 | template<class _R, class _T, class ..._Args> |
| 902 | inline _LIBCPP_INLINE_VISIBILITY |
| 903 | __mem_fn<_R (_T::*)(_Args...)> |
| 904 | mem_fn(_R (_T::* __pm)(_Args...)) |
| 905 | { |
| 906 | return __mem_fn<_R (_T::*)(_Args...)>(__pm); |
| 907 | } |
| 908 | |
| 909 | template<class _R, class _T, class ..._Args> |
| 910 | inline _LIBCPP_INLINE_VISIBILITY |
| 911 | __mem_fn<_R (_T::*)(_Args...) const> |
| 912 | mem_fn(_R (_T::* __pm)(_Args...) const) |
| 913 | { |
| 914 | return __mem_fn<_R (_T::*)(_Args...) const>(__pm); |
| 915 | } |
| 916 | |
| 917 | template<class _R, class _T, class ..._Args> |
| 918 | inline _LIBCPP_INLINE_VISIBILITY |
| 919 | __mem_fn<_R (_T::*)(_Args...) volatile> |
| 920 | mem_fn(_R (_T::* __pm)(_Args...) volatile) |
| 921 | { |
| 922 | return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm); |
| 923 | } |
| 924 | |
| 925 | template<class _R, class _T, class ..._Args> |
| 926 | inline _LIBCPP_INLINE_VISIBILITY |
| 927 | __mem_fn<_R (_T::*)(_Args...) const volatile> |
| 928 | mem_fn(_R (_T::* __pm)(_Args...) const volatile) |
| 929 | { |
| 930 | return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm); |
| 931 | } |
| 932 | |
| 933 | // bad_function_call |
| 934 | |
| 935 | class bad_function_call |
| 936 | : public exception |
| 937 | { |
| 938 | }; |
| 939 | |
| 940 | template<class _Fp> class function; // undefined |
| 941 | |
| 942 | namespace __function |
| 943 | { |
| 944 | |
| 945 | template<class _R, class ..._ArgTypes> |
| 946 | struct __maybe_derive_from_unary_function |
| 947 | { |
| 948 | }; |
| 949 | |
| 950 | template<class _R, class _A1> |
| 951 | struct __maybe_derive_from_unary_function<_R(_A1)> |
| 952 | : public unary_function<_A1, _R> |
| 953 | { |
| 954 | }; |
| 955 | |
| 956 | template<class _R, class ..._ArgTypes> |
| 957 | struct __maybe_derive_from_binary_function |
| 958 | { |
| 959 | }; |
| 960 | |
| 961 | template<class _R, class _A1, class _A2> |
| 962 | struct __maybe_derive_from_binary_function<_R(_A1, _A2)> |
| 963 | : public binary_function<_A1, _A2, _R> |
| 964 | { |
| 965 | }; |
| 966 | |
| 967 | template<class _Fp> class __base; |
| 968 | |
| 969 | template<class _R, class ..._ArgTypes> |
| 970 | class __base<_R(_ArgTypes...)> |
| 971 | { |
| 972 | __base(const __base&); |
| 973 | __base& operator=(const __base&); |
| 974 | public: |
| 975 | __base() {} |
| 976 | virtual ~__base() {} |
| 977 | virtual __base* __clone() const = 0; |
| 978 | virtual void __clone(__base*) const = 0; |
| 979 | virtual void destroy() = 0; |
| 980 | virtual void destroy_deallocate() = 0; |
| 981 | virtual _R operator()(_ArgTypes&& ...) = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 982 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 983 | virtual const void* target(const type_info&) const = 0; |
| 984 | virtual const std::type_info& target_type() const = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 985 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 986 | }; |
| 987 | |
| 988 | template<class _FD, class _Alloc, class _FB> class __func; |
| 989 | |
| 990 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 991 | class __func<_F, _Alloc, _R(_ArgTypes...)> |
| 992 | : public __base<_R(_ArgTypes...)> |
| 993 | { |
| 994 | __compressed_pair<_F, _Alloc> __f_; |
| 995 | public: |
| 996 | explicit __func(_F __f) : __f_(_STD::move(__f)) {} |
| 997 | explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {} |
| 998 | virtual __base<_R(_ArgTypes...)>* __clone() const; |
| 999 | virtual void __clone(__base<_R(_ArgTypes...)>*) const; |
| 1000 | virtual void destroy(); |
| 1001 | virtual void destroy_deallocate(); |
| 1002 | virtual _R operator()(_ArgTypes&& ... __arg); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1003 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1004 | virtual const void* target(const type_info&) const; |
| 1005 | virtual const std::type_info& target_type() const; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1006 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1007 | }; |
| 1008 | |
| 1009 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1010 | __base<_R(_ArgTypes...)>* |
| 1011 | __func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const |
| 1012 | { |
| 1013 | typedef typename _Alloc::template rebind<__func>::other _A; |
| 1014 | _A __a(__f_.second()); |
| 1015 | typedef __allocator_destructor<_A> _D; |
| 1016 | unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1017 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 1018 | return __hold.release(); |
| 1019 | } |
| 1020 | |
| 1021 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1022 | void |
| 1023 | __func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const |
| 1024 | { |
| 1025 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 1026 | } |
| 1027 | |
| 1028 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1029 | void |
| 1030 | __func<_F, _Alloc, _R(_ArgTypes...)>::destroy() |
| 1031 | { |
| 1032 | __f_.~__compressed_pair<_F, _Alloc>(); |
| 1033 | } |
| 1034 | |
| 1035 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1036 | void |
| 1037 | __func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() |
| 1038 | { |
| 1039 | typedef typename _Alloc::template rebind<__func>::other _A; |
| 1040 | _A __a(__f_.second()); |
| 1041 | __f_.~__compressed_pair<_F, _Alloc>(); |
| 1042 | __a.deallocate(this, 1); |
| 1043 | } |
| 1044 | |
| 1045 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1046 | _R |
| 1047 | __func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) |
| 1048 | { |
| 1049 | return __invoke(__f_.first(), _STD::forward<_ArgTypes>(__arg)...); |
| 1050 | } |
| 1051 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1052 | #ifndef _LIBCPP_NO_RTTI |
| 1053 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1054 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1055 | const void* |
| 1056 | __func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const |
| 1057 | { |
| 1058 | if (__ti == typeid(_F)) |
| 1059 | return &__f_.first(); |
| 1060 | return (const void*)0; |
| 1061 | } |
| 1062 | |
| 1063 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1064 | const std::type_info& |
| 1065 | __func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const |
| 1066 | { |
| 1067 | return typeid(_F); |
| 1068 | } |
| 1069 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1070 | #endif |
| 1071 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | } // __function |
| 1073 | |
| 1074 | template<class _R, class ..._ArgTypes> |
| 1075 | class function<_R(_ArgTypes...)> |
| 1076 | : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>, |
| 1077 | public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)> |
| 1078 | { |
| 1079 | typedef __function::__base<_R(_ArgTypes...)> __base; |
| 1080 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1081 | __base* __f_; |
| 1082 | |
| 1083 | template <class _F> |
| 1084 | static bool __not_null(const _F&) {return true;} |
| 1085 | template <class _R2, class ..._A> |
| 1086 | static bool __not_null(_R2 (*__p)(_A...)) {return __p;} |
| 1087 | template <class _R2, class _C, class ..._A> |
| 1088 | static bool __not_null(_R2 (_C::*__p)(_A...)) {return __p;} |
| 1089 | template <class _R2, class _C, class ..._A> |
| 1090 | static bool __not_null(_R2 (_C::*__p)(_A...) const) {return __p;} |
| 1091 | template <class _R2, class _C, class ..._A> |
| 1092 | static bool __not_null(_R2 (_C::*__p)(_A...) volatile) {return __p;} |
| 1093 | template <class _R2, class _C, class ..._A> |
| 1094 | static bool __not_null(_R2 (_C::*__p)(_A...) const volatile) {return __p;} |
| 1095 | template <class _R2, class ..._A> |
| 1096 | static bool __not_null(const function<_R(_A...)>& __p) {return __p;} |
| 1097 | public: |
| 1098 | typedef _R result_type; |
| 1099 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1100 | // construct/copy/destroy: |
Howard Hinnant | e00e030 | 2010-08-19 19:20:10 +0000 | [diff] [blame] | 1101 | function() : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1102 | function(nullptr_t) : __f_(0) {} |
| 1103 | function(const function&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1104 | function(function&&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1105 | template<class _F> |
| 1106 | function(_F, |
| 1107 | typename enable_if<!is_integral<_F>::value>::type* = 0); |
| 1108 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1109 | template<class _Alloc> |
| 1110 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 1111 | template<class _Alloc> |
| 1112 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 1113 | template<class _Alloc> |
| 1114 | function(allocator_arg_t, const _Alloc&, const function&); |
| 1115 | template<class _Alloc> |
| 1116 | function(allocator_arg_t, const _Alloc&, function&&); |
| 1117 | template<class _F, class _Alloc> |
| 1118 | function(allocator_arg_t, const _Alloc& __a, _F __f, |
| 1119 | typename enable_if<!is_integral<_F>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1120 | |
| 1121 | function& operator=(const function&); |
| 1122 | function& operator=(function&&); |
| 1123 | function& operator=(nullptr_t); |
| 1124 | template<class _F> |
| 1125 | typename enable_if |
| 1126 | < |
| 1127 | !is_integral<typename decay<_F>::type>::value, |
| 1128 | function& |
| 1129 | >::type |
| 1130 | operator=(_F&&); |
| 1131 | |
| 1132 | ~function(); |
| 1133 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1134 | // function modifiers: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1135 | void swap(function&); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1136 | template<class _F, class _Alloc> |
| 1137 | void assign(_F&& __f, const _Alloc& __a) |
| 1138 | {function(allocator_arg, __a, _STD::forward<_F>(__f)).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1139 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1140 | // function capacity: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1141 | /*explicit*/ operator bool() const {return __f_;} |
| 1142 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1143 | // deleted overloads close possible hole in the type system |
| 1144 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1145 | bool operator==(const function<_R2(_ArgTypes2...)>&) = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1146 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1147 | bool operator!=(const function<_R2(_ArgTypes2...)>&) = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1148 | public: |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1149 | // function invocation: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1150 | _R operator()(_ArgTypes...) const; |
| 1151 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1152 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1153 | // function target access: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | const std::type_info& target_type() const; |
| 1155 | template <typename _T> _T* target(); |
| 1156 | template <typename _T> const _T* target() const; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1157 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1158 | }; |
| 1159 | |
| 1160 | template<class _R, class ..._ArgTypes> |
| 1161 | function<_R(_ArgTypes...)>::function(const function& __f) |
| 1162 | { |
| 1163 | if (__f.__f_ == 0) |
| 1164 | __f_ = 0; |
| 1165 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1166 | { |
| 1167 | __f_ = (__base*)&__buf_; |
| 1168 | __f.__f_->__clone(__f_); |
| 1169 | } |
| 1170 | else |
| 1171 | __f_ = __f.__f_->__clone(); |
| 1172 | } |
| 1173 | |
| 1174 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1175 | template <class _Alloc> |
| 1176 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
| 1177 | const function& __f) |
| 1178 | { |
| 1179 | if (__f.__f_ == 0) |
| 1180 | __f_ = 0; |
| 1181 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1182 | { |
| 1183 | __f_ = (__base*)&__buf_; |
| 1184 | __f.__f_->__clone(__f_); |
| 1185 | } |
| 1186 | else |
| 1187 | __f_ = __f.__f_->__clone(); |
| 1188 | } |
| 1189 | |
| 1190 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1191 | function<_R(_ArgTypes...)>::function(function&& __f) |
| 1192 | { |
| 1193 | if (__f.__f_ == 0) |
| 1194 | __f_ = 0; |
| 1195 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1196 | { |
| 1197 | __f_ = (__base*)&__buf_; |
| 1198 | __f.__f_->__clone(__f_); |
| 1199 | } |
| 1200 | else |
| 1201 | { |
| 1202 | __f_ = __f.__f_; |
| 1203 | __f.__f_ = 0; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1208 | template <class _Alloc> |
| 1209 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
| 1210 | function&& __f) |
| 1211 | { |
| 1212 | if (__f.__f_ == 0) |
| 1213 | __f_ = 0; |
| 1214 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1215 | { |
| 1216 | __f_ = (__base*)&__buf_; |
| 1217 | __f.__f_->__clone(__f_); |
| 1218 | } |
| 1219 | else |
| 1220 | { |
| 1221 | __f_ = __f.__f_; |
| 1222 | __f.__f_ = 0; |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1227 | template <class _F> |
| 1228 | function<_R(_ArgTypes...)>::function(_F __f, |
| 1229 | typename enable_if<!is_integral<_F>::value>::type*) |
| 1230 | : __f_(0) |
| 1231 | { |
| 1232 | if (__not_null(__f)) |
| 1233 | { |
| 1234 | typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF; |
| 1235 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1236 | { |
| 1237 | __f_ = (__base*)&__buf_; |
| 1238 | ::new (__f_) _FF(_STD::move(__f)); |
| 1239 | } |
| 1240 | else |
| 1241 | { |
| 1242 | typedef allocator<_FF> _A; |
| 1243 | _A __a; |
| 1244 | typedef __allocator_destructor<_A> _D; |
| 1245 | unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1246 | ::new (__hold.get()) _FF(_STD::move(__f), allocator<_F>(__a)); |
| 1247 | __f_ = __hold.release(); |
| 1248 | } |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame^] | 1253 | template <class _F, class _Alloc> |
| 1254 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f, |
| 1255 | typename enable_if<!is_integral<_F>::value>::type*) |
| 1256 | : __f_(0) |
| 1257 | { |
| 1258 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1259 | if (__not_null(__f)) |
| 1260 | { |
| 1261 | typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF; |
| 1262 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1263 | { |
| 1264 | __f_ = (__base*)&__buf_; |
| 1265 | ::new (__f_) _FF(_STD::move(__f)); |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | typedef typename __alloc_traits::template |
| 1270 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1271 | rebind_alloc<_FF> |
| 1272 | #else |
| 1273 | rebind_alloc<_FF>::other |
| 1274 | #endif |
| 1275 | _A; |
| 1276 | _A __a(__a0); |
| 1277 | typedef __allocator_destructor<_A> _D; |
| 1278 | unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1279 | ::new (__hold.get()) _FF(_STD::move(__f), _Alloc(__a)); |
| 1280 | __f_ = __hold.release(); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1286 | function<_R(_ArgTypes...)>& |
| 1287 | function<_R(_ArgTypes...)>::operator=(const function& __f) |
| 1288 | { |
| 1289 | function(__f).swap(*this); |
| 1290 | return *this; |
| 1291 | } |
| 1292 | |
| 1293 | template<class _R, class ..._ArgTypes> |
| 1294 | function<_R(_ArgTypes...)>& |
| 1295 | function<_R(_ArgTypes...)>::operator=(function&& __f) |
| 1296 | { |
| 1297 | if (__f_ == (__base*)&__buf_) |
| 1298 | __f_->destroy(); |
| 1299 | else if (__f_) |
| 1300 | __f_->destroy_deallocate(); |
| 1301 | __f_ = 0; |
| 1302 | if (__f.__f_ == 0) |
| 1303 | __f_ = 0; |
| 1304 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1305 | { |
| 1306 | __f_ = (__base*)&__buf_; |
| 1307 | __f.__f_->__clone(__f_); |
| 1308 | } |
| 1309 | else |
| 1310 | { |
| 1311 | __f_ = __f.__f_; |
| 1312 | __f.__f_ = 0; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | template<class _R, class ..._ArgTypes> |
| 1317 | function<_R(_ArgTypes...)>& |
| 1318 | function<_R(_ArgTypes...)>::operator=(nullptr_t) |
| 1319 | { |
| 1320 | if (__f_ == (__base*)&__buf_) |
| 1321 | __f_->destroy(); |
| 1322 | else if (__f_) |
| 1323 | __f_->destroy_deallocate(); |
| 1324 | __f_ = 0; |
| 1325 | } |
| 1326 | |
| 1327 | template<class _R, class ..._ArgTypes> |
| 1328 | template <class _F> |
| 1329 | typename enable_if |
| 1330 | < |
| 1331 | !is_integral<typename decay<_F>::type>::value, |
| 1332 | function<_R(_ArgTypes...)>& |
| 1333 | >::type |
| 1334 | function<_R(_ArgTypes...)>::operator=(_F&& __f) |
| 1335 | { |
| 1336 | function(_STD::forward<_F>(__f)).swap(*this); |
| 1337 | return *this; |
| 1338 | } |
| 1339 | |
| 1340 | template<class _R, class ..._ArgTypes> |
| 1341 | function<_R(_ArgTypes...)>::~function() |
| 1342 | { |
| 1343 | if (__f_ == (__base*)&__buf_) |
| 1344 | __f_->destroy(); |
| 1345 | else if (__f_) |
| 1346 | __f_->destroy_deallocate(); |
| 1347 | } |
| 1348 | |
| 1349 | template<class _R, class ..._ArgTypes> |
| 1350 | void |
| 1351 | function<_R(_ArgTypes...)>::swap(function& __f) |
| 1352 | { |
| 1353 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1354 | { |
| 1355 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1356 | __base* __t = (__base*)&__tempbuf; |
| 1357 | __f_->__clone(__t); |
| 1358 | __f_->destroy(); |
| 1359 | __f_ = 0; |
| 1360 | __f.__f_->__clone((__base*)&__buf_); |
| 1361 | __f.__f_->destroy(); |
| 1362 | __f.__f_ = 0; |
| 1363 | __f_ = (__base*)&__buf_; |
| 1364 | __t->__clone((__base*)&__f.__buf_); |
| 1365 | __t->destroy(); |
| 1366 | __f.__f_ = (__base*)&__f.__buf_; |
| 1367 | } |
| 1368 | else if (__f_ == (__base*)&__buf_) |
| 1369 | { |
| 1370 | __f_->__clone((__base*)&__f.__buf_); |
| 1371 | __f_->destroy(); |
| 1372 | __f_ = __f.__f_; |
| 1373 | __f.__f_ = (__base*)&__f.__buf_; |
| 1374 | } |
| 1375 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1376 | { |
| 1377 | __f.__f_->__clone((__base*)&__buf_); |
| 1378 | __f.__f_->destroy(); |
| 1379 | __f.__f_ = __f_; |
| 1380 | __f_ = (__base*)&__buf_; |
| 1381 | } |
| 1382 | else |
| 1383 | _STD::swap(__f_, __f.__f_); |
| 1384 | } |
| 1385 | |
| 1386 | template<class _R, class ..._ArgTypes> |
| 1387 | _R |
| 1388 | function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const |
| 1389 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1390 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1391 | if (__f_ == 0) |
| 1392 | throw bad_function_call(); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1393 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1394 | return (*__f_)(_STD::forward<_ArgTypes>(__arg)...); |
| 1395 | } |
| 1396 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1397 | #ifndef _LIBCPP_NO_RTTI |
| 1398 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1399 | template<class _R, class ..._ArgTypes> |
| 1400 | const std::type_info& |
| 1401 | function<_R(_ArgTypes...)>::target_type() const |
| 1402 | { |
| 1403 | if (__f_ == 0) |
| 1404 | return typeid(void); |
| 1405 | return __f_->target_type(); |
| 1406 | } |
| 1407 | |
| 1408 | template<class _R, class ..._ArgTypes> |
| 1409 | template <typename _T> |
| 1410 | _T* |
| 1411 | function<_R(_ArgTypes...)>::target() |
| 1412 | { |
| 1413 | if (__f_ == 0) |
| 1414 | return (_T*)0; |
| 1415 | return (_T*)__f_->target(typeid(_T)); |
| 1416 | } |
| 1417 | |
| 1418 | template<class _R, class ..._ArgTypes> |
| 1419 | template <typename _T> |
| 1420 | const _T* |
| 1421 | function<_R(_ArgTypes...)>::target() const |
| 1422 | { |
| 1423 | if (__f_ == 0) |
| 1424 | return (const _T*)0; |
| 1425 | return (const _T*)__f_->target(typeid(_T)); |
| 1426 | } |
| 1427 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1428 | #endif |
| 1429 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | template <class _R, class... _ArgTypes> |
| 1431 | inline _LIBCPP_INLINE_VISIBILITY |
| 1432 | bool |
| 1433 | operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return !__f;} |
| 1434 | |
| 1435 | template <class _R, class... _ArgTypes> |
| 1436 | inline _LIBCPP_INLINE_VISIBILITY |
| 1437 | bool |
| 1438 | operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return !__f;} |
| 1439 | |
| 1440 | template <class _R, class... _ArgTypes> |
| 1441 | inline _LIBCPP_INLINE_VISIBILITY |
| 1442 | bool |
| 1443 | operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return (bool)__f;} |
| 1444 | |
| 1445 | template <class _R, class... _ArgTypes> |
| 1446 | inline _LIBCPP_INLINE_VISIBILITY |
| 1447 | bool |
| 1448 | operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return (bool)__f;} |
| 1449 | |
| 1450 | template <class _R, class... _ArgTypes> |
| 1451 | inline _LIBCPP_INLINE_VISIBILITY |
| 1452 | void |
| 1453 | swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) |
| 1454 | {return __x.swap(__y);} |
| 1455 | |
| 1456 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
| 1457 | template<class _Tp> struct is_bind_expression |
| 1458 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 1459 | |
| 1460 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
| 1461 | template<class _Tp> struct is_placeholder |
| 1462 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 1463 | |
| 1464 | namespace placeholders |
| 1465 | { |
| 1466 | |
| 1467 | template <int _N> struct __ph {}; |
| 1468 | |
| 1469 | extern __ph<1> _1; |
| 1470 | extern __ph<2> _2; |
| 1471 | extern __ph<3> _3; |
| 1472 | extern __ph<4> _4; |
| 1473 | extern __ph<5> _5; |
| 1474 | extern __ph<6> _6; |
| 1475 | extern __ph<7> _7; |
| 1476 | extern __ph<8> _8; |
| 1477 | extern __ph<9> _9; |
| 1478 | extern __ph<10> _10; |
| 1479 | |
| 1480 | } // placeholders |
| 1481 | |
| 1482 | template<int _N> |
| 1483 | struct __is_placeholder<placeholders::__ph<_N> > |
| 1484 | : public integral_constant<int, _N> {}; |
| 1485 | |
| 1486 | template <class _Tp, class _Uj> |
| 1487 | inline _LIBCPP_INLINE_VISIBILITY |
| 1488 | _Tp& |
| 1489 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 1490 | { |
| 1491 | return __t.get(); |
| 1492 | } |
| 1493 | |
| 1494 | template <bool _IsBindExpr, class _Ti, class ..._Uj> |
| 1495 | struct __mu_return1 {}; |
| 1496 | |
| 1497 | template <class _Ti, class ..._Uj> |
| 1498 | struct __mu_return1<true, _Ti, _Uj...> |
| 1499 | { |
| 1500 | typedef typename result_of<_Ti(_Uj...)>::type type; |
| 1501 | }; |
| 1502 | |
| 1503 | |
| 1504 | template <class _Ti, class ..._Uj, size_t ..._Indx> |
| 1505 | inline _LIBCPP_INLINE_VISIBILITY |
| 1506 | typename __mu_return1<true, _Ti, _Uj...>::type |
| 1507 | __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>) |
| 1508 | { |
| 1509 | return __ti(_STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj))...); |
| 1510 | } |
| 1511 | |
| 1512 | template <class _Ti, class ..._Uj> |
| 1513 | inline _LIBCPP_INLINE_VISIBILITY |
| 1514 | typename enable_if |
| 1515 | < |
| 1516 | is_bind_expression<_Ti>::value, |
| 1517 | typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type |
| 1518 | >::type |
| 1519 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) |
| 1520 | { |
| 1521 | typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; |
| 1522 | return __mu_expand(__ti, __uj, __indices()); |
| 1523 | } |
| 1524 | |
| 1525 | template <bool IsPh, class _Ti, class _Uj> |
| 1526 | struct __mu_return2 {}; |
| 1527 | |
| 1528 | template <class _Ti, class _Uj> |
| 1529 | struct __mu_return2<true, _Ti, _Uj> |
| 1530 | { |
| 1531 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; |
| 1532 | }; |
| 1533 | |
| 1534 | template <class _Ti, class _Uj> |
| 1535 | inline _LIBCPP_INLINE_VISIBILITY |
| 1536 | typename enable_if |
| 1537 | < |
| 1538 | 0 < is_placeholder<_Ti>::value, |
| 1539 | typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type |
| 1540 | >::type |
| 1541 | __mu(_Ti&, _Uj& __uj) |
| 1542 | { |
| 1543 | const size_t _Indx = is_placeholder<_Ti>::value - 1; |
| 1544 | // compiler bug workaround |
| 1545 | typename tuple_element<_Indx, _Uj>::type __t = get<_Indx>(__uj); |
| 1546 | return __t; |
| 1547 | // return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj)); |
| 1548 | } |
| 1549 | |
| 1550 | template <class _Ti, class _Uj> |
| 1551 | inline _LIBCPP_INLINE_VISIBILITY |
| 1552 | typename enable_if |
| 1553 | < |
| 1554 | !is_bind_expression<_Ti>::value && |
| 1555 | is_placeholder<_Ti>::value == 0 && |
| 1556 | !__is_reference_wrapper<_Ti>::value, |
| 1557 | _Ti& |
| 1558 | >::type |
| 1559 | __mu(_Ti& __ti, _Uj& __uj) |
| 1560 | { |
| 1561 | return __ti; |
| 1562 | } |
| 1563 | |
| 1564 | template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj> |
| 1565 | struct ____mu_return; |
| 1566 | |
| 1567 | template <class _Ti, class ..._Uj> |
| 1568 | struct ____mu_return<_Ti, true, false, tuple<_Uj...> > |
| 1569 | { |
| 1570 | typedef typename result_of<_Ti(_Uj...)>::type type; |
| 1571 | }; |
| 1572 | |
| 1573 | template <class _Ti, class _TupleUj> |
| 1574 | struct ____mu_return<_Ti, false, true, _TupleUj> |
| 1575 | { |
| 1576 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 1577 | _TupleUj>::type&& type; |
| 1578 | }; |
| 1579 | |
| 1580 | template <class _Ti, class _TupleUj> |
| 1581 | struct ____mu_return<_Ti, false, false, _TupleUj> |
| 1582 | { |
| 1583 | typedef _Ti& type; |
| 1584 | }; |
| 1585 | |
| 1586 | template <class _Ti, class _TupleUj> |
| 1587 | struct __mu_return |
| 1588 | : public ____mu_return<_Ti, |
| 1589 | is_bind_expression<_Ti>::value, |
| 1590 | 0 < is_placeholder<_Ti>::value, |
| 1591 | _TupleUj> |
| 1592 | { |
| 1593 | }; |
| 1594 | |
| 1595 | template <class _Ti, class _TupleUj> |
| 1596 | struct __mu_return<reference_wrapper<_Ti>, _TupleUj> |
| 1597 | { |
| 1598 | typedef _Ti& type; |
| 1599 | }; |
| 1600 | |
| 1601 | template <class _F, class _BoundArgs, class _TupleUj> |
| 1602 | struct __bind_return; |
| 1603 | |
| 1604 | template <class _F, class ..._BoundArgs, class _TupleUj> |
| 1605 | struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj> |
| 1606 | { |
| 1607 | typedef typename __invoke_return |
| 1608 | < |
| 1609 | _F&, |
| 1610 | typename __mu_return |
| 1611 | < |
| 1612 | _BoundArgs, |
| 1613 | _TupleUj |
| 1614 | >::type... |
| 1615 | >::type type; |
| 1616 | }; |
| 1617 | |
| 1618 | template <class _F, class ..._BoundArgs, class _TupleUj> |
| 1619 | struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj> |
| 1620 | { |
| 1621 | typedef typename __invoke_return |
| 1622 | < |
| 1623 | _F&, |
| 1624 | typename __mu_return |
| 1625 | < |
| 1626 | const _BoundArgs, |
| 1627 | _TupleUj |
| 1628 | >::type... |
| 1629 | >::type type; |
| 1630 | }; |
| 1631 | |
| 1632 | template <class _F, class _BoundArgs, size_t ..._Indx, class _Args> |
| 1633 | inline _LIBCPP_INLINE_VISIBILITY |
| 1634 | typename __bind_return<_F, _BoundArgs, _Args>::type |
| 1635 | __apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
| 1636 | _Args&& __args) |
| 1637 | { |
| 1638 | return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); |
| 1639 | } |
| 1640 | |
| 1641 | template<class _F, class ..._BoundArgs> |
| 1642 | class __bind |
| 1643 | : public __weak_result_type<_F> |
| 1644 | { |
| 1645 | _F __f_; |
| 1646 | tuple<_BoundArgs...> __bound_args_; |
| 1647 | |
| 1648 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 1649 | public: |
| 1650 | __bind(__bind&& __b) |
| 1651 | : __f_(_STD::move(__b.__f_)), |
| 1652 | __bound_args_(_STD::move(__b.__bound_args_)) {} |
| 1653 | |
| 1654 | template <class _G, class ..._BA> |
| 1655 | explicit __bind(_G&& __f, _BA&& ...__bound_args) |
| 1656 | : __f_(_STD::forward<_G>(__f)), |
| 1657 | __bound_args_(_STD::forward<_BA>(__bound_args)...) {} |
| 1658 | |
| 1659 | template <class ..._Args> |
| 1660 | typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type |
| 1661 | operator()(_Args&& ...__args) |
| 1662 | { |
| 1663 | // compiler bug workaround |
| 1664 | return __apply_functor(__f_, __bound_args_, __indices(), |
| 1665 | tuple<_Args&&...>(__args...)); |
| 1666 | } |
| 1667 | |
| 1668 | template <class ..._Args> |
| 1669 | typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type |
| 1670 | operator()(_Args&& ...__args) const |
| 1671 | { |
| 1672 | return __apply_functor(__f_, __bound_args_, __indices(), |
| 1673 | tuple<_Args&&...>(__args...)); |
| 1674 | } |
| 1675 | }; |
| 1676 | |
| 1677 | template<class _F, class ..._BoundArgs> |
| 1678 | struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {}; |
| 1679 | |
| 1680 | template<class _R, class _F, class ..._BoundArgs> |
| 1681 | class __bind_r |
| 1682 | : public __bind<_F, _BoundArgs...> |
| 1683 | { |
| 1684 | typedef __bind<_F, _BoundArgs...> base; |
| 1685 | public: |
| 1686 | typedef _R result_type; |
| 1687 | |
| 1688 | template <class _G, class ..._BA> |
| 1689 | explicit __bind_r(_G&& __f, _BA&& ...__bound_args) |
| 1690 | : base(_STD::forward<_G>(__f), |
| 1691 | _STD::forward<_BA>(__bound_args)...) {} |
| 1692 | |
| 1693 | template <class ..._Args> |
| 1694 | result_type |
| 1695 | operator()(_Args&& ...__args) |
| 1696 | { |
| 1697 | return base::operator()(_STD::forward<_Args>(__args)...); |
| 1698 | } |
| 1699 | |
| 1700 | template <class ..._Args> |
| 1701 | result_type |
| 1702 | operator()(_Args&& ...__args) const |
| 1703 | { |
| 1704 | return base::operator()(_STD::forward<_Args>(__args)...); |
| 1705 | } |
| 1706 | }; |
| 1707 | |
| 1708 | template<class _R, class _F, class ..._BoundArgs> |
| 1709 | struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {}; |
| 1710 | |
| 1711 | template<class _F, class ..._BoundArgs> |
| 1712 | inline _LIBCPP_INLINE_VISIBILITY |
| 1713 | __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> |
| 1714 | bind(_F&& __f, _BoundArgs&&... __bound_args) |
| 1715 | { |
| 1716 | typedef __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> type; |
| 1717 | return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...); |
| 1718 | } |
| 1719 | |
| 1720 | template<class _R, class _F, class ..._BoundArgs> |
| 1721 | inline _LIBCPP_INLINE_VISIBILITY |
| 1722 | __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> |
| 1723 | bind(_F&& __f, _BoundArgs&&... __bound_args) |
| 1724 | { |
| 1725 | typedef __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> type; |
| 1726 | return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...); |
| 1727 | } |
| 1728 | |
| 1729 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1730 | |
| 1731 | template <> |
| 1732 | struct hash<bool> |
| 1733 | : public unary_function<bool, size_t> |
| 1734 | { |
| 1735 | size_t operator()(bool __v) const {return static_cast<size_t>(__v);} |
| 1736 | }; |
| 1737 | |
| 1738 | template <> |
| 1739 | struct hash<char> |
| 1740 | : public unary_function<char, size_t> |
| 1741 | { |
| 1742 | size_t operator()(char __v) const {return static_cast<size_t>(__v);} |
| 1743 | }; |
| 1744 | |
| 1745 | template <> |
| 1746 | struct hash<signed char> |
| 1747 | : public unary_function<signed char, size_t> |
| 1748 | { |
| 1749 | size_t operator()(signed char __v) const {return static_cast<size_t>(__v);} |
| 1750 | }; |
| 1751 | |
| 1752 | template <> |
| 1753 | struct hash<unsigned char> |
| 1754 | : public unary_function<unsigned char, size_t> |
| 1755 | { |
| 1756 | size_t operator()(unsigned char __v) const {return static_cast<size_t>(__v);} |
| 1757 | }; |
| 1758 | |
| 1759 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 1760 | |
| 1761 | template <> |
| 1762 | struct hash<char16_t> |
| 1763 | : public unary_function<char16_t, size_t> |
| 1764 | { |
| 1765 | size_t operator()(char16_t __v) const {return static_cast<size_t>(__v);} |
| 1766 | }; |
| 1767 | |
| 1768 | template <> |
| 1769 | struct hash<char32_t> |
| 1770 | : public unary_function<char32_t, size_t> |
| 1771 | { |
| 1772 | size_t operator()(char32_t __v) const {return static_cast<size_t>(__v);} |
| 1773 | }; |
| 1774 | |
| 1775 | #endif |
| 1776 | |
| 1777 | template <> |
| 1778 | struct hash<wchar_t> |
| 1779 | : public unary_function<wchar_t, size_t> |
| 1780 | { |
| 1781 | size_t operator()(wchar_t __v) const {return static_cast<size_t>(__v);} |
| 1782 | }; |
| 1783 | |
| 1784 | template <> |
| 1785 | struct hash<short> |
| 1786 | : public unary_function<short, size_t> |
| 1787 | { |
| 1788 | size_t operator()(short __v) const {return static_cast<size_t>(__v);} |
| 1789 | }; |
| 1790 | |
| 1791 | template <> |
| 1792 | struct hash<unsigned short> |
| 1793 | : public unary_function<unsigned short, size_t> |
| 1794 | { |
| 1795 | size_t operator()(unsigned short __v) const {return static_cast<size_t>(__v);} |
| 1796 | }; |
| 1797 | |
| 1798 | template <> |
| 1799 | struct hash<int> |
| 1800 | : public unary_function<int, size_t> |
| 1801 | { |
| 1802 | size_t operator()(int __v) const {return static_cast<size_t>(__v);} |
| 1803 | }; |
| 1804 | |
| 1805 | template <> |
| 1806 | struct hash<unsigned int> |
| 1807 | : public unary_function<unsigned int, size_t> |
| 1808 | { |
| 1809 | size_t operator()(unsigned int __v) const {return static_cast<size_t>(__v);} |
| 1810 | }; |
| 1811 | |
| 1812 | template <> |
| 1813 | struct hash<long> |
| 1814 | : public unary_function<long, size_t> |
| 1815 | { |
| 1816 | size_t operator()(long __v) const {return static_cast<size_t>(__v);} |
| 1817 | }; |
| 1818 | |
| 1819 | template <> |
| 1820 | struct hash<unsigned long> |
| 1821 | : public unary_function<unsigned long, size_t> |
| 1822 | { |
| 1823 | size_t operator()(unsigned long __v) const {return static_cast<size_t>(__v);} |
| 1824 | }; |
| 1825 | |
| 1826 | template <> |
| 1827 | struct hash<long long> |
| 1828 | : public unary_function<long long, size_t> |
| 1829 | { |
| 1830 | size_t operator()(long long __v) const |
| 1831 | { |
| 1832 | size_t __r = 0; |
| 1833 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1834 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1835 | __r ^= __p[__i]; |
| 1836 | return __r; |
| 1837 | } |
| 1838 | }; |
| 1839 | |
| 1840 | template <> |
| 1841 | struct hash<unsigned long long> |
| 1842 | : public unary_function<unsigned long long, size_t> |
| 1843 | { |
| 1844 | size_t operator()(unsigned long long __v) const |
| 1845 | { |
| 1846 | size_t __r = 0; |
| 1847 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1848 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1849 | __r ^= __p[__i]; |
| 1850 | return __r; |
| 1851 | } |
| 1852 | }; |
| 1853 | |
| 1854 | template <> |
| 1855 | struct hash<float> |
| 1856 | : public unary_function<float, size_t> |
| 1857 | { |
| 1858 | size_t operator()(float __v) const |
| 1859 | { |
| 1860 | if (__v == 0) |
| 1861 | return 0; |
| 1862 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1863 | return *__p; |
| 1864 | } |
| 1865 | }; |
| 1866 | |
| 1867 | template <> |
| 1868 | struct hash<double> |
| 1869 | : public unary_function<double, size_t> |
| 1870 | { |
| 1871 | size_t operator()(double __v) const |
| 1872 | { |
| 1873 | if (__v == 0) |
| 1874 | return 0; |
| 1875 | size_t __r = 0; |
| 1876 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1877 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1878 | __r ^= __p[__i]; |
| 1879 | return __r; |
| 1880 | } |
| 1881 | }; |
| 1882 | |
| 1883 | template <> |
| 1884 | struct hash<long double> |
| 1885 | : public unary_function<long double, size_t> |
| 1886 | { |
| 1887 | size_t operator()(long double __v) const |
| 1888 | { |
| 1889 | if (__v == 0) |
| 1890 | return 0; |
| 1891 | size_t __r = 0; |
| 1892 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1893 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1894 | __r ^= __p[__i]; |
| 1895 | return __r; |
| 1896 | } |
| 1897 | }; |
| 1898 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 1899 | // struct hash<T*> in <memory> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1900 | |
| 1901 | _LIBCPP_END_NAMESPACE_STD |
| 1902 | |
| 1903 | #endif // _LIBCPP_FUNCTIONAL |