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