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 |
| 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 | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 189 | template<class Fn, class... BoundArgs> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 190 | unspecified bind(Fn&&, BoundArgs&&...); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 191 | template<class R, class Fn, class... BoundArgs> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 192 | unspecified bind(Fn&&, BoundArgs&&...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 194 | namespace placeholders { |
| 195 | // M is the implementation-defined number of placeholders |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 196 | extern unspecified _1; |
| 197 | extern unspecified _2; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 198 | . |
| 199 | . |
| 200 | . |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | 324bb03 | 2010-08-22 00:02:43 +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 | 324bb03 | 2010-08-22 00:02:43 +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 | 324bb03 | 2010-08-22 00:02:43 +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 | 324bb03 | 2010-08-22 00:02:43 +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 | 324bb03 | 2010-08-22 00:02:43 +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> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 481 | struct _LIBCPP_VISIBLE plus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 482 | { |
| 483 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 484 | {return __x + __y;} |
| 485 | }; |
| 486 | |
| 487 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 488 | struct _LIBCPP_VISIBLE minus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 | { |
| 490 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 491 | {return __x - __y;} |
| 492 | }; |
| 493 | |
| 494 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 495 | struct _LIBCPP_VISIBLE multiplies : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 496 | { |
| 497 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 498 | {return __x * __y;} |
| 499 | }; |
| 500 | |
| 501 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 502 | struct _LIBCPP_VISIBLE divides : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | { |
| 504 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 505 | {return __x / __y;} |
| 506 | }; |
| 507 | |
| 508 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 509 | struct _LIBCPP_VISIBLE modulus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | { |
| 511 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 512 | {return __x % __y;} |
| 513 | }; |
| 514 | |
| 515 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 516 | struct _LIBCPP_VISIBLE negate : unary_function<_Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 517 | { |
| 518 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const |
| 519 | {return -__x;} |
| 520 | }; |
| 521 | |
| 522 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 523 | struct _LIBCPP_VISIBLE equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | { |
| 525 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 526 | {return __x == __y;} |
| 527 | }; |
| 528 | |
| 529 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 530 | struct _LIBCPP_VISIBLE not_equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 531 | { |
| 532 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 533 | {return __x != __y;} |
| 534 | }; |
| 535 | |
| 536 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 537 | struct _LIBCPP_VISIBLE greater : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 538 | { |
| 539 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 540 | {return __x > __y;} |
| 541 | }; |
| 542 | |
| 543 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 544 | struct _LIBCPP_VISIBLE less : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 545 | { |
| 546 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 547 | {return __x < __y;} |
| 548 | }; |
| 549 | |
| 550 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 551 | struct _LIBCPP_VISIBLE greater_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 552 | { |
| 553 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 554 | {return __x >= __y;} |
| 555 | }; |
| 556 | |
| 557 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 558 | struct _LIBCPP_VISIBLE less_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 559 | { |
| 560 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 561 | {return __x <= __y;} |
| 562 | }; |
| 563 | |
| 564 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 565 | struct _LIBCPP_VISIBLE logical_and : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | { |
| 567 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 568 | {return __x && __y;} |
| 569 | }; |
| 570 | |
| 571 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 572 | struct _LIBCPP_VISIBLE logical_or : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 573 | { |
| 574 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 575 | {return __x || __y;} |
| 576 | }; |
| 577 | |
| 578 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 579 | struct _LIBCPP_VISIBLE logical_not : unary_function<_Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | { |
| 581 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const |
| 582 | {return !__x;} |
| 583 | }; |
| 584 | |
| 585 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 586 | struct _LIBCPP_VISIBLE bit_and : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 587 | { |
| 588 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 589 | {return __x & __y;} |
| 590 | }; |
| 591 | |
| 592 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 593 | struct _LIBCPP_VISIBLE bit_or : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | { |
| 595 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 596 | {return __x | __y;} |
| 597 | }; |
| 598 | |
| 599 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 600 | struct _LIBCPP_VISIBLE bit_xor : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 601 | { |
| 602 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 603 | {return __x ^ __y;} |
| 604 | }; |
| 605 | |
| 606 | template <class _Predicate> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 607 | class _LIBCPP_VISIBLE unary_negate |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 624 | class _LIBCPP_VISIBLE binary_negate |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 644 | class _LIBCPP_VISIBLE binder1st |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 670 | class _LIBCPP_VISIBLE binder2nd |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 678 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 679 | binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) |
| 680 | : op(__x), value(__y) {} |
| 681 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 682 | ( typename __Operation::first_argument_type& __x) const |
| 683 | {return op(__x, value);} |
| 684 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 685 | (const typename __Operation::first_argument_type& __x) const |
| 686 | {return op(__x, value);} |
| 687 | }; |
| 688 | |
| 689 | template <class __Operation, class _Tp> |
| 690 | inline _LIBCPP_INLINE_VISIBILITY |
| 691 | binder2nd<__Operation> |
| 692 | bind2nd(const __Operation& __op, const _Tp& __x) |
| 693 | {return binder2nd<__Operation>(__op, __x);} |
| 694 | |
| 695 | template <class _Arg, class _Result> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 696 | class _LIBCPP_VISIBLE pointer_to_unary_function |
| 697 | : public unary_function<_Arg, _Result> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 698 | { |
| 699 | _Result (*__f_)(_Arg); |
| 700 | public: |
| 701 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) |
| 702 | : __f_(__f) {} |
| 703 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const |
| 704 | {return __f_(__x);} |
| 705 | }; |
| 706 | |
| 707 | template <class _Arg, class _Result> |
| 708 | inline _LIBCPP_INLINE_VISIBILITY |
| 709 | pointer_to_unary_function<_Arg,_Result> |
| 710 | ptr_fun(_Result (*__f)(_Arg)) |
| 711 | {return pointer_to_unary_function<_Arg,_Result>(__f);} |
| 712 | |
| 713 | template <class _Arg1, class _Arg2, class _Result> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 714 | class _LIBCPP_VISIBLE pointer_to_binary_function |
| 715 | : public binary_function<_Arg1, _Arg2, _Result> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 716 | { |
| 717 | _Result (*__f_)(_Arg1, _Arg2); |
| 718 | public: |
| 719 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) |
| 720 | : __f_(__f) {} |
| 721 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const |
| 722 | {return __f_(__x, __y);} |
| 723 | }; |
| 724 | |
| 725 | template <class _Arg1, class _Arg2, class _Result> |
| 726 | inline _LIBCPP_INLINE_VISIBILITY |
| 727 | pointer_to_binary_function<_Arg1,_Arg2,_Result> |
| 728 | ptr_fun(_Result (*__f)(_Arg1,_Arg2)) |
| 729 | {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} |
| 730 | |
| 731 | template<class _Sp, class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 732 | class _LIBCPP_VISIBLE mem_fun_t : public unary_function<_Tp*, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 733 | { |
| 734 | _Sp (_Tp::*__p_)(); |
| 735 | public: |
| 736 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) |
| 737 | : __p_(__p) {} |
| 738 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const |
| 739 | {return (__p->*__p_)();} |
| 740 | }; |
| 741 | |
| 742 | template<class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 743 | class _LIBCPP_VISIBLE mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 744 | { |
| 745 | _Sp (_Tp::*__p_)(_Ap); |
| 746 | public: |
| 747 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) |
| 748 | : __p_(__p) {} |
| 749 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const |
| 750 | {return (__p->*__p_)(__x);} |
| 751 | }; |
| 752 | |
| 753 | template<class _Sp, class _Tp> |
| 754 | inline _LIBCPP_INLINE_VISIBILITY |
| 755 | mem_fun_t<_Sp,_Tp> |
| 756 | mem_fun(_Sp (_Tp::*__f)()) |
| 757 | {return mem_fun_t<_Sp,_Tp>(__f);} |
| 758 | |
| 759 | template<class _Sp, class _Tp, class _Ap> |
| 760 | inline _LIBCPP_INLINE_VISIBILITY |
| 761 | mem_fun1_t<_Sp,_Tp,_Ap> |
| 762 | mem_fun(_Sp (_Tp::*__f)(_Ap)) |
| 763 | {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 764 | |
| 765 | template<class _Sp, class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 766 | class _LIBCPP_VISIBLE mem_fun_ref_t : public unary_function<_Tp, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 767 | { |
| 768 | _Sp (_Tp::*__p_)(); |
| 769 | public: |
| 770 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) |
| 771 | : __p_(__p) {} |
| 772 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const |
| 773 | {return (__p.*__p_)();} |
| 774 | }; |
| 775 | |
| 776 | template<class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 777 | class _LIBCPP_VISIBLE mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 778 | { |
| 779 | _Sp (_Tp::*__p_)(_Ap); |
| 780 | public: |
| 781 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) |
| 782 | : __p_(__p) {} |
| 783 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const |
| 784 | {return (__p.*__p_)(__x);} |
| 785 | }; |
| 786 | |
| 787 | template<class _Sp, class _Tp> |
| 788 | inline _LIBCPP_INLINE_VISIBILITY |
| 789 | mem_fun_ref_t<_Sp,_Tp> |
| 790 | mem_fun_ref(_Sp (_Tp::*__f)()) |
| 791 | {return mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 792 | |
| 793 | template<class _Sp, class _Tp, class _Ap> |
| 794 | inline _LIBCPP_INLINE_VISIBILITY |
| 795 | mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 796 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) |
| 797 | {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 798 | |
| 799 | template <class _Sp, class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 800 | class _LIBCPP_VISIBLE const_mem_fun_t : public unary_function<const _Tp*, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 801 | { |
| 802 | _Sp (_Tp::*__p_)() const; |
| 803 | public: |
| 804 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) |
| 805 | : __p_(__p) {} |
| 806 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const |
| 807 | {return (__p->*__p_)();} |
| 808 | }; |
| 809 | |
| 810 | template <class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 811 | class _LIBCPP_VISIBLE const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 812 | { |
| 813 | _Sp (_Tp::*__p_)(_Ap) const; |
| 814 | public: |
| 815 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) |
| 816 | : __p_(__p) {} |
| 817 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const |
| 818 | {return (__p->*__p_)(__x);} |
| 819 | }; |
| 820 | |
| 821 | template <class _Sp, class _Tp> |
| 822 | inline _LIBCPP_INLINE_VISIBILITY |
| 823 | const_mem_fun_t<_Sp,_Tp> |
| 824 | mem_fun(_Sp (_Tp::*__f)() const) |
| 825 | {return const_mem_fun_t<_Sp,_Tp>(__f);} |
| 826 | |
| 827 | template <class _Sp, class _Tp, class _Ap> |
| 828 | inline _LIBCPP_INLINE_VISIBILITY |
| 829 | const_mem_fun1_t<_Sp,_Tp,_Ap> |
| 830 | mem_fun(_Sp (_Tp::*__f)(_Ap) const) |
| 831 | {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 832 | |
| 833 | template <class _Sp, class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 834 | class _LIBCPP_VISIBLE const_mem_fun_ref_t : public unary_function<_Tp, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 835 | { |
| 836 | _Sp (_Tp::*__p_)() const; |
| 837 | public: |
| 838 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) |
| 839 | : __p_(__p) {} |
| 840 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const |
| 841 | {return (__p.*__p_)();} |
| 842 | }; |
| 843 | |
| 844 | template <class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 845 | class _LIBCPP_VISIBLE const_mem_fun1_ref_t |
| 846 | : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 847 | { |
| 848 | _Sp (_Tp::*__p_)(_Ap) const; |
| 849 | public: |
| 850 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) |
| 851 | : __p_(__p) {} |
| 852 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const |
| 853 | {return (__p.*__p_)(__x);} |
| 854 | }; |
| 855 | |
| 856 | template <class _Sp, class _Tp> |
| 857 | inline _LIBCPP_INLINE_VISIBILITY |
| 858 | const_mem_fun_ref_t<_Sp,_Tp> |
| 859 | mem_fun_ref(_Sp (_Tp::*__f)() const) |
| 860 | {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 861 | |
| 862 | template <class _Sp, class _Tp, class _Ap> |
| 863 | inline _LIBCPP_INLINE_VISIBILITY |
| 864 | const_mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 865 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) |
| 866 | {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 867 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | #ifdef _LIBCPP_HAS_NO_VARIADICS |
| 869 | |
| 870 | #include <__functional_03> |
| 871 | |
| 872 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 873 | |
| 874 | template <class _Tp> |
| 875 | class __mem_fn |
| 876 | : public __weak_result_type<_Tp> |
| 877 | { |
| 878 | public: |
| 879 | // types |
| 880 | typedef _Tp type; |
| 881 | private: |
| 882 | type __f_; |
| 883 | |
| 884 | public: |
| 885 | _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} |
| 886 | |
| 887 | // invoke |
| 888 | template <class... _ArgTypes> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 889 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 890 | typename __invoke_return<type, _ArgTypes...>::type |
| 891 | operator() (_ArgTypes&&... __args) |
| 892 | { |
| 893 | return __invoke(__f_, _STD::forward<_ArgTypes>(__args)...); |
| 894 | } |
| 895 | }; |
| 896 | |
| 897 | template<class _R, class _T> |
| 898 | inline _LIBCPP_INLINE_VISIBILITY |
| 899 | __mem_fn<_R _T::*> |
| 900 | mem_fn(_R _T::* __pm) |
| 901 | { |
| 902 | return __mem_fn<_R _T::*>(__pm); |
| 903 | } |
| 904 | |
| 905 | template<class _R, class _T, class ..._Args> |
| 906 | inline _LIBCPP_INLINE_VISIBILITY |
| 907 | __mem_fn<_R (_T::*)(_Args...)> |
| 908 | mem_fn(_R (_T::* __pm)(_Args...)) |
| 909 | { |
| 910 | return __mem_fn<_R (_T::*)(_Args...)>(__pm); |
| 911 | } |
| 912 | |
| 913 | template<class _R, class _T, class ..._Args> |
| 914 | inline _LIBCPP_INLINE_VISIBILITY |
| 915 | __mem_fn<_R (_T::*)(_Args...) const> |
| 916 | mem_fn(_R (_T::* __pm)(_Args...) const) |
| 917 | { |
| 918 | return __mem_fn<_R (_T::*)(_Args...) const>(__pm); |
| 919 | } |
| 920 | |
| 921 | template<class _R, class _T, class ..._Args> |
| 922 | inline _LIBCPP_INLINE_VISIBILITY |
| 923 | __mem_fn<_R (_T::*)(_Args...) volatile> |
| 924 | mem_fn(_R (_T::* __pm)(_Args...) volatile) |
| 925 | { |
| 926 | return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm); |
| 927 | } |
| 928 | |
| 929 | template<class _R, class _T, class ..._Args> |
| 930 | inline _LIBCPP_INLINE_VISIBILITY |
| 931 | __mem_fn<_R (_T::*)(_Args...) const volatile> |
| 932 | mem_fn(_R (_T::* __pm)(_Args...) const volatile) |
| 933 | { |
| 934 | return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm); |
| 935 | } |
| 936 | |
| 937 | // bad_function_call |
| 938 | |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 939 | class _LIBCPP_EXCEPTION_ABI bad_function_call |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 940 | : public exception |
| 941 | { |
| 942 | }; |
| 943 | |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 944 | template<class _Fp> class _LIBCPP_VISIBLE function; // undefined |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 945 | |
| 946 | namespace __function |
| 947 | { |
| 948 | |
| 949 | template<class _R, class ..._ArgTypes> |
| 950 | struct __maybe_derive_from_unary_function |
| 951 | { |
| 952 | }; |
| 953 | |
| 954 | template<class _R, class _A1> |
| 955 | struct __maybe_derive_from_unary_function<_R(_A1)> |
| 956 | : public unary_function<_A1, _R> |
| 957 | { |
| 958 | }; |
| 959 | |
| 960 | template<class _R, class ..._ArgTypes> |
| 961 | struct __maybe_derive_from_binary_function |
| 962 | { |
| 963 | }; |
| 964 | |
| 965 | template<class _R, class _A1, class _A2> |
| 966 | struct __maybe_derive_from_binary_function<_R(_A1, _A2)> |
| 967 | : public binary_function<_A1, _A2, _R> |
| 968 | { |
| 969 | }; |
| 970 | |
| 971 | template<class _Fp> class __base; |
| 972 | |
| 973 | template<class _R, class ..._ArgTypes> |
| 974 | class __base<_R(_ArgTypes...)> |
| 975 | { |
| 976 | __base(const __base&); |
| 977 | __base& operator=(const __base&); |
| 978 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 979 | _LIBCPP_INLINE_VISIBILITY __base() {} |
| 980 | _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 981 | virtual __base* __clone() const = 0; |
| 982 | virtual void __clone(__base*) const = 0; |
| 983 | virtual void destroy() = 0; |
| 984 | virtual void destroy_deallocate() = 0; |
| 985 | virtual _R operator()(_ArgTypes&& ...) = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 986 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 987 | virtual const void* target(const type_info&) const = 0; |
| 988 | virtual const std::type_info& target_type() const = 0; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 989 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 990 | }; |
| 991 | |
| 992 | template<class _FD, class _Alloc, class _FB> class __func; |
| 993 | |
| 994 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 995 | class __func<_F, _Alloc, _R(_ArgTypes...)> |
| 996 | : public __base<_R(_ArgTypes...)> |
| 997 | { |
| 998 | __compressed_pair<_F, _Alloc> __f_; |
| 999 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1001 | explicit __func(_F __f) : __f_(_STD::move(__f)) {} |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1002 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1003 | explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {} |
| 1004 | virtual __base<_R(_ArgTypes...)>* __clone() const; |
| 1005 | virtual void __clone(__base<_R(_ArgTypes...)>*) const; |
| 1006 | virtual void destroy(); |
| 1007 | virtual void destroy_deallocate(); |
| 1008 | virtual _R operator()(_ArgTypes&& ... __arg); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1009 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1010 | virtual const void* target(const type_info&) const; |
| 1011 | virtual const std::type_info& target_type() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1012 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1013 | }; |
| 1014 | |
| 1015 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1016 | __base<_R(_ArgTypes...)>* |
| 1017 | __func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const |
| 1018 | { |
| 1019 | typedef typename _Alloc::template rebind<__func>::other _A; |
| 1020 | _A __a(__f_.second()); |
| 1021 | typedef __allocator_destructor<_A> _D; |
| 1022 | unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1023 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 1024 | return __hold.release(); |
| 1025 | } |
| 1026 | |
| 1027 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1028 | void |
| 1029 | __func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const |
| 1030 | { |
| 1031 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 1032 | } |
| 1033 | |
| 1034 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1035 | void |
| 1036 | __func<_F, _Alloc, _R(_ArgTypes...)>::destroy() |
| 1037 | { |
| 1038 | __f_.~__compressed_pair<_F, _Alloc>(); |
| 1039 | } |
| 1040 | |
| 1041 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1042 | void |
| 1043 | __func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() |
| 1044 | { |
| 1045 | typedef typename _Alloc::template rebind<__func>::other _A; |
| 1046 | _A __a(__f_.second()); |
| 1047 | __f_.~__compressed_pair<_F, _Alloc>(); |
| 1048 | __a.deallocate(this, 1); |
| 1049 | } |
| 1050 | |
| 1051 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1052 | _R |
| 1053 | __func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) |
| 1054 | { |
| 1055 | return __invoke(__f_.first(), _STD::forward<_ArgTypes>(__arg)...); |
| 1056 | } |
| 1057 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1058 | #ifndef _LIBCPP_NO_RTTI |
| 1059 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1061 | const void* |
| 1062 | __func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const |
| 1063 | { |
| 1064 | if (__ti == typeid(_F)) |
| 1065 | return &__f_.first(); |
| 1066 | return (const void*)0; |
| 1067 | } |
| 1068 | |
| 1069 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1070 | const std::type_info& |
| 1071 | __func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const |
| 1072 | { |
| 1073 | return typeid(_F); |
| 1074 | } |
| 1075 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1076 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1077 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1078 | } // __function |
| 1079 | |
| 1080 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1081 | class _LIBCPP_VISIBLE function<_R(_ArgTypes...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1082 | : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>, |
| 1083 | public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)> |
| 1084 | { |
| 1085 | typedef __function::__base<_R(_ArgTypes...)> __base; |
| 1086 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1087 | __base* __f_; |
| 1088 | |
| 1089 | template <class _F> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1090 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1091 | static bool __not_null(const _F&) {return true;} |
| 1092 | template <class _R2, class ..._A> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1093 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1094 | static bool __not_null(_R2 (*__p)(_A...)) {return __p;} |
| 1095 | template <class _R2, class _C, class ..._A> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1096 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1097 | static bool __not_null(_R2 (_C::*__p)(_A...)) {return __p;} |
| 1098 | template <class _R2, class _C, class ..._A> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1099 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1100 | static bool __not_null(_R2 (_C::*__p)(_A...) const) {return __p;} |
| 1101 | template <class _R2, class _C, class ..._A> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1102 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1103 | static bool __not_null(_R2 (_C::*__p)(_A...) volatile) {return __p;} |
| 1104 | template <class _R2, class _C, class ..._A> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1105 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1106 | static bool __not_null(_R2 (_C::*__p)(_A...) const volatile) {return __p;} |
| 1107 | template <class _R2, class ..._A> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1108 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1109 | static bool __not_null(const function<_R(_A...)>& __p) {return __p;} |
| 1110 | public: |
| 1111 | typedef _R result_type; |
| 1112 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1113 | // construct/copy/destroy: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1114 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e00e030 | 2010-08-19 19:20:10 +0000 | [diff] [blame] | 1115 | function() : __f_(0) {} |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1116 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1117 | function(nullptr_t) : __f_(0) {} |
| 1118 | function(const function&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1119 | function(function&&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1120 | template<class _F> |
| 1121 | function(_F, |
| 1122 | typename enable_if<!is_integral<_F>::value>::type* = 0); |
| 1123 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1124 | template<class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1125 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1126 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 1127 | template<class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1128 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1129 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 1130 | template<class _Alloc> |
| 1131 | function(allocator_arg_t, const _Alloc&, const function&); |
| 1132 | template<class _Alloc> |
| 1133 | function(allocator_arg_t, const _Alloc&, function&&); |
| 1134 | template<class _F, class _Alloc> |
| 1135 | function(allocator_arg_t, const _Alloc& __a, _F __f, |
| 1136 | typename enable_if<!is_integral<_F>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1137 | |
| 1138 | function& operator=(const function&); |
| 1139 | function& operator=(function&&); |
| 1140 | function& operator=(nullptr_t); |
| 1141 | template<class _F> |
| 1142 | typename enable_if |
| 1143 | < |
| 1144 | !is_integral<typename decay<_F>::type>::value, |
| 1145 | function& |
| 1146 | >::type |
| 1147 | operator=(_F&&); |
| 1148 | |
| 1149 | ~function(); |
| 1150 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1151 | // function modifiers: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1152 | void swap(function&); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1153 | template<class _F, class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1154 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1155 | void assign(_F&& __f, const _Alloc& __a) |
| 1156 | {function(allocator_arg, __a, _STD::forward<_F>(__f)).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1157 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1158 | // function capacity: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1159 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1160 | /*explicit*/ operator bool() const {return __f_;} |
| 1161 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1162 | // deleted overloads close possible hole in the type system |
| 1163 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | a0f1dc9 | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 1164 | bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1165 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | a0f1dc9 | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 1166 | bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | public: |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1168 | // function invocation: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1169 | _R operator()(_ArgTypes...) const; |
| 1170 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1171 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1172 | // function target access: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1173 | const std::type_info& target_type() const; |
| 1174 | template <typename _T> _T* target(); |
| 1175 | template <typename _T> const _T* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1176 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1177 | }; |
| 1178 | |
| 1179 | template<class _R, class ..._ArgTypes> |
| 1180 | function<_R(_ArgTypes...)>::function(const function& __f) |
| 1181 | { |
| 1182 | if (__f.__f_ == 0) |
| 1183 | __f_ = 0; |
| 1184 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1185 | { |
| 1186 | __f_ = (__base*)&__buf_; |
| 1187 | __f.__f_->__clone(__f_); |
| 1188 | } |
| 1189 | else |
| 1190 | __f_ = __f.__f_->__clone(); |
| 1191 | } |
| 1192 | |
| 1193 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1194 | template <class _Alloc> |
| 1195 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
| 1196 | const function& __f) |
| 1197 | { |
| 1198 | if (__f.__f_ == 0) |
| 1199 | __f_ = 0; |
| 1200 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1201 | { |
| 1202 | __f_ = (__base*)&__buf_; |
| 1203 | __f.__f_->__clone(__f_); |
| 1204 | } |
| 1205 | else |
| 1206 | __f_ = __f.__f_->__clone(); |
| 1207 | } |
| 1208 | |
| 1209 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1210 | function<_R(_ArgTypes...)>::function(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 | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1227 | template <class _Alloc> |
| 1228 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
| 1229 | function&& __f) |
| 1230 | { |
| 1231 | if (__f.__f_ == 0) |
| 1232 | __f_ = 0; |
| 1233 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1234 | { |
| 1235 | __f_ = (__base*)&__buf_; |
| 1236 | __f.__f_->__clone(__f_); |
| 1237 | } |
| 1238 | else |
| 1239 | { |
| 1240 | __f_ = __f.__f_; |
| 1241 | __f.__f_ = 0; |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | template <class _F> |
| 1247 | function<_R(_ArgTypes...)>::function(_F __f, |
| 1248 | typename enable_if<!is_integral<_F>::value>::type*) |
| 1249 | : __f_(0) |
| 1250 | { |
| 1251 | if (__not_null(__f)) |
| 1252 | { |
| 1253 | typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF; |
| 1254 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1255 | { |
| 1256 | __f_ = (__base*)&__buf_; |
| 1257 | ::new (__f_) _FF(_STD::move(__f)); |
| 1258 | } |
| 1259 | else |
| 1260 | { |
| 1261 | typedef allocator<_FF> _A; |
| 1262 | _A __a; |
| 1263 | typedef __allocator_destructor<_A> _D; |
| 1264 | unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1265 | ::new (__hold.get()) _FF(_STD::move(__f), allocator<_F>(__a)); |
| 1266 | __f_ = __hold.release(); |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1272 | template <class _F, class _Alloc> |
| 1273 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f, |
| 1274 | typename enable_if<!is_integral<_F>::value>::type*) |
| 1275 | : __f_(0) |
| 1276 | { |
| 1277 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1278 | if (__not_null(__f)) |
| 1279 | { |
| 1280 | typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF; |
| 1281 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1282 | { |
| 1283 | __f_ = (__base*)&__buf_; |
| 1284 | ::new (__f_) _FF(_STD::move(__f)); |
| 1285 | } |
| 1286 | else |
| 1287 | { |
| 1288 | typedef typename __alloc_traits::template |
| 1289 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1290 | rebind_alloc<_FF> |
| 1291 | #else |
| 1292 | rebind_alloc<_FF>::other |
| 1293 | #endif |
| 1294 | _A; |
| 1295 | _A __a(__a0); |
| 1296 | typedef __allocator_destructor<_A> _D; |
| 1297 | unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1298 | ::new (__hold.get()) _FF(_STD::move(__f), _Alloc(__a)); |
| 1299 | __f_ = __hold.release(); |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1305 | function<_R(_ArgTypes...)>& |
| 1306 | function<_R(_ArgTypes...)>::operator=(const function& __f) |
| 1307 | { |
| 1308 | function(__f).swap(*this); |
| 1309 | return *this; |
| 1310 | } |
| 1311 | |
| 1312 | template<class _R, class ..._ArgTypes> |
| 1313 | function<_R(_ArgTypes...)>& |
| 1314 | function<_R(_ArgTypes...)>::operator=(function&& __f) |
| 1315 | { |
| 1316 | if (__f_ == (__base*)&__buf_) |
| 1317 | __f_->destroy(); |
| 1318 | else if (__f_) |
| 1319 | __f_->destroy_deallocate(); |
| 1320 | __f_ = 0; |
| 1321 | if (__f.__f_ == 0) |
| 1322 | __f_ = 0; |
| 1323 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1324 | { |
| 1325 | __f_ = (__base*)&__buf_; |
| 1326 | __f.__f_->__clone(__f_); |
| 1327 | } |
| 1328 | else |
| 1329 | { |
| 1330 | __f_ = __f.__f_; |
| 1331 | __f.__f_ = 0; |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | template<class _R, class ..._ArgTypes> |
| 1336 | function<_R(_ArgTypes...)>& |
| 1337 | function<_R(_ArgTypes...)>::operator=(nullptr_t) |
| 1338 | { |
| 1339 | if (__f_ == (__base*)&__buf_) |
| 1340 | __f_->destroy(); |
| 1341 | else if (__f_) |
| 1342 | __f_->destroy_deallocate(); |
| 1343 | __f_ = 0; |
| 1344 | } |
| 1345 | |
| 1346 | template<class _R, class ..._ArgTypes> |
| 1347 | template <class _F> |
| 1348 | typename enable_if |
| 1349 | < |
| 1350 | !is_integral<typename decay<_F>::type>::value, |
| 1351 | function<_R(_ArgTypes...)>& |
| 1352 | >::type |
| 1353 | function<_R(_ArgTypes...)>::operator=(_F&& __f) |
| 1354 | { |
| 1355 | function(_STD::forward<_F>(__f)).swap(*this); |
| 1356 | return *this; |
| 1357 | } |
| 1358 | |
| 1359 | template<class _R, class ..._ArgTypes> |
| 1360 | function<_R(_ArgTypes...)>::~function() |
| 1361 | { |
| 1362 | if (__f_ == (__base*)&__buf_) |
| 1363 | __f_->destroy(); |
| 1364 | else if (__f_) |
| 1365 | __f_->destroy_deallocate(); |
| 1366 | } |
| 1367 | |
| 1368 | template<class _R, class ..._ArgTypes> |
| 1369 | void |
| 1370 | function<_R(_ArgTypes...)>::swap(function& __f) |
| 1371 | { |
| 1372 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1373 | { |
| 1374 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1375 | __base* __t = (__base*)&__tempbuf; |
| 1376 | __f_->__clone(__t); |
| 1377 | __f_->destroy(); |
| 1378 | __f_ = 0; |
| 1379 | __f.__f_->__clone((__base*)&__buf_); |
| 1380 | __f.__f_->destroy(); |
| 1381 | __f.__f_ = 0; |
| 1382 | __f_ = (__base*)&__buf_; |
| 1383 | __t->__clone((__base*)&__f.__buf_); |
| 1384 | __t->destroy(); |
| 1385 | __f.__f_ = (__base*)&__f.__buf_; |
| 1386 | } |
| 1387 | else if (__f_ == (__base*)&__buf_) |
| 1388 | { |
| 1389 | __f_->__clone((__base*)&__f.__buf_); |
| 1390 | __f_->destroy(); |
| 1391 | __f_ = __f.__f_; |
| 1392 | __f.__f_ = (__base*)&__f.__buf_; |
| 1393 | } |
| 1394 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1395 | { |
| 1396 | __f.__f_->__clone((__base*)&__buf_); |
| 1397 | __f.__f_->destroy(); |
| 1398 | __f.__f_ = __f_; |
| 1399 | __f_ = (__base*)&__buf_; |
| 1400 | } |
| 1401 | else |
| 1402 | _STD::swap(__f_, __f.__f_); |
| 1403 | } |
| 1404 | |
| 1405 | template<class _R, class ..._ArgTypes> |
| 1406 | _R |
| 1407 | function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const |
| 1408 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1409 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1410 | if (__f_ == 0) |
| 1411 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1412 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1413 | return (*__f_)(_STD::forward<_ArgTypes>(__arg)...); |
| 1414 | } |
| 1415 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1416 | #ifndef _LIBCPP_NO_RTTI |
| 1417 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1418 | template<class _R, class ..._ArgTypes> |
| 1419 | const std::type_info& |
| 1420 | function<_R(_ArgTypes...)>::target_type() const |
| 1421 | { |
| 1422 | if (__f_ == 0) |
| 1423 | return typeid(void); |
| 1424 | return __f_->target_type(); |
| 1425 | } |
| 1426 | |
| 1427 | template<class _R, class ..._ArgTypes> |
| 1428 | template <typename _T> |
| 1429 | _T* |
| 1430 | function<_R(_ArgTypes...)>::target() |
| 1431 | { |
| 1432 | if (__f_ == 0) |
| 1433 | return (_T*)0; |
| 1434 | return (_T*)__f_->target(typeid(_T)); |
| 1435 | } |
| 1436 | |
| 1437 | template<class _R, class ..._ArgTypes> |
| 1438 | template <typename _T> |
| 1439 | const _T* |
| 1440 | function<_R(_ArgTypes...)>::target() const |
| 1441 | { |
| 1442 | if (__f_ == 0) |
| 1443 | return (const _T*)0; |
| 1444 | return (const _T*)__f_->target(typeid(_T)); |
| 1445 | } |
| 1446 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1447 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1448 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1449 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1450 | inline _LIBCPP_INLINE_VISIBILITY |
| 1451 | bool |
| 1452 | operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return !__f;} |
| 1453 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1454 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | inline _LIBCPP_INLINE_VISIBILITY |
| 1456 | bool |
| 1457 | operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return !__f;} |
| 1458 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1459 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1460 | inline _LIBCPP_INLINE_VISIBILITY |
| 1461 | bool |
| 1462 | operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return (bool)__f;} |
| 1463 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1464 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1465 | inline _LIBCPP_INLINE_VISIBILITY |
| 1466 | bool |
| 1467 | operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return (bool)__f;} |
| 1468 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1469 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1470 | inline _LIBCPP_INLINE_VISIBILITY |
| 1471 | void |
| 1472 | swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) |
| 1473 | {return __x.swap(__y);} |
| 1474 | |
| 1475 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1476 | template<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1477 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 1478 | |
| 1479 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1480 | template<class _Tp> struct _LIBCPP_VISIBLE is_placeholder |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1481 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 1482 | |
| 1483 | namespace placeholders |
| 1484 | { |
| 1485 | |
| 1486 | template <int _N> struct __ph {}; |
| 1487 | |
| 1488 | extern __ph<1> _1; |
| 1489 | extern __ph<2> _2; |
| 1490 | extern __ph<3> _3; |
| 1491 | extern __ph<4> _4; |
| 1492 | extern __ph<5> _5; |
| 1493 | extern __ph<6> _6; |
| 1494 | extern __ph<7> _7; |
| 1495 | extern __ph<8> _8; |
| 1496 | extern __ph<9> _9; |
| 1497 | extern __ph<10> _10; |
| 1498 | |
| 1499 | } // placeholders |
| 1500 | |
| 1501 | template<int _N> |
| 1502 | struct __is_placeholder<placeholders::__ph<_N> > |
| 1503 | : public integral_constant<int, _N> {}; |
| 1504 | |
| 1505 | template <class _Tp, class _Uj> |
| 1506 | inline _LIBCPP_INLINE_VISIBILITY |
| 1507 | _Tp& |
| 1508 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 1509 | { |
| 1510 | return __t.get(); |
| 1511 | } |
| 1512 | |
| 1513 | template <bool _IsBindExpr, class _Ti, class ..._Uj> |
| 1514 | struct __mu_return1 {}; |
| 1515 | |
| 1516 | template <class _Ti, class ..._Uj> |
| 1517 | struct __mu_return1<true, _Ti, _Uj...> |
| 1518 | { |
| 1519 | typedef typename result_of<_Ti(_Uj...)>::type type; |
| 1520 | }; |
| 1521 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1522 | template <class _Ti, class ..._Uj, size_t ..._Indx> |
| 1523 | inline _LIBCPP_INLINE_VISIBILITY |
| 1524 | typename __mu_return1<true, _Ti, _Uj...>::type |
| 1525 | __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>) |
| 1526 | { |
| 1527 | return __ti(_STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj))...); |
| 1528 | } |
| 1529 | |
| 1530 | template <class _Ti, class ..._Uj> |
| 1531 | inline _LIBCPP_INLINE_VISIBILITY |
| 1532 | typename enable_if |
| 1533 | < |
| 1534 | is_bind_expression<_Ti>::value, |
| 1535 | typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type |
| 1536 | >::type |
| 1537 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) |
| 1538 | { |
| 1539 | typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; |
| 1540 | return __mu_expand(__ti, __uj, __indices()); |
| 1541 | } |
| 1542 | |
| 1543 | template <bool IsPh, class _Ti, class _Uj> |
| 1544 | struct __mu_return2 {}; |
| 1545 | |
| 1546 | template <class _Ti, class _Uj> |
| 1547 | struct __mu_return2<true, _Ti, _Uj> |
| 1548 | { |
| 1549 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; |
| 1550 | }; |
| 1551 | |
| 1552 | template <class _Ti, class _Uj> |
| 1553 | inline _LIBCPP_INLINE_VISIBILITY |
| 1554 | typename enable_if |
| 1555 | < |
| 1556 | 0 < is_placeholder<_Ti>::value, |
| 1557 | typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type |
| 1558 | >::type |
| 1559 | __mu(_Ti&, _Uj& __uj) |
| 1560 | { |
| 1561 | const size_t _Indx = is_placeholder<_Ti>::value - 1; |
| 1562 | // compiler bug workaround |
| 1563 | typename tuple_element<_Indx, _Uj>::type __t = get<_Indx>(__uj); |
| 1564 | return __t; |
| 1565 | // return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj)); |
| 1566 | } |
| 1567 | |
| 1568 | template <class _Ti, class _Uj> |
| 1569 | inline _LIBCPP_INLINE_VISIBILITY |
| 1570 | typename enable_if |
| 1571 | < |
| 1572 | !is_bind_expression<_Ti>::value && |
| 1573 | is_placeholder<_Ti>::value == 0 && |
| 1574 | !__is_reference_wrapper<_Ti>::value, |
| 1575 | _Ti& |
| 1576 | >::type |
| 1577 | __mu(_Ti& __ti, _Uj& __uj) |
| 1578 | { |
| 1579 | return __ti; |
| 1580 | } |
| 1581 | |
| 1582 | template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj> |
| 1583 | struct ____mu_return; |
| 1584 | |
| 1585 | template <class _Ti, class ..._Uj> |
| 1586 | struct ____mu_return<_Ti, true, false, tuple<_Uj...> > |
| 1587 | { |
| 1588 | typedef typename result_of<_Ti(_Uj...)>::type type; |
| 1589 | }; |
| 1590 | |
| 1591 | template <class _Ti, class _TupleUj> |
| 1592 | struct ____mu_return<_Ti, false, true, _TupleUj> |
| 1593 | { |
| 1594 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 1595 | _TupleUj>::type&& type; |
| 1596 | }; |
| 1597 | |
| 1598 | template <class _Ti, class _TupleUj> |
| 1599 | struct ____mu_return<_Ti, false, false, _TupleUj> |
| 1600 | { |
| 1601 | typedef _Ti& type; |
| 1602 | }; |
| 1603 | |
| 1604 | template <class _Ti, class _TupleUj> |
| 1605 | struct __mu_return |
| 1606 | : public ____mu_return<_Ti, |
| 1607 | is_bind_expression<_Ti>::value, |
| 1608 | 0 < is_placeholder<_Ti>::value, |
| 1609 | _TupleUj> |
| 1610 | { |
| 1611 | }; |
| 1612 | |
| 1613 | template <class _Ti, class _TupleUj> |
| 1614 | struct __mu_return<reference_wrapper<_Ti>, _TupleUj> |
| 1615 | { |
| 1616 | typedef _Ti& type; |
| 1617 | }; |
| 1618 | |
| 1619 | template <class _F, class _BoundArgs, class _TupleUj> |
| 1620 | struct __bind_return; |
| 1621 | |
| 1622 | template <class _F, class ..._BoundArgs, class _TupleUj> |
| 1623 | struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj> |
| 1624 | { |
| 1625 | typedef typename __invoke_return |
| 1626 | < |
| 1627 | _F&, |
| 1628 | typename __mu_return |
| 1629 | < |
| 1630 | _BoundArgs, |
| 1631 | _TupleUj |
| 1632 | >::type... |
| 1633 | >::type type; |
| 1634 | }; |
| 1635 | |
| 1636 | template <class _F, class ..._BoundArgs, class _TupleUj> |
| 1637 | struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj> |
| 1638 | { |
| 1639 | typedef typename __invoke_return |
| 1640 | < |
| 1641 | _F&, |
| 1642 | typename __mu_return |
| 1643 | < |
| 1644 | const _BoundArgs, |
| 1645 | _TupleUj |
| 1646 | >::type... |
| 1647 | >::type type; |
| 1648 | }; |
| 1649 | |
| 1650 | template <class _F, class _BoundArgs, size_t ..._Indx, class _Args> |
| 1651 | inline _LIBCPP_INLINE_VISIBILITY |
| 1652 | typename __bind_return<_F, _BoundArgs, _Args>::type |
| 1653 | __apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
| 1654 | _Args&& __args) |
| 1655 | { |
| 1656 | return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); |
| 1657 | } |
| 1658 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1659 | template<class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1660 | class __bind |
| 1661 | : public __weak_result_type<_F> |
| 1662 | { |
| 1663 | _F __f_; |
| 1664 | tuple<_BoundArgs...> __bound_args_; |
| 1665 | |
| 1666 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 1667 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1668 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1669 | __bind(__bind&& __b) |
| 1670 | : __f_(_STD::move(__b.__f_)), |
| 1671 | __bound_args_(_STD::move(__b.__bound_args_)) {} |
| 1672 | |
| 1673 | template <class _G, class ..._BA> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1674 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1675 | explicit __bind(_G&& __f, _BA&& ...__bound_args) |
| 1676 | : __f_(_STD::forward<_G>(__f)), |
| 1677 | __bound_args_(_STD::forward<_BA>(__bound_args)...) {} |
| 1678 | |
| 1679 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1680 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1681 | typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type |
| 1682 | operator()(_Args&& ...__args) |
| 1683 | { |
| 1684 | // compiler bug workaround |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1685 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | ffb9a4e | 2010-10-07 18:03:23 +0000 | [diff] [blame] | 1686 | tuple<_Args&&...>(_STD::forward<_Args>(__args)...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1690 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1691 | typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type |
| 1692 | operator()(_Args&& ...__args) const |
| 1693 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1694 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | ffb9a4e | 2010-10-07 18:03:23 +0000 | [diff] [blame] | 1695 | tuple<_Args&&...>(_STD::forward<_Args>(__args)...)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1696 | } |
| 1697 | }; |
| 1698 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1699 | template<class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1700 | struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {}; |
| 1701 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1702 | template<class _R, class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1703 | class __bind_r |
| 1704 | : public __bind<_F, _BoundArgs...> |
| 1705 | { |
| 1706 | typedef __bind<_F, _BoundArgs...> base; |
| 1707 | public: |
| 1708 | typedef _R result_type; |
| 1709 | |
| 1710 | template <class _G, class ..._BA> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1711 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1712 | explicit __bind_r(_G&& __f, _BA&& ...__bound_args) |
| 1713 | : base(_STD::forward<_G>(__f), |
| 1714 | _STD::forward<_BA>(__bound_args)...) {} |
| 1715 | |
| 1716 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1717 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1718 | result_type |
| 1719 | operator()(_Args&& ...__args) |
| 1720 | { |
| 1721 | return base::operator()(_STD::forward<_Args>(__args)...); |
| 1722 | } |
| 1723 | |
| 1724 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1726 | result_type |
| 1727 | operator()(_Args&& ...__args) const |
| 1728 | { |
| 1729 | return base::operator()(_STD::forward<_Args>(__args)...); |
| 1730 | } |
| 1731 | }; |
| 1732 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1733 | template<class _R, class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1734 | struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {}; |
| 1735 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1736 | template<class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1737 | inline _LIBCPP_INLINE_VISIBILITY |
| 1738 | __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> |
| 1739 | bind(_F&& __f, _BoundArgs&&... __bound_args) |
| 1740 | { |
| 1741 | typedef __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> type; |
| 1742 | return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...); |
| 1743 | } |
| 1744 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1745 | template<class _R, class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1746 | inline _LIBCPP_INLINE_VISIBILITY |
| 1747 | __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> |
| 1748 | bind(_F&& __f, _BoundArgs&&... __bound_args) |
| 1749 | { |
| 1750 | typedef __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> type; |
| 1751 | return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...); |
| 1752 | } |
| 1753 | |
| 1754 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1755 | |
| 1756 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1757 | struct _LIBCPP_VISIBLE hash<bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1758 | : public unary_function<bool, size_t> |
| 1759 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1760 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1761 | size_t operator()(bool __v) const {return static_cast<size_t>(__v);} |
| 1762 | }; |
| 1763 | |
| 1764 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1765 | struct _LIBCPP_VISIBLE hash<char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1766 | : public unary_function<char, size_t> |
| 1767 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1768 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1769 | size_t operator()(char __v) const {return static_cast<size_t>(__v);} |
| 1770 | }; |
| 1771 | |
| 1772 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1773 | struct _LIBCPP_VISIBLE hash<signed char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1774 | : public unary_function<signed char, size_t> |
| 1775 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1776 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1777 | size_t operator()(signed char __v) const {return static_cast<size_t>(__v);} |
| 1778 | }; |
| 1779 | |
| 1780 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1781 | struct _LIBCPP_VISIBLE hash<unsigned char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | : public unary_function<unsigned char, size_t> |
| 1783 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1784 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1785 | size_t operator()(unsigned char __v) const {return static_cast<size_t>(__v);} |
| 1786 | }; |
| 1787 | |
| 1788 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 1789 | |
| 1790 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1791 | struct _LIBCPP_VISIBLE hash<char16_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1792 | : public unary_function<char16_t, size_t> |
| 1793 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1794 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1795 | size_t operator()(char16_t __v) const {return static_cast<size_t>(__v);} |
| 1796 | }; |
| 1797 | |
| 1798 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1799 | struct _LIBCPP_VISIBLE hash<char32_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1800 | : public unary_function<char32_t, size_t> |
| 1801 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1803 | size_t operator()(char32_t __v) const {return static_cast<size_t>(__v);} |
| 1804 | }; |
| 1805 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1806 | #endif // _LIBCPP_HAS_NO_UNICODE_CHARS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1807 | |
| 1808 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1809 | struct _LIBCPP_VISIBLE hash<wchar_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1810 | : public unary_function<wchar_t, size_t> |
| 1811 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1812 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1813 | size_t operator()(wchar_t __v) const {return static_cast<size_t>(__v);} |
| 1814 | }; |
| 1815 | |
| 1816 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1817 | struct _LIBCPP_VISIBLE hash<short> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1818 | : public unary_function<short, size_t> |
| 1819 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1820 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1821 | size_t operator()(short __v) const {return static_cast<size_t>(__v);} |
| 1822 | }; |
| 1823 | |
| 1824 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1825 | struct _LIBCPP_VISIBLE hash<unsigned short> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1826 | : public unary_function<unsigned short, size_t> |
| 1827 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1828 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1829 | size_t operator()(unsigned short __v) const {return static_cast<size_t>(__v);} |
| 1830 | }; |
| 1831 | |
| 1832 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1833 | struct _LIBCPP_VISIBLE hash<int> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1834 | : public unary_function<int, size_t> |
| 1835 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1836 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | size_t operator()(int __v) const {return static_cast<size_t>(__v);} |
| 1838 | }; |
| 1839 | |
| 1840 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1841 | struct _LIBCPP_VISIBLE hash<unsigned int> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1842 | : public unary_function<unsigned int, size_t> |
| 1843 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1844 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1845 | size_t operator()(unsigned int __v) const {return static_cast<size_t>(__v);} |
| 1846 | }; |
| 1847 | |
| 1848 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1849 | struct _LIBCPP_VISIBLE hash<long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 | : public unary_function<long, size_t> |
| 1851 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1852 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1853 | size_t operator()(long __v) const {return static_cast<size_t>(__v);} |
| 1854 | }; |
| 1855 | |
| 1856 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1857 | struct _LIBCPP_VISIBLE hash<unsigned long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1858 | : public unary_function<unsigned long, size_t> |
| 1859 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1861 | size_t operator()(unsigned long __v) const {return static_cast<size_t>(__v);} |
| 1862 | }; |
| 1863 | |
| 1864 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1865 | struct _LIBCPP_VISIBLE hash<long long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1866 | : public unary_function<long long, size_t> |
| 1867 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1868 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1869 | size_t operator()(long long __v) const |
| 1870 | { |
| 1871 | size_t __r = 0; |
| 1872 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1873 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1874 | __r ^= __p[__i]; |
| 1875 | return __r; |
| 1876 | } |
| 1877 | }; |
| 1878 | |
| 1879 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1880 | struct _LIBCPP_VISIBLE hash<unsigned long long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1881 | : public unary_function<unsigned long long, size_t> |
| 1882 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1884 | size_t operator()(unsigned long long __v) const |
| 1885 | { |
| 1886 | size_t __r = 0; |
| 1887 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1888 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1889 | __r ^= __p[__i]; |
| 1890 | return __r; |
| 1891 | } |
| 1892 | }; |
| 1893 | |
| 1894 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1895 | struct _LIBCPP_VISIBLE hash<float> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1896 | : public unary_function<float, size_t> |
| 1897 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1898 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1899 | size_t operator()(float __v) const |
| 1900 | { |
| 1901 | if (__v == 0) |
| 1902 | return 0; |
| 1903 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1904 | return *__p; |
| 1905 | } |
| 1906 | }; |
| 1907 | |
| 1908 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1909 | struct _LIBCPP_VISIBLE hash<double> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1910 | : public unary_function<double, size_t> |
| 1911 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1912 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1913 | size_t operator()(double __v) const |
| 1914 | { |
| 1915 | if (__v == 0) |
| 1916 | return 0; |
| 1917 | size_t __r = 0; |
| 1918 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1919 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1920 | __r ^= __p[__i]; |
| 1921 | return __r; |
| 1922 | } |
| 1923 | }; |
| 1924 | |
| 1925 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1926 | struct _LIBCPP_VISIBLE hash<long double> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1927 | : public unary_function<long double, size_t> |
| 1928 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1929 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1930 | size_t operator()(long double __v) const |
| 1931 | { |
| 1932 | if (__v == 0) |
| 1933 | return 0; |
| 1934 | size_t __r = 0; |
| 1935 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1936 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1937 | __r ^= __p[__i]; |
| 1938 | return __r; |
| 1939 | } |
| 1940 | }; |
| 1941 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 1942 | // struct hash<T*> in <memory> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1943 | |
| 1944 | _LIBCPP_END_NAMESPACE_STD |
| 1945 | |
| 1946 | #endif // _LIBCPP_FUNCTIONAL |