Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------ functional ----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_FUNCTIONAL |
| 12 | #define _LIBCPP_FUNCTIONAL |
| 13 | |
| 14 | /* |
| 15 | functional synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class Arg, class Result> |
| 21 | struct unary_function |
| 22 | { |
| 23 | typedef Arg argument_type; |
| 24 | typedef Result result_type; |
| 25 | }; |
| 26 | |
| 27 | template <class Arg1, class Arg2, class Result> |
| 28 | struct binary_function |
| 29 | { |
| 30 | typedef Arg1 first_argument_type; |
| 31 | typedef Arg2 second_argument_type; |
| 32 | typedef Result result_type; |
| 33 | }; |
| 34 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 35 | template <class T> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | class reference_wrapper |
| 37 | : public unary_function<T1, R> // if wrapping a unary functor |
| 38 | : public binary_function<T1, T2, R> // if wraping a binary functor |
| 39 | { |
| 40 | public: |
| 41 | // types |
| 42 | typedef T type; |
| 43 | typedef see below result_type; // Not always defined |
| 44 | |
| 45 | // construct/copy/destroy |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 46 | reference_wrapper(T&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | reference_wrapper(T&&) = delete; // do not bind to temps |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 48 | reference_wrapper(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | |
| 50 | // assignment |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 51 | reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 52 | |
| 53 | // access |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 54 | operator T& () const noexcept; |
| 55 | T& get() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | |
| 57 | // invoke |
| 58 | template <class... ArgTypes> |
Howard Hinnant | 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 | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 63 | template <class T> reference_wrapper<T> ref(T& t) noexcept; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 64 | template <class T> void ref(const T&& t) = delete; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 65 | template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 66 | |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 67 | template <class T> reference_wrapper<const T> cref(const T& t) noexcept; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 68 | template <class T> void cref(const T&& t) = delete; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 69 | template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 70 | |
| 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: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 368 | function() noexcept; |
| 369 | function(nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 370 | function(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 371 | function(function&&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 375 | function(allocator_arg_t, const Alloc&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 376 | template<Allocator Alloc> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 377 | function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 386 | function& operator=(function&&) noexcept; |
Howard Hinnant | ad1a5cc | 2011-05-29 13:53:56 +0000 | [diff] [blame] | 387 | function& operator=(nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 391 | function& operator=(reference_wrapper<F>) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 392 | |
| 393 | ~function(); |
| 394 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 395 | // function modifiers: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 396 | void swap(function&) noexcept; |
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 | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 401 | explicit operator bool() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 402 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 403 | // function invocation: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | R operator()(ArgTypes...) const; |
| 405 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 406 | // function target access: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 407 | const std::type_info& target_type() const noexcept; |
| 408 | template <typename T> T* target() noexcept; |
| 409 | template <typename T> const T* target() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | }; |
| 411 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 412 | // Null pointer comparisons: |
| 413 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 414 | bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 416 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 417 | bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 419 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 420 | bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 422 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 423 | bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 425 | // specialized algorithms: |
| 426 | template <class R, class ... ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 427 | void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 428 | |
| 429 | template <class T> struct hash; |
| 430 | |
| 431 | template <> struct hash<bool>; |
| 432 | template <> struct hash<char>; |
| 433 | template <> struct hash<signed char>; |
| 434 | template <> struct hash<unsigned char>; |
| 435 | template <> struct hash<char16_t>; |
| 436 | template <> struct hash<char32_t>; |
| 437 | template <> struct hash<wchar_t>; |
| 438 | template <> struct hash<short>; |
| 439 | template <> struct hash<unsigned short>; |
| 440 | template <> struct hash<int>; |
| 441 | template <> struct hash<unsigned int>; |
| 442 | template <> struct hash<long>; |
| 443 | template <> struct hash<long long>; |
| 444 | template <> struct hash<unsigned long>; |
| 445 | template <> struct hash<unsigned long long>; |
| 446 | |
| 447 | template <> struct hash<float>; |
| 448 | template <> struct hash<double>; |
| 449 | template <> struct hash<long double>; |
| 450 | |
| 451 | template<class T> struct hash<T*>; |
| 452 | |
| 453 | } // std |
| 454 | |
| 455 | POLICY: For non-variadic implementations, the number of arguments is limited |
| 456 | to 3. It is hoped that the need for non-variadic implementations |
| 457 | will be minimal. |
| 458 | |
| 459 | */ |
| 460 | |
| 461 | #include <__config> |
| 462 | #include <type_traits> |
| 463 | #include <typeinfo> |
| 464 | #include <exception> |
| 465 | #include <memory> |
| 466 | #include <tuple> |
| 467 | |
| 468 | #include <__functional_base> |
| 469 | |
| 470 | #pragma GCC system_header |
| 471 | |
| 472 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 473 | |
| 474 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 475 | struct _LIBCPP_VISIBLE plus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | { |
| 477 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 478 | {return __x + __y;} |
| 479 | }; |
| 480 | |
| 481 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 482 | struct _LIBCPP_VISIBLE minus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | { |
| 484 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 485 | {return __x - __y;} |
| 486 | }; |
| 487 | |
| 488 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 489 | struct _LIBCPP_VISIBLE multiplies : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 490 | { |
| 491 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 492 | {return __x * __y;} |
| 493 | }; |
| 494 | |
| 495 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 496 | struct _LIBCPP_VISIBLE divides : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 497 | { |
| 498 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 499 | {return __x / __y;} |
| 500 | }; |
| 501 | |
| 502 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 503 | struct _LIBCPP_VISIBLE modulus : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 504 | { |
| 505 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 506 | {return __x % __y;} |
| 507 | }; |
| 508 | |
| 509 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 510 | struct _LIBCPP_VISIBLE negate : unary_function<_Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 511 | { |
| 512 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const |
| 513 | {return -__x;} |
| 514 | }; |
| 515 | |
| 516 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 517 | struct _LIBCPP_VISIBLE equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | { |
| 519 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 520 | {return __x == __y;} |
| 521 | }; |
| 522 | |
| 523 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 524 | struct _LIBCPP_VISIBLE not_equal_to : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 525 | { |
| 526 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 527 | {return __x != __y;} |
| 528 | }; |
| 529 | |
| 530 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 531 | struct _LIBCPP_VISIBLE greater : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | { |
| 533 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 534 | {return __x > __y;} |
| 535 | }; |
| 536 | |
| 537 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 538 | struct _LIBCPP_VISIBLE less : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | { |
| 540 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 541 | {return __x < __y;} |
| 542 | }; |
| 543 | |
| 544 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 545 | struct _LIBCPP_VISIBLE greater_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 546 | { |
| 547 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 548 | {return __x >= __y;} |
| 549 | }; |
| 550 | |
| 551 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 552 | struct _LIBCPP_VISIBLE less_equal : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 553 | { |
| 554 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 555 | {return __x <= __y;} |
| 556 | }; |
| 557 | |
| 558 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 559 | struct _LIBCPP_VISIBLE logical_and : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 560 | { |
| 561 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 562 | {return __x && __y;} |
| 563 | }; |
| 564 | |
| 565 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 566 | struct _LIBCPP_VISIBLE logical_or : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 567 | { |
| 568 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const |
| 569 | {return __x || __y;} |
| 570 | }; |
| 571 | |
| 572 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 573 | struct _LIBCPP_VISIBLE logical_not : unary_function<_Tp, bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 574 | { |
| 575 | _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const |
| 576 | {return !__x;} |
| 577 | }; |
| 578 | |
| 579 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 580 | struct _LIBCPP_VISIBLE bit_and : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | { |
| 582 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 583 | {return __x & __y;} |
| 584 | }; |
| 585 | |
| 586 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 587 | struct _LIBCPP_VISIBLE bit_or : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 588 | { |
| 589 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 590 | {return __x | __y;} |
| 591 | }; |
| 592 | |
| 593 | template <class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 594 | struct _LIBCPP_VISIBLE bit_xor : binary_function<_Tp, _Tp, _Tp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 595 | { |
| 596 | _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const |
| 597 | {return __x ^ __y;} |
| 598 | }; |
| 599 | |
| 600 | template <class _Predicate> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 601 | class _LIBCPP_VISIBLE unary_negate |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 602 | : public unary_function<typename _Predicate::argument_type, bool> |
| 603 | { |
| 604 | _Predicate __pred_; |
| 605 | public: |
| 606 | _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred) |
| 607 | : __pred_(__pred) {} |
| 608 | _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const |
| 609 | {return !__pred_(__x);} |
| 610 | }; |
| 611 | |
| 612 | template <class _Predicate> |
| 613 | inline _LIBCPP_INLINE_VISIBILITY |
| 614 | unary_negate<_Predicate> |
| 615 | not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} |
| 616 | |
| 617 | template <class _Predicate> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 618 | class _LIBCPP_VISIBLE binary_negate |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | : public binary_function<typename _Predicate::first_argument_type, |
| 620 | typename _Predicate::second_argument_type, |
| 621 | bool> |
| 622 | { |
| 623 | _Predicate __pred_; |
| 624 | public: |
| 625 | _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred) |
| 626 | : __pred_(__pred) {} |
| 627 | _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x, |
| 628 | const typename _Predicate::second_argument_type& __y) const |
| 629 | {return !__pred_(__x, __y);} |
| 630 | }; |
| 631 | |
| 632 | template <class _Predicate> |
| 633 | inline _LIBCPP_INLINE_VISIBILITY |
| 634 | binary_negate<_Predicate> |
| 635 | not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} |
| 636 | |
| 637 | template <class __Operation> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 638 | class _LIBCPP_VISIBLE binder1st |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 639 | : public unary_function<typename __Operation::second_argument_type, |
| 640 | typename __Operation::result_type> |
| 641 | { |
| 642 | protected: |
| 643 | __Operation op; |
| 644 | typename __Operation::first_argument_type value; |
| 645 | public: |
| 646 | _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, |
| 647 | const typename __Operation::first_argument_type __y) |
| 648 | : op(__x), value(__y) {} |
| 649 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 650 | (typename __Operation::second_argument_type& __x) const |
| 651 | {return op(value, __x);} |
| 652 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 653 | (const typename __Operation::second_argument_type& __x) const |
| 654 | {return op(value, __x);} |
| 655 | }; |
| 656 | |
| 657 | template <class __Operation, class _Tp> |
| 658 | inline _LIBCPP_INLINE_VISIBILITY |
| 659 | binder1st<__Operation> |
| 660 | bind1st(const __Operation& __op, const _Tp& __x) |
| 661 | {return binder1st<__Operation>(__op, __x);} |
| 662 | |
| 663 | template <class __Operation> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 664 | class _LIBCPP_VISIBLE binder2nd |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 665 | : public unary_function<typename __Operation::first_argument_type, |
| 666 | typename __Operation::result_type> |
| 667 | { |
| 668 | protected: |
| 669 | __Operation op; |
| 670 | typename __Operation::second_argument_type value; |
| 671 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 672 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 673 | binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) |
| 674 | : op(__x), value(__y) {} |
| 675 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 676 | ( typename __Operation::first_argument_type& __x) const |
| 677 | {return op(__x, value);} |
| 678 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 679 | (const typename __Operation::first_argument_type& __x) const |
| 680 | {return op(__x, value);} |
| 681 | }; |
| 682 | |
| 683 | template <class __Operation, class _Tp> |
| 684 | inline _LIBCPP_INLINE_VISIBILITY |
| 685 | binder2nd<__Operation> |
| 686 | bind2nd(const __Operation& __op, const _Tp& __x) |
| 687 | {return binder2nd<__Operation>(__op, __x);} |
| 688 | |
| 689 | template <class _Arg, class _Result> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 690 | class _LIBCPP_VISIBLE pointer_to_unary_function |
| 691 | : public unary_function<_Arg, _Result> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 692 | { |
| 693 | _Result (*__f_)(_Arg); |
| 694 | public: |
| 695 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) |
| 696 | : __f_(__f) {} |
| 697 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const |
| 698 | {return __f_(__x);} |
| 699 | }; |
| 700 | |
| 701 | template <class _Arg, class _Result> |
| 702 | inline _LIBCPP_INLINE_VISIBILITY |
| 703 | pointer_to_unary_function<_Arg,_Result> |
| 704 | ptr_fun(_Result (*__f)(_Arg)) |
| 705 | {return pointer_to_unary_function<_Arg,_Result>(__f);} |
| 706 | |
| 707 | template <class _Arg1, class _Arg2, class _Result> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 708 | class _LIBCPP_VISIBLE pointer_to_binary_function |
| 709 | : public binary_function<_Arg1, _Arg2, _Result> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 710 | { |
| 711 | _Result (*__f_)(_Arg1, _Arg2); |
| 712 | public: |
| 713 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) |
| 714 | : __f_(__f) {} |
| 715 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const |
| 716 | {return __f_(__x, __y);} |
| 717 | }; |
| 718 | |
| 719 | template <class _Arg1, class _Arg2, class _Result> |
| 720 | inline _LIBCPP_INLINE_VISIBILITY |
| 721 | pointer_to_binary_function<_Arg1,_Arg2,_Result> |
| 722 | ptr_fun(_Result (*__f)(_Arg1,_Arg2)) |
| 723 | {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} |
| 724 | |
| 725 | template<class _Sp, class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 726 | class _LIBCPP_VISIBLE mem_fun_t : public unary_function<_Tp*, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 727 | { |
| 728 | _Sp (_Tp::*__p_)(); |
| 729 | public: |
| 730 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) |
| 731 | : __p_(__p) {} |
| 732 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const |
| 733 | {return (__p->*__p_)();} |
| 734 | }; |
| 735 | |
| 736 | template<class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 737 | class _LIBCPP_VISIBLE mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 738 | { |
| 739 | _Sp (_Tp::*__p_)(_Ap); |
| 740 | public: |
| 741 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) |
| 742 | : __p_(__p) {} |
| 743 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const |
| 744 | {return (__p->*__p_)(__x);} |
| 745 | }; |
| 746 | |
| 747 | template<class _Sp, class _Tp> |
| 748 | inline _LIBCPP_INLINE_VISIBILITY |
| 749 | mem_fun_t<_Sp,_Tp> |
| 750 | mem_fun(_Sp (_Tp::*__f)()) |
| 751 | {return mem_fun_t<_Sp,_Tp>(__f);} |
| 752 | |
| 753 | template<class _Sp, class _Tp, class _Ap> |
| 754 | inline _LIBCPP_INLINE_VISIBILITY |
| 755 | mem_fun1_t<_Sp,_Tp,_Ap> |
| 756 | mem_fun(_Sp (_Tp::*__f)(_Ap)) |
| 757 | {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 758 | |
| 759 | template<class _Sp, class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 760 | class _LIBCPP_VISIBLE mem_fun_ref_t : public unary_function<_Tp, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 761 | { |
| 762 | _Sp (_Tp::*__p_)(); |
| 763 | public: |
| 764 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) |
| 765 | : __p_(__p) {} |
| 766 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const |
| 767 | {return (__p.*__p_)();} |
| 768 | }; |
| 769 | |
| 770 | template<class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 771 | 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] | 772 | { |
| 773 | _Sp (_Tp::*__p_)(_Ap); |
| 774 | public: |
| 775 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) |
| 776 | : __p_(__p) {} |
| 777 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const |
| 778 | {return (__p.*__p_)(__x);} |
| 779 | }; |
| 780 | |
| 781 | template<class _Sp, class _Tp> |
| 782 | inline _LIBCPP_INLINE_VISIBILITY |
| 783 | mem_fun_ref_t<_Sp,_Tp> |
| 784 | mem_fun_ref(_Sp (_Tp::*__f)()) |
| 785 | {return mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 786 | |
| 787 | template<class _Sp, class _Tp, class _Ap> |
| 788 | inline _LIBCPP_INLINE_VISIBILITY |
| 789 | mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 790 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) |
| 791 | {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 792 | |
| 793 | template <class _Sp, class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 794 | 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] | 795 | { |
| 796 | _Sp (_Tp::*__p_)() const; |
| 797 | public: |
| 798 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) |
| 799 | : __p_(__p) {} |
| 800 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const |
| 801 | {return (__p->*__p_)();} |
| 802 | }; |
| 803 | |
| 804 | template <class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 805 | 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] | 806 | { |
| 807 | _Sp (_Tp::*__p_)(_Ap) const; |
| 808 | public: |
| 809 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) |
| 810 | : __p_(__p) {} |
| 811 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const |
| 812 | {return (__p->*__p_)(__x);} |
| 813 | }; |
| 814 | |
| 815 | template <class _Sp, class _Tp> |
| 816 | inline _LIBCPP_INLINE_VISIBILITY |
| 817 | const_mem_fun_t<_Sp,_Tp> |
| 818 | mem_fun(_Sp (_Tp::*__f)() const) |
| 819 | {return const_mem_fun_t<_Sp,_Tp>(__f);} |
| 820 | |
| 821 | template <class _Sp, class _Tp, class _Ap> |
| 822 | inline _LIBCPP_INLINE_VISIBILITY |
| 823 | const_mem_fun1_t<_Sp,_Tp,_Ap> |
| 824 | mem_fun(_Sp (_Tp::*__f)(_Ap) const) |
| 825 | {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 826 | |
| 827 | template <class _Sp, class _Tp> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 828 | 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] | 829 | { |
| 830 | _Sp (_Tp::*__p_)() const; |
| 831 | public: |
| 832 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) |
| 833 | : __p_(__p) {} |
| 834 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const |
| 835 | {return (__p.*__p_)();} |
| 836 | }; |
| 837 | |
| 838 | template <class _Sp, class _Tp, class _Ap> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 839 | class _LIBCPP_VISIBLE const_mem_fun1_ref_t |
| 840 | : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 841 | { |
| 842 | _Sp (_Tp::*__p_)(_Ap) const; |
| 843 | public: |
| 844 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) |
| 845 | : __p_(__p) {} |
| 846 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const |
| 847 | {return (__p.*__p_)(__x);} |
| 848 | }; |
| 849 | |
| 850 | template <class _Sp, class _Tp> |
| 851 | inline _LIBCPP_INLINE_VISIBILITY |
| 852 | const_mem_fun_ref_t<_Sp,_Tp> |
| 853 | mem_fun_ref(_Sp (_Tp::*__f)() const) |
| 854 | {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 855 | |
| 856 | template <class _Sp, class _Tp, class _Ap> |
| 857 | inline _LIBCPP_INLINE_VISIBILITY |
| 858 | const_mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 859 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) |
| 860 | {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 861 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 862 | #ifdef _LIBCPP_HAS_NO_VARIADICS |
| 863 | |
| 864 | #include <__functional_03> |
| 865 | |
| 866 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 867 | |
| 868 | template <class _Tp> |
| 869 | class __mem_fn |
| 870 | : public __weak_result_type<_Tp> |
| 871 | { |
| 872 | public: |
| 873 | // types |
| 874 | typedef _Tp type; |
| 875 | private: |
| 876 | type __f_; |
| 877 | |
| 878 | public: |
| 879 | _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} |
| 880 | |
| 881 | // invoke |
| 882 | template <class... _ArgTypes> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | typename __invoke_return<type, _ArgTypes...>::type |
| 885 | operator() (_ArgTypes&&... __args) |
| 886 | { |
| 887 | return __invoke(__f_, _STD::forward<_ArgTypes>(__args)...); |
| 888 | } |
| 889 | }; |
| 890 | |
| 891 | template<class _R, class _T> |
| 892 | inline _LIBCPP_INLINE_VISIBILITY |
| 893 | __mem_fn<_R _T::*> |
| 894 | mem_fn(_R _T::* __pm) |
| 895 | { |
| 896 | return __mem_fn<_R _T::*>(__pm); |
| 897 | } |
| 898 | |
| 899 | template<class _R, class _T, class ..._Args> |
| 900 | inline _LIBCPP_INLINE_VISIBILITY |
| 901 | __mem_fn<_R (_T::*)(_Args...)> |
| 902 | mem_fn(_R (_T::* __pm)(_Args...)) |
| 903 | { |
| 904 | return __mem_fn<_R (_T::*)(_Args...)>(__pm); |
| 905 | } |
| 906 | |
| 907 | template<class _R, class _T, class ..._Args> |
| 908 | inline _LIBCPP_INLINE_VISIBILITY |
| 909 | __mem_fn<_R (_T::*)(_Args...) const> |
| 910 | mem_fn(_R (_T::* __pm)(_Args...) const) |
| 911 | { |
| 912 | return __mem_fn<_R (_T::*)(_Args...) const>(__pm); |
| 913 | } |
| 914 | |
| 915 | template<class _R, class _T, class ..._Args> |
| 916 | inline _LIBCPP_INLINE_VISIBILITY |
| 917 | __mem_fn<_R (_T::*)(_Args...) volatile> |
| 918 | mem_fn(_R (_T::* __pm)(_Args...) volatile) |
| 919 | { |
| 920 | return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm); |
| 921 | } |
| 922 | |
| 923 | template<class _R, class _T, class ..._Args> |
| 924 | inline _LIBCPP_INLINE_VISIBILITY |
| 925 | __mem_fn<_R (_T::*)(_Args...) const volatile> |
| 926 | mem_fn(_R (_T::* __pm)(_Args...) const volatile) |
| 927 | { |
| 928 | return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm); |
| 929 | } |
| 930 | |
| 931 | // bad_function_call |
| 932 | |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 933 | class _LIBCPP_EXCEPTION_ABI bad_function_call |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 934 | : public exception |
| 935 | { |
| 936 | }; |
| 937 | |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 938 | template<class _Fp> class _LIBCPP_VISIBLE function; // undefined |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 939 | |
| 940 | namespace __function |
| 941 | { |
| 942 | |
| 943 | template<class _R, class ..._ArgTypes> |
| 944 | struct __maybe_derive_from_unary_function |
| 945 | { |
| 946 | }; |
| 947 | |
| 948 | template<class _R, class _A1> |
| 949 | struct __maybe_derive_from_unary_function<_R(_A1)> |
| 950 | : public unary_function<_A1, _R> |
| 951 | { |
| 952 | }; |
| 953 | |
| 954 | template<class _R, class ..._ArgTypes> |
| 955 | struct __maybe_derive_from_binary_function |
| 956 | { |
| 957 | }; |
| 958 | |
| 959 | template<class _R, class _A1, class _A2> |
| 960 | struct __maybe_derive_from_binary_function<_R(_A1, _A2)> |
| 961 | : public binary_function<_A1, _A2, _R> |
| 962 | { |
| 963 | }; |
| 964 | |
| 965 | template<class _Fp> class __base; |
| 966 | |
| 967 | template<class _R, class ..._ArgTypes> |
| 968 | class __base<_R(_ArgTypes...)> |
| 969 | { |
| 970 | __base(const __base&); |
| 971 | __base& operator=(const __base&); |
| 972 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 973 | _LIBCPP_INLINE_VISIBILITY __base() {} |
| 974 | _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 975 | virtual __base* __clone() const = 0; |
| 976 | virtual void __clone(__base*) const = 0; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 977 | virtual void destroy() _NOEXCEPT = 0; |
| 978 | virtual void destroy_deallocate() _NOEXCEPT = 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 979 | virtual _R operator()(_ArgTypes&& ...) = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 980 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 981 | virtual const void* target(const type_info&) const _NOEXCEPT = 0; |
| 982 | virtual const std::type_info& target_type() const _NOEXCEPT = 0; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 983 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 984 | }; |
| 985 | |
| 986 | template<class _FD, class _Alloc, class _FB> class __func; |
| 987 | |
| 988 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 989 | class __func<_F, _Alloc, _R(_ArgTypes...)> |
| 990 | : public __base<_R(_ArgTypes...)> |
| 991 | { |
| 992 | __compressed_pair<_F, _Alloc> __f_; |
| 993 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 994 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 995 | explicit __func(_F __f) : __f_(_STD::move(__f)) {} |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 997 | explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {} |
| 998 | virtual __base<_R(_ArgTypes...)>* __clone() const; |
| 999 | virtual void __clone(__base<_R(_ArgTypes...)>*) const; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1000 | virtual void destroy() _NOEXCEPT; |
| 1001 | virtual void destroy_deallocate() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1002 | virtual _R operator()(_ArgTypes&& ... __arg); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1003 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1004 | virtual const void* target(const type_info&) const _NOEXCEPT; |
| 1005 | virtual const std::type_info& target_type() const _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1006 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1007 | }; |
| 1008 | |
| 1009 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1010 | __base<_R(_ArgTypes...)>* |
| 1011 | __func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const |
| 1012 | { |
| 1013 | typedef typename _Alloc::template rebind<__func>::other _A; |
| 1014 | _A __a(__f_.second()); |
| 1015 | typedef __allocator_destructor<_A> _D; |
| 1016 | unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1017 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 1018 | return __hold.release(); |
| 1019 | } |
| 1020 | |
| 1021 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1022 | void |
| 1023 | __func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const |
| 1024 | { |
| 1025 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 1026 | } |
| 1027 | |
| 1028 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1029 | void |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1030 | __func<_F, _Alloc, _R(_ArgTypes...)>::destroy() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1031 | { |
| 1032 | __f_.~__compressed_pair<_F, _Alloc>(); |
| 1033 | } |
| 1034 | |
| 1035 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1036 | void |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1037 | __func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1038 | { |
| 1039 | typedef typename _Alloc::template rebind<__func>::other _A; |
| 1040 | _A __a(__f_.second()); |
| 1041 | __f_.~__compressed_pair<_F, _Alloc>(); |
| 1042 | __a.deallocate(this, 1); |
| 1043 | } |
| 1044 | |
| 1045 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1046 | _R |
| 1047 | __func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) |
| 1048 | { |
| 1049 | return __invoke(__f_.first(), _STD::forward<_ArgTypes>(__arg)...); |
| 1050 | } |
| 1051 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1052 | #ifndef _LIBCPP_NO_RTTI |
| 1053 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1054 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1055 | const void* |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1056 | __func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1057 | { |
| 1058 | if (__ti == typeid(_F)) |
| 1059 | return &__f_.first(); |
| 1060 | return (const void*)0; |
| 1061 | } |
| 1062 | |
| 1063 | template<class _F, class _Alloc, class _R, class ..._ArgTypes> |
| 1064 | const std::type_info& |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1065 | __func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | { |
| 1067 | return typeid(_F); |
| 1068 | } |
| 1069 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1070 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1071 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | } // __function |
| 1073 | |
| 1074 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1075 | class _LIBCPP_VISIBLE function<_R(_ArgTypes...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1076 | : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>, |
| 1077 | public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)> |
| 1078 | { |
| 1079 | typedef __function::__base<_R(_ArgTypes...)> __base; |
| 1080 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1081 | __base* __f_; |
| 1082 | |
| 1083 | template <class _F> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1084 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1085 | static bool __not_null(const _F&) {return true;} |
| 1086 | template <class _R2, class ..._A> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1087 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1088 | static bool __not_null(_R2 (*__p)(_A...)) {return __p;} |
| 1089 | template <class _R2, class _C, class ..._A> |
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(_R2 (_C::*__p)(_A...)) {return __p;} |
| 1092 | template <class _R2, class _C, 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 (_C::*__p)(_A...) const) {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...) volatile) {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 volatile) {return __p;} |
| 1101 | template <class _R2, 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(const function<_R(_A...)>& __p) {return __p;} |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1104 | |
| 1105 | template <class _F, bool = __invokable<_F&, _ArgTypes...>::value> |
| 1106 | struct __callable; |
| 1107 | template <class _F> |
| 1108 | struct __callable<_F, true> |
| 1109 | { |
| 1110 | static const bool value = |
| 1111 | is_convertible<typename __invoke_of<_F&, _ArgTypes...>::type, |
| 1112 | _R>::value; |
| 1113 | }; |
| 1114 | template <class _F> |
| 1115 | struct __callable<_F, false> |
| 1116 | { |
| 1117 | static const bool value = false; |
| 1118 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1119 | public: |
| 1120 | typedef _R result_type; |
| 1121 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1122 | // construct/copy/destroy: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1123 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1124 | function() _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1125 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1126 | function(nullptr_t) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1127 | function(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1128 | function(function&&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1129 | template<class _F> |
| 1130 | function(_F, |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1131 | typename enable_if<__callable<_F>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1132 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1133 | template<class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1134 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1135 | function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1136 | template<class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1138 | function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1139 | template<class _Alloc> |
| 1140 | function(allocator_arg_t, const _Alloc&, const function&); |
| 1141 | template<class _Alloc> |
| 1142 | function(allocator_arg_t, const _Alloc&, function&&); |
| 1143 | template<class _F, class _Alloc> |
| 1144 | function(allocator_arg_t, const _Alloc& __a, _F __f, |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1145 | typename enable_if<__callable<_F>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1146 | |
| 1147 | function& operator=(const function&); |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1148 | function& operator=(function&&) _NOEXCEPT; |
| 1149 | function& operator=(nullptr_t) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1150 | template<class _F> |
| 1151 | typename enable_if |
| 1152 | < |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1153 | __callable<typename decay<_F>::type>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | function& |
| 1155 | >::type |
| 1156 | operator=(_F&&); |
| 1157 | |
| 1158 | ~function(); |
| 1159 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1160 | // function modifiers: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1161 | void swap(function&) _NOEXCEPT; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1162 | template<class _F, class _Alloc> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1163 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1164 | void assign(_F&& __f, const _Alloc& __a) |
| 1165 | {function(allocator_arg, __a, _STD::forward<_F>(__f)).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1166 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1167 | // function capacity: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1168 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1169 | /*explicit*/ operator bool() const _NOEXCEPT {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1170 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1171 | // deleted overloads close possible hole in the type system |
| 1172 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | a0f1dc9 | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 1173 | bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1174 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | a0f1dc9 | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 1175 | bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1176 | public: |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1177 | // function invocation: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1178 | _R operator()(_ArgTypes...) const; |
| 1179 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1180 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1181 | // function target access: |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1182 | const std::type_info& target_type() const _NOEXCEPT; |
| 1183 | template <typename _T> _T* target() _NOEXCEPT; |
| 1184 | template <typename _T> const _T* target() const _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1185 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1186 | }; |
| 1187 | |
| 1188 | template<class _R, class ..._ArgTypes> |
| 1189 | function<_R(_ArgTypes...)>::function(const function& __f) |
| 1190 | { |
| 1191 | if (__f.__f_ == 0) |
| 1192 | __f_ = 0; |
| 1193 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1194 | { |
| 1195 | __f_ = (__base*)&__buf_; |
| 1196 | __f.__f_->__clone(__f_); |
| 1197 | } |
| 1198 | else |
| 1199 | __f_ = __f.__f_->__clone(); |
| 1200 | } |
| 1201 | |
| 1202 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1203 | template <class _Alloc> |
| 1204 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
| 1205 | const function& __f) |
| 1206 | { |
| 1207 | if (__f.__f_ == 0) |
| 1208 | __f_ = 0; |
| 1209 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1210 | { |
| 1211 | __f_ = (__base*)&__buf_; |
| 1212 | __f.__f_->__clone(__f_); |
| 1213 | } |
| 1214 | else |
| 1215 | __f_ = __f.__f_->__clone(); |
| 1216 | } |
| 1217 | |
| 1218 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1219 | function<_R(_ArgTypes...)>::function(function&& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1220 | { |
| 1221 | if (__f.__f_ == 0) |
| 1222 | __f_ = 0; |
| 1223 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1224 | { |
| 1225 | __f_ = (__base*)&__buf_; |
| 1226 | __f.__f_->__clone(__f_); |
| 1227 | } |
| 1228 | else |
| 1229 | { |
| 1230 | __f_ = __f.__f_; |
| 1231 | __f.__f_ = 0; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1236 | template <class _Alloc> |
| 1237 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
| 1238 | function&& __f) |
| 1239 | { |
| 1240 | if (__f.__f_ == 0) |
| 1241 | __f_ = 0; |
| 1242 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1243 | { |
| 1244 | __f_ = (__base*)&__buf_; |
| 1245 | __f.__f_->__clone(__f_); |
| 1246 | } |
| 1247 | else |
| 1248 | { |
| 1249 | __f_ = __f.__f_; |
| 1250 | __f.__f_ = 0; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1255 | template <class _F> |
| 1256 | function<_R(_ArgTypes...)>::function(_F __f, |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1257 | typename enable_if<__callable<_F>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1258 | : __f_(0) |
| 1259 | { |
| 1260 | if (__not_null(__f)) |
| 1261 | { |
| 1262 | typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1263 | if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1264 | { |
| 1265 | __f_ = (__base*)&__buf_; |
| 1266 | ::new (__f_) _FF(_STD::move(__f)); |
| 1267 | } |
| 1268 | else |
| 1269 | { |
| 1270 | typedef allocator<_FF> _A; |
| 1271 | _A __a; |
| 1272 | typedef __allocator_destructor<_A> _D; |
| 1273 | unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1274 | ::new (__hold.get()) _FF(_STD::move(__f), allocator<_F>(__a)); |
| 1275 | __f_ = __hold.release(); |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1281 | template <class _F, class _Alloc> |
| 1282 | function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f, |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1283 | typename enable_if<__callable<_F>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1284 | : __f_(0) |
| 1285 | { |
| 1286 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1287 | if (__not_null(__f)) |
| 1288 | { |
| 1289 | typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF; |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1290 | if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1291 | { |
| 1292 | __f_ = (__base*)&__buf_; |
| 1293 | ::new (__f_) _FF(_STD::move(__f)); |
| 1294 | } |
| 1295 | else |
| 1296 | { |
| 1297 | typedef typename __alloc_traits::template |
| 1298 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1299 | rebind_alloc<_FF> |
| 1300 | #else |
| 1301 | rebind_alloc<_FF>::other |
| 1302 | #endif |
| 1303 | _A; |
| 1304 | _A __a(__a0); |
| 1305 | typedef __allocator_destructor<_A> _D; |
| 1306 | unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); |
| 1307 | ::new (__hold.get()) _FF(_STD::move(__f), _Alloc(__a)); |
| 1308 | __f_ = __hold.release(); |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | template<class _R, class ..._ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1314 | function<_R(_ArgTypes...)>& |
| 1315 | function<_R(_ArgTypes...)>::operator=(const function& __f) |
| 1316 | { |
| 1317 | function(__f).swap(*this); |
| 1318 | return *this; |
| 1319 | } |
| 1320 | |
| 1321 | template<class _R, class ..._ArgTypes> |
| 1322 | function<_R(_ArgTypes...)>& |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1323 | function<_R(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1324 | { |
| 1325 | if (__f_ == (__base*)&__buf_) |
| 1326 | __f_->destroy(); |
| 1327 | else if (__f_) |
| 1328 | __f_->destroy_deallocate(); |
| 1329 | __f_ = 0; |
| 1330 | if (__f.__f_ == 0) |
| 1331 | __f_ = 0; |
| 1332 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1333 | { |
| 1334 | __f_ = (__base*)&__buf_; |
| 1335 | __f.__f_->__clone(__f_); |
| 1336 | } |
| 1337 | else |
| 1338 | { |
| 1339 | __f_ = __f.__f_; |
| 1340 | __f.__f_ = 0; |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | template<class _R, class ..._ArgTypes> |
| 1345 | function<_R(_ArgTypes...)>& |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1346 | function<_R(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1347 | { |
| 1348 | if (__f_ == (__base*)&__buf_) |
| 1349 | __f_->destroy(); |
| 1350 | else if (__f_) |
| 1351 | __f_->destroy_deallocate(); |
| 1352 | __f_ = 0; |
| 1353 | } |
| 1354 | |
| 1355 | template<class _R, class ..._ArgTypes> |
| 1356 | template <class _F> |
| 1357 | typename enable_if |
| 1358 | < |
Howard Hinnant | 083ba5f | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 1359 | function<_R(_ArgTypes...)>::template __callable<typename decay<_F>::type>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1360 | function<_R(_ArgTypes...)>& |
| 1361 | >::type |
| 1362 | function<_R(_ArgTypes...)>::operator=(_F&& __f) |
| 1363 | { |
| 1364 | function(_STD::forward<_F>(__f)).swap(*this); |
| 1365 | return *this; |
| 1366 | } |
| 1367 | |
| 1368 | template<class _R, class ..._ArgTypes> |
| 1369 | function<_R(_ArgTypes...)>::~function() |
| 1370 | { |
| 1371 | if (__f_ == (__base*)&__buf_) |
| 1372 | __f_->destroy(); |
| 1373 | else if (__f_) |
| 1374 | __f_->destroy_deallocate(); |
| 1375 | } |
| 1376 | |
| 1377 | template<class _R, class ..._ArgTypes> |
| 1378 | void |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1379 | function<_R(_ArgTypes...)>::swap(function& __f) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1380 | { |
| 1381 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1382 | { |
| 1383 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1384 | __base* __t = (__base*)&__tempbuf; |
| 1385 | __f_->__clone(__t); |
| 1386 | __f_->destroy(); |
| 1387 | __f_ = 0; |
| 1388 | __f.__f_->__clone((__base*)&__buf_); |
| 1389 | __f.__f_->destroy(); |
| 1390 | __f.__f_ = 0; |
| 1391 | __f_ = (__base*)&__buf_; |
| 1392 | __t->__clone((__base*)&__f.__buf_); |
| 1393 | __t->destroy(); |
| 1394 | __f.__f_ = (__base*)&__f.__buf_; |
| 1395 | } |
| 1396 | else if (__f_ == (__base*)&__buf_) |
| 1397 | { |
| 1398 | __f_->__clone((__base*)&__f.__buf_); |
| 1399 | __f_->destroy(); |
| 1400 | __f_ = __f.__f_; |
| 1401 | __f.__f_ = (__base*)&__f.__buf_; |
| 1402 | } |
| 1403 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1404 | { |
| 1405 | __f.__f_->__clone((__base*)&__buf_); |
| 1406 | __f.__f_->destroy(); |
| 1407 | __f.__f_ = __f_; |
| 1408 | __f_ = (__base*)&__buf_; |
| 1409 | } |
| 1410 | else |
| 1411 | _STD::swap(__f_, __f.__f_); |
| 1412 | } |
| 1413 | |
| 1414 | template<class _R, class ..._ArgTypes> |
| 1415 | _R |
| 1416 | function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const |
| 1417 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1418 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1419 | if (__f_ == 0) |
| 1420 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1421 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | return (*__f_)(_STD::forward<_ArgTypes>(__arg)...); |
| 1423 | } |
| 1424 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1425 | #ifndef _LIBCPP_NO_RTTI |
| 1426 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1427 | template<class _R, class ..._ArgTypes> |
| 1428 | const std::type_info& |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1429 | function<_R(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | { |
| 1431 | if (__f_ == 0) |
| 1432 | return typeid(void); |
| 1433 | return __f_->target_type(); |
| 1434 | } |
| 1435 | |
| 1436 | template<class _R, class ..._ArgTypes> |
| 1437 | template <typename _T> |
| 1438 | _T* |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1439 | function<_R(_ArgTypes...)>::target() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1440 | { |
| 1441 | if (__f_ == 0) |
| 1442 | return (_T*)0; |
| 1443 | return (_T*)__f_->target(typeid(_T)); |
| 1444 | } |
| 1445 | |
| 1446 | template<class _R, class ..._ArgTypes> |
| 1447 | template <typename _T> |
| 1448 | const _T* |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1449 | function<_R(_ArgTypes...)>::target() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1450 | { |
| 1451 | if (__f_ == 0) |
| 1452 | return (const _T*)0; |
| 1453 | return (const _T*)__f_->target(typeid(_T)); |
| 1454 | } |
| 1455 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1456 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1457 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1458 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1459 | inline _LIBCPP_INLINE_VISIBILITY |
| 1460 | bool |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1461 | operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1463 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1464 | inline _LIBCPP_INLINE_VISIBILITY |
| 1465 | bool |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1466 | operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1467 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1468 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1469 | inline _LIBCPP_INLINE_VISIBILITY |
| 1470 | bool |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1471 | operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1472 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1473 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1474 | inline _LIBCPP_INLINE_VISIBILITY |
| 1475 | bool |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1476 | operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1477 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1478 | template <class _R, class... _ArgTypes> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1479 | inline _LIBCPP_INLINE_VISIBILITY |
| 1480 | void |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1481 | swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1482 | {return __x.swap(__y);} |
| 1483 | |
| 1484 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1485 | template<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 1487 | |
| 1488 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1489 | template<class _Tp> struct _LIBCPP_VISIBLE is_placeholder |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1490 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 1491 | |
| 1492 | namespace placeholders |
| 1493 | { |
| 1494 | |
| 1495 | template <int _N> struct __ph {}; |
| 1496 | |
| 1497 | extern __ph<1> _1; |
| 1498 | extern __ph<2> _2; |
| 1499 | extern __ph<3> _3; |
| 1500 | extern __ph<4> _4; |
| 1501 | extern __ph<5> _5; |
| 1502 | extern __ph<6> _6; |
| 1503 | extern __ph<7> _7; |
| 1504 | extern __ph<8> _8; |
| 1505 | extern __ph<9> _9; |
| 1506 | extern __ph<10> _10; |
| 1507 | |
| 1508 | } // placeholders |
| 1509 | |
| 1510 | template<int _N> |
| 1511 | struct __is_placeholder<placeholders::__ph<_N> > |
| 1512 | : public integral_constant<int, _N> {}; |
| 1513 | |
| 1514 | template <class _Tp, class _Uj> |
| 1515 | inline _LIBCPP_INLINE_VISIBILITY |
| 1516 | _Tp& |
| 1517 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 1518 | { |
| 1519 | return __t.get(); |
| 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 |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1524 | typename __invoke_of<_Ti&, _Uj...>::type |
| 1525 | __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1526 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1527 | return __ti(_STD::forward<_Uj>(get<_Indx>(__uj))...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | template <class _Ti, class ..._Uj> |
| 1531 | inline _LIBCPP_INLINE_VISIBILITY |
| 1532 | typename enable_if |
| 1533 | < |
| 1534 | is_bind_expression<_Ti>::value, |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1535 | typename __invoke_of<_Ti&, _Uj...>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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; |
Douglas Gregor | 5ea2e37 | 2011-01-25 23:11:15 +0000 | [diff] [blame] | 1562 | return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | template <class _Ti, class _Uj> |
| 1566 | inline _LIBCPP_INLINE_VISIBILITY |
| 1567 | typename enable_if |
| 1568 | < |
| 1569 | !is_bind_expression<_Ti>::value && |
| 1570 | is_placeholder<_Ti>::value == 0 && |
| 1571 | !__is_reference_wrapper<_Ti>::value, |
| 1572 | _Ti& |
| 1573 | >::type |
| 1574 | __mu(_Ti& __ti, _Uj& __uj) |
| 1575 | { |
| 1576 | return __ti; |
| 1577 | } |
| 1578 | |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1579 | template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, |
| 1580 | class _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1581 | struct ____mu_return; |
| 1582 | |
| 1583 | template <class _Ti, class ..._Uj> |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1584 | struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1585 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1586 | typedef typename __invoke_of<_Ti&, _Uj...>::type type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1587 | }; |
| 1588 | |
| 1589 | template <class _Ti, class _TupleUj> |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1590 | struct ____mu_return<_Ti, false, false, true, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1591 | { |
| 1592 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 1593 | _TupleUj>::type&& type; |
| 1594 | }; |
| 1595 | |
| 1596 | template <class _Ti, class _TupleUj> |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1597 | struct ____mu_return<_Ti, true, false, false, _TupleUj> |
| 1598 | { |
| 1599 | typedef typename _Ti::type& type; |
| 1600 | }; |
| 1601 | |
| 1602 | template <class _Ti, class _TupleUj> |
| 1603 | struct ____mu_return<_Ti, false, false, false, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1604 | { |
| 1605 | typedef _Ti& type; |
| 1606 | }; |
| 1607 | |
| 1608 | template <class _Ti, class _TupleUj> |
| 1609 | struct __mu_return |
| 1610 | : public ____mu_return<_Ti, |
Howard Hinnant | ef54251 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 1611 | __is_reference_wrapper<_Ti>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1612 | is_bind_expression<_Ti>::value, |
| 1613 | 0 < is_placeholder<_Ti>::value, |
| 1614 | _TupleUj> |
| 1615 | { |
| 1616 | }; |
| 1617 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1618 | template <class _F, class _BoundArgs, class _TupleUj> |
| 1619 | struct __bind_return; |
| 1620 | |
| 1621 | template <class _F, class ..._BoundArgs, class _TupleUj> |
| 1622 | struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj> |
| 1623 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1624 | typedef typename __invoke_of |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1625 | < |
| 1626 | _F&, |
| 1627 | typename __mu_return |
| 1628 | < |
| 1629 | _BoundArgs, |
| 1630 | _TupleUj |
| 1631 | >::type... |
| 1632 | >::type type; |
| 1633 | }; |
| 1634 | |
| 1635 | template <class _F, class ..._BoundArgs, class _TupleUj> |
| 1636 | struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj> |
| 1637 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1638 | typedef typename __invoke_of |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1639 | < |
| 1640 | _F&, |
| 1641 | typename __mu_return |
| 1642 | < |
| 1643 | const _BoundArgs, |
| 1644 | _TupleUj |
| 1645 | >::type... |
| 1646 | >::type type; |
| 1647 | }; |
| 1648 | |
| 1649 | template <class _F, class _BoundArgs, size_t ..._Indx, class _Args> |
| 1650 | inline _LIBCPP_INLINE_VISIBILITY |
| 1651 | typename __bind_return<_F, _BoundArgs, _Args>::type |
| 1652 | __apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
| 1653 | _Args&& __args) |
| 1654 | { |
| 1655 | return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); |
| 1656 | } |
| 1657 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1658 | template<class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1659 | class __bind |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1660 | : public __weak_result_type<typename decay<_F>::type> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1661 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1662 | typedef typename decay<_F>::type _Fd; |
| 1663 | typedef tuple<typename decay<_BoundArgs>::type...> _Td; |
| 1664 | _Fd __f_; |
| 1665 | _Td __bound_args_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1666 | |
| 1667 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 1668 | public: |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1669 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1670 | __bind(__bind&& __b) |
| 1671 | : __f_(_STD::move(__b.__f_)), |
| 1672 | __bound_args_(_STD::move(__b.__bound_args_)) {} |
| 1673 | |
| 1674 | template <class _G, class ..._BA> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1675 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1676 | explicit __bind(_G&& __f, _BA&& ...__bound_args) |
| 1677 | : __f_(_STD::forward<_G>(__f)), |
| 1678 | __bound_args_(_STD::forward<_BA>(__bound_args)...) {} |
| 1679 | |
| 1680 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1681 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1682 | typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1683 | operator()(_Args&& ...__args) |
| 1684 | { |
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 | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1691 | typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | |
Howard Hinnant | 496934a | 2011-05-16 16:19:01 +0000 | [diff] [blame] | 1710 | _LIBCPP_INLINE_VISIBILITY |
| 1711 | __bind_r(__bind_r&& __b) |
Howard Hinnant | 6b9826b | 2011-05-17 20:27:51 +0000 | [diff] [blame] | 1712 | : base(_STD::forward<base>(__b)) {} |
Howard Hinnant | 496934a | 2011-05-16 16:19:01 +0000 | [diff] [blame] | 1713 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1714 | template <class _G, class ..._BA> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1715 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1716 | explicit __bind_r(_G&& __f, _BA&& ...__bound_args) |
| 1717 | : base(_STD::forward<_G>(__f), |
| 1718 | _STD::forward<_BA>(__bound_args)...) {} |
| 1719 | |
| 1720 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1721 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1722 | result_type |
| 1723 | operator()(_Args&& ...__args) |
| 1724 | { |
| 1725 | return base::operator()(_STD::forward<_Args>(__args)...); |
| 1726 | } |
| 1727 | |
| 1728 | template <class ..._Args> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1729 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1730 | result_type |
| 1731 | operator()(_Args&& ...__args) const |
| 1732 | { |
| 1733 | return base::operator()(_STD::forward<_Args>(__args)...); |
| 1734 | } |
| 1735 | }; |
| 1736 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1737 | template<class _R, class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1738 | struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {}; |
| 1739 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1740 | template<class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1741 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1742 | __bind<_F, _BoundArgs...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1743 | bind(_F&& __f, _BoundArgs&&... __bound_args) |
| 1744 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1745 | typedef __bind<_F, _BoundArgs...> type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1746 | return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...); |
| 1747 | } |
| 1748 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1749 | template<class _R, class _F, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1750 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1751 | __bind_r<_R, _F, _BoundArgs...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1752 | bind(_F&& __f, _BoundArgs&&... __bound_args) |
| 1753 | { |
Howard Hinnant | 0148a83 | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 1754 | typedef __bind_r<_R, _F, _BoundArgs...> type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1755 | return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...); |
| 1756 | } |
| 1757 | |
| 1758 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1759 | |
| 1760 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1761 | struct _LIBCPP_VISIBLE hash<bool> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1762 | : public unary_function<bool, size_t> |
| 1763 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1764 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1765 | size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1766 | }; |
| 1767 | |
| 1768 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1769 | struct _LIBCPP_VISIBLE hash<char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1770 | : public unary_function<char, size_t> |
| 1771 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1772 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1773 | size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1774 | }; |
| 1775 | |
| 1776 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1777 | struct _LIBCPP_VISIBLE hash<signed char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1778 | : public unary_function<signed char, size_t> |
| 1779 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1780 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1781 | size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | }; |
| 1783 | |
| 1784 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1785 | struct _LIBCPP_VISIBLE hash<unsigned char> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1786 | : public unary_function<unsigned char, size_t> |
| 1787 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1788 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1789 | size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1790 | }; |
| 1791 | |
| 1792 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 1793 | |
| 1794 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1795 | struct _LIBCPP_VISIBLE hash<char16_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1796 | : public unary_function<char16_t, size_t> |
| 1797 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1799 | size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1800 | }; |
| 1801 | |
| 1802 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1803 | struct _LIBCPP_VISIBLE hash<char32_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1804 | : public unary_function<char32_t, size_t> |
| 1805 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1806 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1807 | size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1808 | }; |
| 1809 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1810 | #endif // _LIBCPP_HAS_NO_UNICODE_CHARS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1811 | |
| 1812 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1813 | struct _LIBCPP_VISIBLE hash<wchar_t> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1814 | : public unary_function<wchar_t, size_t> |
| 1815 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1816 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1817 | size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1818 | }; |
| 1819 | |
| 1820 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1821 | struct _LIBCPP_VISIBLE hash<short> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1822 | : public unary_function<short, size_t> |
| 1823 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1824 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1825 | size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1826 | }; |
| 1827 | |
| 1828 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1829 | struct _LIBCPP_VISIBLE hash<unsigned short> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1830 | : public unary_function<unsigned short, size_t> |
| 1831 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1832 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1833 | size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1834 | }; |
| 1835 | |
| 1836 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1837 | struct _LIBCPP_VISIBLE hash<int> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1838 | : public unary_function<int, size_t> |
| 1839 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1840 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1841 | size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1842 | }; |
| 1843 | |
| 1844 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1845 | struct _LIBCPP_VISIBLE hash<unsigned int> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1846 | : public unary_function<unsigned int, size_t> |
| 1847 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1848 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1849 | size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 | }; |
| 1851 | |
| 1852 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1853 | struct _LIBCPP_VISIBLE hash<long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1854 | : public unary_function<long, size_t> |
| 1855 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1857 | size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1858 | }; |
| 1859 | |
| 1860 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1861 | struct _LIBCPP_VISIBLE hash<unsigned long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 | : public unary_function<unsigned long, size_t> |
| 1863 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1864 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1865 | size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1866 | }; |
| 1867 | |
| 1868 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1869 | struct _LIBCPP_VISIBLE hash<long long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1870 | : public unary_function<long long, size_t> |
| 1871 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1872 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1873 | size_t operator()(long long __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1874 | { |
| 1875 | size_t __r = 0; |
| 1876 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1877 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1878 | __r ^= __p[__i]; |
| 1879 | return __r; |
| 1880 | } |
| 1881 | }; |
| 1882 | |
| 1883 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1884 | struct _LIBCPP_VISIBLE hash<unsigned long long> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1885 | : public unary_function<unsigned long long, size_t> |
| 1886 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1887 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1888 | size_t operator()(unsigned long long __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1889 | { |
| 1890 | size_t __r = 0; |
| 1891 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1892 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1893 | __r ^= __p[__i]; |
| 1894 | return __r; |
| 1895 | } |
| 1896 | }; |
| 1897 | |
| 1898 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1899 | struct _LIBCPP_VISIBLE hash<float> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1900 | : public unary_function<float, size_t> |
| 1901 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1902 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1903 | size_t operator()(float __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1904 | { |
| 1905 | if (__v == 0) |
| 1906 | return 0; |
| 1907 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1908 | return *__p; |
| 1909 | } |
| 1910 | }; |
| 1911 | |
| 1912 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1913 | struct _LIBCPP_VISIBLE hash<double> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1914 | : public unary_function<double, size_t> |
| 1915 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1916 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1917 | size_t operator()(double __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1918 | { |
| 1919 | if (__v == 0) |
| 1920 | return 0; |
| 1921 | size_t __r = 0; |
| 1922 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1923 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1924 | __r ^= __p[__i]; |
| 1925 | return __r; |
| 1926 | } |
| 1927 | }; |
| 1928 | |
| 1929 | template <> |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1930 | struct _LIBCPP_VISIBLE hash<long double> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1931 | : public unary_function<long double, size_t> |
| 1932 | { |
Howard Hinnant | 42a63a7 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1933 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1934 | size_t operator()(long double __v) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1935 | { |
| 1936 | if (__v == 0) |
| 1937 | return 0; |
| 1938 | size_t __r = 0; |
| 1939 | const size_t* const __p = reinterpret_cast<const size_t*>(&__v); |
| 1940 | for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i) |
| 1941 | __r ^= __p[__i]; |
| 1942 | return __r; |
| 1943 | } |
| 1944 | }; |
| 1945 | |
Howard Hinnant | 21aefc3 | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 1946 | // struct hash<T*> in <memory> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1947 | |
| 1948 | _LIBCPP_END_NAMESPACE_STD |
| 1949 | |
| 1950 | #endif // _LIBCPP_FUNCTIONAL |