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