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