__functional_03 revision 300770
1227825Stheraven// -*- C++ -*- 2227825Stheraven//===----------------------------------------------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_FUNCTIONAL_03 12227825Stheraven#define _LIBCPP_FUNCTIONAL_03 13227825Stheraven 14227825Stheraven// manual variadic expansion for <functional> 15227825Stheraven 16227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17227825Stheraven#pragma GCC system_header 18227825Stheraven#endif 19227825Stheraven 20300770Sdimnamespace __function { 21227825Stheraven 22227825Stheraventemplate<class _Fp> class __base; 23227825Stheraven 24232924Stheraventemplate<class _Rp> 25232924Stheravenclass __base<_Rp()> 26227825Stheraven{ 27227825Stheraven __base(const __base&); 28227825Stheraven __base& operator=(const __base&); 29227825Stheravenpublic: 30227825Stheraven __base() {} 31227825Stheraven virtual ~__base() {} 32227825Stheraven virtual __base* __clone() const = 0; 33227825Stheraven virtual void __clone(__base*) const = 0; 34227825Stheraven virtual void destroy() = 0; 35227825Stheraven virtual void destroy_deallocate() = 0; 36232924Stheraven virtual _Rp operator()() = 0; 37227825Stheraven#ifndef _LIBCPP_NO_RTTI 38227825Stheraven virtual const void* target(const type_info&) const = 0; 39227825Stheraven virtual const std::type_info& target_type() const = 0; 40227825Stheraven#endif // _LIBCPP_NO_RTTI 41227825Stheraven}; 42227825Stheraven 43232924Stheraventemplate<class _Rp, class _A0> 44232924Stheravenclass __base<_Rp(_A0)> 45227825Stheraven{ 46227825Stheraven __base(const __base&); 47227825Stheraven __base& operator=(const __base&); 48227825Stheravenpublic: 49227825Stheraven __base() {} 50227825Stheraven virtual ~__base() {} 51227825Stheraven virtual __base* __clone() const = 0; 52227825Stheraven virtual void __clone(__base*) const = 0; 53227825Stheraven virtual void destroy() = 0; 54227825Stheraven virtual void destroy_deallocate() = 0; 55232924Stheraven virtual _Rp operator()(_A0) = 0; 56227825Stheraven#ifndef _LIBCPP_NO_RTTI 57227825Stheraven virtual const void* target(const type_info&) const = 0; 58227825Stheraven virtual const std::type_info& target_type() const = 0; 59227825Stheraven#endif // _LIBCPP_NO_RTTI 60227825Stheraven}; 61227825Stheraven 62232924Stheraventemplate<class _Rp, class _A0, class _A1> 63232924Stheravenclass __base<_Rp(_A0, _A1)> 64227825Stheraven{ 65227825Stheraven __base(const __base&); 66227825Stheraven __base& operator=(const __base&); 67227825Stheravenpublic: 68227825Stheraven __base() {} 69227825Stheraven virtual ~__base() {} 70227825Stheraven virtual __base* __clone() const = 0; 71227825Stheraven virtual void __clone(__base*) const = 0; 72227825Stheraven virtual void destroy() = 0; 73227825Stheraven virtual void destroy_deallocate() = 0; 74232924Stheraven virtual _Rp operator()(_A0, _A1) = 0; 75227825Stheraven#ifndef _LIBCPP_NO_RTTI 76227825Stheraven virtual const void* target(const type_info&) const = 0; 77227825Stheraven virtual const std::type_info& target_type() const = 0; 78227825Stheraven#endif // _LIBCPP_NO_RTTI 79227825Stheraven}; 80227825Stheraven 81232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 82232924Stheravenclass __base<_Rp(_A0, _A1, _A2)> 83227825Stheraven{ 84227825Stheraven __base(const __base&); 85227825Stheraven __base& operator=(const __base&); 86227825Stheravenpublic: 87227825Stheraven __base() {} 88227825Stheraven virtual ~__base() {} 89227825Stheraven virtual __base* __clone() const = 0; 90227825Stheraven virtual void __clone(__base*) const = 0; 91227825Stheraven virtual void destroy() = 0; 92227825Stheraven virtual void destroy_deallocate() = 0; 93232924Stheraven virtual _Rp operator()(_A0, _A1, _A2) = 0; 94227825Stheraven#ifndef _LIBCPP_NO_RTTI 95227825Stheraven virtual const void* target(const type_info&) const = 0; 96227825Stheraven virtual const std::type_info& target_type() const = 0; 97227825Stheraven#endif // _LIBCPP_NO_RTTI 98227825Stheraven}; 99227825Stheraven 100227825Stheraventemplate<class _FD, class _Alloc, class _FB> class __func; 101227825Stheraven 102232924Stheraventemplate<class _Fp, class _Alloc, class _Rp> 103232924Stheravenclass __func<_Fp, _Alloc, _Rp()> 104232924Stheraven : public __base<_Rp()> 105227825Stheraven{ 106232924Stheraven __compressed_pair<_Fp, _Alloc> __f_; 107227825Stheravenpublic: 108232924Stheraven explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} 109232924Stheraven explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 110232924Stheraven virtual __base<_Rp()>* __clone() const; 111232924Stheraven virtual void __clone(__base<_Rp()>*) const; 112227825Stheraven virtual void destroy(); 113227825Stheraven virtual void destroy_deallocate(); 114232924Stheraven virtual _Rp operator()(); 115227825Stheraven#ifndef _LIBCPP_NO_RTTI 116227825Stheraven virtual const void* target(const type_info&) const; 117227825Stheraven virtual const std::type_info& target_type() const; 118227825Stheraven#endif // _LIBCPP_NO_RTTI 119227825Stheraven}; 120227825Stheraven 121232924Stheraventemplate<class _Fp, class _Alloc, class _Rp> 122232924Stheraven__base<_Rp()>* 123232924Stheraven__func<_Fp, _Alloc, _Rp()>::__clone() const 124227825Stheraven{ 125288943Sdim typedef allocator_traits<_Alloc> __alloc_traits; 126288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 127232924Stheraven _Ap __a(__f_.second()); 128232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 129232924Stheraven unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 130227825Stheraven ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 131227825Stheraven return __hold.release(); 132227825Stheraven} 133227825Stheraven 134232924Stheraventemplate<class _Fp, class _Alloc, class _Rp> 135227825Stheravenvoid 136232924Stheraven__func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const 137227825Stheraven{ 138227825Stheraven ::new (__p) __func(__f_.first(), __f_.second()); 139227825Stheraven} 140227825Stheraven 141232924Stheraventemplate<class _Fp, class _Alloc, class _Rp> 142227825Stheravenvoid 143232924Stheraven__func<_Fp, _Alloc, _Rp()>::destroy() 144227825Stheraven{ 145232924Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 146227825Stheraven} 147227825Stheraven 148232924Stheraventemplate<class _Fp, class _Alloc, class _Rp> 149227825Stheravenvoid 150232924Stheraven__func<_Fp, _Alloc, _Rp()>::destroy_deallocate() 151227825Stheraven{ 152288943Sdim typedef allocator_traits<_Alloc> __alloc_traits; 153288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 154232924Stheraven _Ap __a(__f_.second()); 155232924Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 156227825Stheraven __a.deallocate(this, 1); 157227825Stheraven} 158227825Stheraven 159232924Stheraventemplate<class _Fp, class _Alloc, class _Rp> 160232924Stheraven_Rp 161232924Stheraven__func<_Fp, _Alloc, _Rp()>::operator()() 162227825Stheraven{ 163288943Sdim typedef __invoke_void_return_wrapper<_Rp> _Invoker; 164288943Sdim return _Invoker::__call(__f_.first()); 165227825Stheraven} 166227825Stheraven 167227825Stheraven#ifndef _LIBCPP_NO_RTTI 168227825Stheraven 169232924Stheraventemplate<class _Fp, class _Alloc, class _Rp> 170227825Stheravenconst void* 171232924Stheraven__func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const 172227825Stheraven{ 173232924Stheraven if (__ti == typeid(_Fp)) 174227825Stheraven return &__f_.first(); 175227825Stheraven return (const void*)0; 176227825Stheraven} 177227825Stheraven 178232924Stheraventemplate<class _Fp, class _Alloc, class _Rp> 179227825Stheravenconst std::type_info& 180232924Stheraven__func<_Fp, _Alloc, _Rp()>::target_type() const 181227825Stheraven{ 182232924Stheraven return typeid(_Fp); 183227825Stheraven} 184227825Stheraven 185227825Stheraven#endif // _LIBCPP_NO_RTTI 186227825Stheraven 187232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0> 188232924Stheravenclass __func<_Fp, _Alloc, _Rp(_A0)> 189232924Stheraven : public __base<_Rp(_A0)> 190227825Stheraven{ 191232924Stheraven __compressed_pair<_Fp, _Alloc> __f_; 192227825Stheravenpublic: 193232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} 194232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) 195227825Stheraven : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 196232924Stheraven virtual __base<_Rp(_A0)>* __clone() const; 197232924Stheraven virtual void __clone(__base<_Rp(_A0)>*) const; 198227825Stheraven virtual void destroy(); 199227825Stheraven virtual void destroy_deallocate(); 200232924Stheraven virtual _Rp operator()(_A0); 201227825Stheraven#ifndef _LIBCPP_NO_RTTI 202227825Stheraven virtual const void* target(const type_info&) const; 203227825Stheraven virtual const std::type_info& target_type() const; 204227825Stheraven#endif // _LIBCPP_NO_RTTI 205227825Stheraven}; 206227825Stheraven 207232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0> 208232924Stheraven__base<_Rp(_A0)>* 209232924Stheraven__func<_Fp, _Alloc, _Rp(_A0)>::__clone() const 210227825Stheraven{ 211288943Sdim typedef allocator_traits<_Alloc> __alloc_traits; 212288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 213232924Stheraven _Ap __a(__f_.second()); 214232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 215232924Stheraven unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 216227825Stheraven ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 217227825Stheraven return __hold.release(); 218227825Stheraven} 219227825Stheraven 220232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0> 221227825Stheravenvoid 222232924Stheraven__func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const 223227825Stheraven{ 224227825Stheraven ::new (__p) __func(__f_.first(), __f_.second()); 225227825Stheraven} 226227825Stheraven 227232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0> 228227825Stheravenvoid 229232924Stheraven__func<_Fp, _Alloc, _Rp(_A0)>::destroy() 230227825Stheraven{ 231232924Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 232227825Stheraven} 233227825Stheraven 234232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0> 235227825Stheravenvoid 236232924Stheraven__func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate() 237227825Stheraven{ 238288943Sdim typedef allocator_traits<_Alloc> __alloc_traits; 239288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 240232924Stheraven _Ap __a(__f_.second()); 241232924Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 242227825Stheraven __a.deallocate(this, 1); 243227825Stheraven} 244227825Stheraven 245232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0> 246232924Stheraven_Rp 247232924Stheraven__func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0) 248227825Stheraven{ 249288943Sdim typedef __invoke_void_return_wrapper<_Rp> _Invoker; 250288943Sdim return _Invoker::__call(__f_.first(), __a0); 251227825Stheraven} 252227825Stheraven 253227825Stheraven#ifndef _LIBCPP_NO_RTTI 254227825Stheraven 255232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0> 256227825Stheravenconst void* 257232924Stheraven__func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const 258227825Stheraven{ 259232924Stheraven if (__ti == typeid(_Fp)) 260227825Stheraven return &__f_.first(); 261227825Stheraven return (const void*)0; 262227825Stheraven} 263227825Stheraven 264232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0> 265227825Stheravenconst std::type_info& 266232924Stheraven__func<_Fp, _Alloc, _Rp(_A0)>::target_type() const 267227825Stheraven{ 268232924Stheraven return typeid(_Fp); 269227825Stheraven} 270227825Stheraven 271227825Stheraven#endif // _LIBCPP_NO_RTTI 272227825Stheraven 273232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 274232924Stheravenclass __func<_Fp, _Alloc, _Rp(_A0, _A1)> 275232924Stheraven : public __base<_Rp(_A0, _A1)> 276227825Stheraven{ 277232924Stheraven __compressed_pair<_Fp, _Alloc> __f_; 278227825Stheravenpublic: 279232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} 280232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) 281227825Stheraven : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 282232924Stheraven virtual __base<_Rp(_A0, _A1)>* __clone() const; 283232924Stheraven virtual void __clone(__base<_Rp(_A0, _A1)>*) const; 284227825Stheraven virtual void destroy(); 285227825Stheraven virtual void destroy_deallocate(); 286232924Stheraven virtual _Rp operator()(_A0, _A1); 287227825Stheraven#ifndef _LIBCPP_NO_RTTI 288227825Stheraven virtual const void* target(const type_info&) const; 289227825Stheraven virtual const std::type_info& target_type() const; 290227825Stheraven#endif // _LIBCPP_NO_RTTI 291227825Stheraven}; 292227825Stheraven 293232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 294232924Stheraven__base<_Rp(_A0, _A1)>* 295232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const 296227825Stheraven{ 297288943Sdim typedef allocator_traits<_Alloc> __alloc_traits; 298288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 299232924Stheraven _Ap __a(__f_.second()); 300232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 301232924Stheraven unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 302227825Stheraven ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 303227825Stheraven return __hold.release(); 304227825Stheraven} 305227825Stheraven 306232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 307227825Stheravenvoid 308232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const 309227825Stheraven{ 310227825Stheraven ::new (__p) __func(__f_.first(), __f_.second()); 311227825Stheraven} 312227825Stheraven 313232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 314227825Stheravenvoid 315232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy() 316227825Stheraven{ 317232924Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 318227825Stheraven} 319227825Stheraven 320232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 321227825Stheravenvoid 322232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate() 323227825Stheraven{ 324288943Sdim typedef allocator_traits<_Alloc> __alloc_traits; 325288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 326232924Stheraven _Ap __a(__f_.second()); 327232924Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 328227825Stheraven __a.deallocate(this, 1); 329227825Stheraven} 330227825Stheraven 331232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 332232924Stheraven_Rp 333232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) 334227825Stheraven{ 335288943Sdim typedef __invoke_void_return_wrapper<_Rp> _Invoker; 336288943Sdim return _Invoker::__call(__f_.first(), __a0, __a1); 337227825Stheraven} 338227825Stheraven 339227825Stheraven#ifndef _LIBCPP_NO_RTTI 340227825Stheraven 341232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 342227825Stheravenconst void* 343232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const 344227825Stheraven{ 345232924Stheraven if (__ti == typeid(_Fp)) 346227825Stheraven return &__f_.first(); 347227825Stheraven return (const void*)0; 348227825Stheraven} 349227825Stheraven 350232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 351227825Stheravenconst std::type_info& 352232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const 353227825Stheraven{ 354232924Stheraven return typeid(_Fp); 355227825Stheraven} 356227825Stheraven 357227825Stheraven#endif // _LIBCPP_NO_RTTI 358227825Stheraven 359232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 360232924Stheravenclass __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> 361232924Stheraven : public __base<_Rp(_A0, _A1, _A2)> 362227825Stheraven{ 363232924Stheraven __compressed_pair<_Fp, _Alloc> __f_; 364227825Stheravenpublic: 365232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} 366232924Stheraven _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) 367227825Stheraven : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 368232924Stheraven virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const; 369232924Stheraven virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const; 370227825Stheraven virtual void destroy(); 371227825Stheraven virtual void destroy_deallocate(); 372232924Stheraven virtual _Rp operator()(_A0, _A1, _A2); 373227825Stheraven#ifndef _LIBCPP_NO_RTTI 374227825Stheraven virtual const void* target(const type_info&) const; 375227825Stheraven virtual const std::type_info& target_type() const; 376227825Stheraven#endif // _LIBCPP_NO_RTTI 377227825Stheraven}; 378227825Stheraven 379232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 380232924Stheraven__base<_Rp(_A0, _A1, _A2)>* 381232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const 382227825Stheraven{ 383288943Sdim typedef allocator_traits<_Alloc> __alloc_traits; 384288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 385232924Stheraven _Ap __a(__f_.second()); 386232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 387232924Stheraven unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 388227825Stheraven ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 389227825Stheraven return __hold.release(); 390227825Stheraven} 391227825Stheraven 392232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 393227825Stheravenvoid 394232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const 395227825Stheraven{ 396227825Stheraven ::new (__p) __func(__f_.first(), __f_.second()); 397227825Stheraven} 398227825Stheraven 399232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 400227825Stheravenvoid 401232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy() 402227825Stheraven{ 403232924Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 404227825Stheraven} 405227825Stheraven 406232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 407227825Stheravenvoid 408232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate() 409227825Stheraven{ 410288943Sdim typedef allocator_traits<_Alloc> __alloc_traits; 411288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 412232924Stheraven _Ap __a(__f_.second()); 413232924Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 414227825Stheraven __a.deallocate(this, 1); 415227825Stheraven} 416227825Stheraven 417232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 418232924Stheraven_Rp 419232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) 420227825Stheraven{ 421288943Sdim typedef __invoke_void_return_wrapper<_Rp> _Invoker; 422288943Sdim return _Invoker::__call(__f_.first(), __a0, __a1, __a2); 423227825Stheraven} 424227825Stheraven 425227825Stheraven#ifndef _LIBCPP_NO_RTTI 426227825Stheraven 427232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 428227825Stheravenconst void* 429232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const 430227825Stheraven{ 431232924Stheraven if (__ti == typeid(_Fp)) 432227825Stheraven return &__f_.first(); 433227825Stheraven return (const void*)0; 434227825Stheraven} 435227825Stheraven 436232924Stheraventemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 437227825Stheravenconst std::type_info& 438232924Stheraven__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const 439227825Stheraven{ 440232924Stheraven return typeid(_Fp); 441227825Stheraven} 442227825Stheraven 443227825Stheraven#endif // _LIBCPP_NO_RTTI 444227825Stheraven 445227825Stheraven} // __function 446227825Stheraven 447232924Stheraventemplate<class _Rp> 448261272Sdimclass _LIBCPP_TYPE_VIS_ONLY function<_Rp()> 449227825Stheraven{ 450232924Stheraven typedef __function::__base<_Rp()> __base; 451227825Stheraven aligned_storage<3*sizeof(void*)>::type __buf_; 452227825Stheraven __base* __f_; 453227825Stheraven 454227825Stheravenpublic: 455232924Stheraven typedef _Rp result_type; 456227825Stheraven 457227825Stheraven // 20.7.16.2.1, construct/copy/destroy: 458227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} 459227825Stheraven _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} 460227825Stheraven function(const function&); 461232924Stheraven template<class _Fp> 462232924Stheraven function(_Fp, 463232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type* = 0); 464227825Stheraven 465227825Stheraven template<class _Alloc> 466227825Stheraven _LIBCPP_INLINE_VISIBILITY 467227825Stheraven function(allocator_arg_t, const _Alloc&) : __f_(0) {} 468227825Stheraven template<class _Alloc> 469227825Stheraven _LIBCPP_INLINE_VISIBILITY 470227825Stheraven function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} 471227825Stheraven template<class _Alloc> 472227825Stheraven function(allocator_arg_t, const _Alloc&, const function&); 473232924Stheraven template<class _Fp, class _Alloc> 474232924Stheraven function(allocator_arg_t, const _Alloc& __a, _Fp __f, 475232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type* = 0); 476227825Stheraven 477227825Stheraven function& operator=(const function&); 478227825Stheraven function& operator=(nullptr_t); 479232924Stheraven template<class _Fp> 480227825Stheraven typename enable_if 481227825Stheraven < 482232924Stheraven !is_integral<_Fp>::value, 483227825Stheraven function& 484227825Stheraven >::type 485232924Stheraven operator=(_Fp); 486227825Stheraven 487227825Stheraven ~function(); 488227825Stheraven 489227825Stheraven // 20.7.16.2.2, function modifiers: 490227825Stheraven void swap(function&); 491232924Stheraven template<class _Fp, class _Alloc> 492227825Stheraven _LIBCPP_INLINE_VISIBILITY 493232924Stheraven void assign(_Fp __f, const _Alloc& __a) 494227825Stheraven {function(allocator_arg, __a, __f).swap(*this);} 495227825Stheraven 496227825Stheraven // 20.7.16.2.3, function capacity: 497227825Stheraven _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} 498227825Stheraven 499227825Stheravenprivate: 500227825Stheraven // deleted overloads close possible hole in the type system 501227825Stheraven template<class _R2> 502227825Stheraven bool operator==(const function<_R2()>&) const;// = delete; 503227825Stheraven template<class _R2> 504227825Stheraven bool operator!=(const function<_R2()>&) const;// = delete; 505227825Stheravenpublic: 506227825Stheraven // 20.7.16.2.4, function invocation: 507232924Stheraven _Rp operator()() const; 508227825Stheraven 509227825Stheraven#ifndef _LIBCPP_NO_RTTI 510227825Stheraven // 20.7.16.2.5, function target access: 511227825Stheraven const std::type_info& target_type() const; 512232924Stheraven template <typename _Tp> _Tp* target(); 513232924Stheraven template <typename _Tp> const _Tp* target() const; 514227825Stheraven#endif // _LIBCPP_NO_RTTI 515227825Stheraven}; 516227825Stheraven 517232924Stheraventemplate<class _Rp> 518232924Stheravenfunction<_Rp()>::function(const function& __f) 519227825Stheraven{ 520227825Stheraven if (__f.__f_ == 0) 521227825Stheraven __f_ = 0; 522227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 523227825Stheraven { 524227825Stheraven __f_ = (__base*)&__buf_; 525227825Stheraven __f.__f_->__clone(__f_); 526227825Stheraven } 527227825Stheraven else 528227825Stheraven __f_ = __f.__f_->__clone(); 529227825Stheraven} 530227825Stheraven 531232924Stheraventemplate<class _Rp> 532227825Stheraventemplate<class _Alloc> 533232924Stheravenfunction<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f) 534227825Stheraven{ 535227825Stheraven if (__f.__f_ == 0) 536227825Stheraven __f_ = 0; 537227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 538227825Stheraven { 539227825Stheraven __f_ = (__base*)&__buf_; 540227825Stheraven __f.__f_->__clone(__f_); 541227825Stheraven } 542227825Stheraven else 543227825Stheraven __f_ = __f.__f_->__clone(); 544227825Stheraven} 545227825Stheraven 546232924Stheraventemplate<class _Rp> 547232924Stheraventemplate <class _Fp> 548232924Stheravenfunction<_Rp()>::function(_Fp __f, 549232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type*) 550227825Stheraven : __f_(0) 551227825Stheraven{ 552300770Sdim if (__function::__not_null(__f)) 553227825Stheraven { 554232924Stheraven typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF; 555227825Stheraven if (sizeof(_FF) <= sizeof(__buf_)) 556227825Stheraven { 557227825Stheraven __f_ = (__base*)&__buf_; 558227825Stheraven ::new (__f_) _FF(__f); 559227825Stheraven } 560227825Stheraven else 561227825Stheraven { 562232924Stheraven typedef allocator<_FF> _Ap; 563232924Stheraven _Ap __a; 564232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 565232924Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 566232924Stheraven ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); 567227825Stheraven __f_ = __hold.release(); 568227825Stheraven } 569227825Stheraven } 570227825Stheraven} 571227825Stheraven 572232924Stheraventemplate<class _Rp> 573232924Stheraventemplate <class _Fp, class _Alloc> 574232924Stheravenfunction<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 575232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type*) 576227825Stheraven : __f_(0) 577227825Stheraven{ 578227825Stheraven typedef allocator_traits<_Alloc> __alloc_traits; 579300770Sdim if (__function::__not_null(__f)) 580227825Stheraven { 581232924Stheraven typedef __function::__func<_Fp, _Alloc, _Rp()> _FF; 582227825Stheraven if (sizeof(_FF) <= sizeof(__buf_)) 583227825Stheraven { 584227825Stheraven __f_ = (__base*)&__buf_; 585288943Sdim ::new (__f_) _FF(__f, __a0); 586227825Stheraven } 587227825Stheraven else 588227825Stheraven { 589288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 590232924Stheraven _Ap __a(__a0); 591232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 592232924Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 593227825Stheraven ::new (__hold.get()) _FF(__f, _Alloc(__a)); 594227825Stheraven __f_ = __hold.release(); 595227825Stheraven } 596227825Stheraven } 597227825Stheraven} 598227825Stheraven 599232924Stheraventemplate<class _Rp> 600232924Stheravenfunction<_Rp()>& 601232924Stheravenfunction<_Rp()>::operator=(const function& __f) 602227825Stheraven{ 603227825Stheraven function(__f).swap(*this); 604227825Stheraven return *this; 605227825Stheraven} 606227825Stheraven 607232924Stheraventemplate<class _Rp> 608232924Stheravenfunction<_Rp()>& 609232924Stheravenfunction<_Rp()>::operator=(nullptr_t) 610227825Stheraven{ 611227825Stheraven if (__f_ == (__base*)&__buf_) 612227825Stheraven __f_->destroy(); 613227825Stheraven else if (__f_) 614227825Stheraven __f_->destroy_deallocate(); 615227825Stheraven __f_ = 0; 616288943Sdim return *this; 617227825Stheraven} 618227825Stheraven 619232924Stheraventemplate<class _Rp> 620232924Stheraventemplate <class _Fp> 621227825Stheraventypename enable_if 622227825Stheraven< 623232924Stheraven !is_integral<_Fp>::value, 624232924Stheraven function<_Rp()>& 625227825Stheraven>::type 626232924Stheravenfunction<_Rp()>::operator=(_Fp __f) 627227825Stheraven{ 628227825Stheraven function(_VSTD::move(__f)).swap(*this); 629227825Stheraven return *this; 630227825Stheraven} 631227825Stheraven 632232924Stheraventemplate<class _Rp> 633232924Stheravenfunction<_Rp()>::~function() 634227825Stheraven{ 635227825Stheraven if (__f_ == (__base*)&__buf_) 636227825Stheraven __f_->destroy(); 637227825Stheraven else if (__f_) 638227825Stheraven __f_->destroy_deallocate(); 639227825Stheraven} 640227825Stheraven 641232924Stheraventemplate<class _Rp> 642227825Stheravenvoid 643232924Stheravenfunction<_Rp()>::swap(function& __f) 644227825Stheraven{ 645227825Stheraven if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 646227825Stheraven { 647227825Stheraven typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 648227825Stheraven __base* __t = (__base*)&__tempbuf; 649227825Stheraven __f_->__clone(__t); 650227825Stheraven __f_->destroy(); 651227825Stheraven __f_ = 0; 652227825Stheraven __f.__f_->__clone((__base*)&__buf_); 653227825Stheraven __f.__f_->destroy(); 654227825Stheraven __f.__f_ = 0; 655227825Stheraven __f_ = (__base*)&__buf_; 656227825Stheraven __t->__clone((__base*)&__f.__buf_); 657227825Stheraven __t->destroy(); 658227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 659227825Stheraven } 660227825Stheraven else if (__f_ == (__base*)&__buf_) 661227825Stheraven { 662227825Stheraven __f_->__clone((__base*)&__f.__buf_); 663227825Stheraven __f_->destroy(); 664227825Stheraven __f_ = __f.__f_; 665227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 666227825Stheraven } 667227825Stheraven else if (__f.__f_ == (__base*)&__f.__buf_) 668227825Stheraven { 669227825Stheraven __f.__f_->__clone((__base*)&__buf_); 670227825Stheraven __f.__f_->destroy(); 671227825Stheraven __f.__f_ = __f_; 672227825Stheraven __f_ = (__base*)&__buf_; 673227825Stheraven } 674227825Stheraven else 675227825Stheraven _VSTD::swap(__f_, __f.__f_); 676227825Stheraven} 677227825Stheraven 678232924Stheraventemplate<class _Rp> 679232924Stheraven_Rp 680232924Stheravenfunction<_Rp()>::operator()() const 681227825Stheraven{ 682227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 683227825Stheraven if (__f_ == 0) 684227825Stheraven throw bad_function_call(); 685227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 686227825Stheraven return (*__f_)(); 687227825Stheraven} 688227825Stheraven 689227825Stheraven#ifndef _LIBCPP_NO_RTTI 690227825Stheraven 691232924Stheraventemplate<class _Rp> 692227825Stheravenconst std::type_info& 693232924Stheravenfunction<_Rp()>::target_type() const 694227825Stheraven{ 695227825Stheraven if (__f_ == 0) 696227825Stheraven return typeid(void); 697227825Stheraven return __f_->target_type(); 698227825Stheraven} 699227825Stheraven 700232924Stheraventemplate<class _Rp> 701232924Stheraventemplate <typename _Tp> 702232924Stheraven_Tp* 703232924Stheravenfunction<_Rp()>::target() 704227825Stheraven{ 705227825Stheraven if (__f_ == 0) 706232924Stheraven return (_Tp*)0; 707232924Stheraven return (_Tp*)__f_->target(typeid(_Tp)); 708227825Stheraven} 709227825Stheraven 710232924Stheraventemplate<class _Rp> 711232924Stheraventemplate <typename _Tp> 712232924Stheravenconst _Tp* 713232924Stheravenfunction<_Rp()>::target() const 714227825Stheraven{ 715227825Stheraven if (__f_ == 0) 716232924Stheraven return (const _Tp*)0; 717232924Stheraven return (const _Tp*)__f_->target(typeid(_Tp)); 718227825Stheraven} 719227825Stheraven 720227825Stheraven#endif // _LIBCPP_NO_RTTI 721227825Stheraven 722232924Stheraventemplate<class _Rp, class _A0> 723261272Sdimclass _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)> 724232924Stheraven : public unary_function<_A0, _Rp> 725227825Stheraven{ 726232924Stheraven typedef __function::__base<_Rp(_A0)> __base; 727227825Stheraven aligned_storage<3*sizeof(void*)>::type __buf_; 728227825Stheraven __base* __f_; 729227825Stheraven 730227825Stheravenpublic: 731232924Stheraven typedef _Rp result_type; 732227825Stheraven 733227825Stheraven // 20.7.16.2.1, construct/copy/destroy: 734227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} 735227825Stheraven _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} 736227825Stheraven function(const function&); 737232924Stheraven template<class _Fp> 738232924Stheraven function(_Fp, 739232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type* = 0); 740227825Stheraven 741227825Stheraven template<class _Alloc> 742227825Stheraven _LIBCPP_INLINE_VISIBILITY 743227825Stheraven function(allocator_arg_t, const _Alloc&) : __f_(0) {} 744227825Stheraven template<class _Alloc> 745227825Stheraven _LIBCPP_INLINE_VISIBILITY 746227825Stheraven function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} 747227825Stheraven template<class _Alloc> 748227825Stheraven function(allocator_arg_t, const _Alloc&, const function&); 749232924Stheraven template<class _Fp, class _Alloc> 750232924Stheraven function(allocator_arg_t, const _Alloc& __a, _Fp __f, 751232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type* = 0); 752227825Stheraven 753227825Stheraven function& operator=(const function&); 754227825Stheraven function& operator=(nullptr_t); 755232924Stheraven template<class _Fp> 756227825Stheraven typename enable_if 757227825Stheraven < 758232924Stheraven !is_integral<_Fp>::value, 759227825Stheraven function& 760227825Stheraven >::type 761232924Stheraven operator=(_Fp); 762227825Stheraven 763227825Stheraven ~function(); 764227825Stheraven 765227825Stheraven // 20.7.16.2.2, function modifiers: 766227825Stheraven void swap(function&); 767232924Stheraven template<class _Fp, class _Alloc> 768227825Stheraven _LIBCPP_INLINE_VISIBILITY 769232924Stheraven void assign(_Fp __f, const _Alloc& __a) 770227825Stheraven {function(allocator_arg, __a, __f).swap(*this);} 771227825Stheraven 772227825Stheraven // 20.7.16.2.3, function capacity: 773227825Stheraven _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} 774227825Stheraven 775227825Stheravenprivate: 776227825Stheraven // deleted overloads close possible hole in the type system 777227825Stheraven template<class _R2, class _B0> 778227825Stheraven bool operator==(const function<_R2(_B0)>&) const;// = delete; 779227825Stheraven template<class _R2, class _B0> 780227825Stheraven bool operator!=(const function<_R2(_B0)>&) const;// = delete; 781227825Stheravenpublic: 782227825Stheraven // 20.7.16.2.4, function invocation: 783232924Stheraven _Rp operator()(_A0) const; 784227825Stheraven 785227825Stheraven#ifndef _LIBCPP_NO_RTTI 786227825Stheraven // 20.7.16.2.5, function target access: 787227825Stheraven const std::type_info& target_type() const; 788232924Stheraven template <typename _Tp> _Tp* target(); 789232924Stheraven template <typename _Tp> const _Tp* target() const; 790227825Stheraven#endif // _LIBCPP_NO_RTTI 791227825Stheraven}; 792227825Stheraven 793232924Stheraventemplate<class _Rp, class _A0> 794232924Stheravenfunction<_Rp(_A0)>::function(const function& __f) 795227825Stheraven{ 796227825Stheraven if (__f.__f_ == 0) 797227825Stheraven __f_ = 0; 798227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 799227825Stheraven { 800227825Stheraven __f_ = (__base*)&__buf_; 801227825Stheraven __f.__f_->__clone(__f_); 802227825Stheraven } 803227825Stheraven else 804227825Stheraven __f_ = __f.__f_->__clone(); 805227825Stheraven} 806227825Stheraven 807232924Stheraventemplate<class _Rp, class _A0> 808227825Stheraventemplate<class _Alloc> 809232924Stheravenfunction<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) 810227825Stheraven{ 811227825Stheraven if (__f.__f_ == 0) 812227825Stheraven __f_ = 0; 813227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 814227825Stheraven { 815227825Stheraven __f_ = (__base*)&__buf_; 816227825Stheraven __f.__f_->__clone(__f_); 817227825Stheraven } 818227825Stheraven else 819227825Stheraven __f_ = __f.__f_->__clone(); 820227825Stheraven} 821227825Stheraven 822232924Stheraventemplate<class _Rp, class _A0> 823232924Stheraventemplate <class _Fp> 824232924Stheravenfunction<_Rp(_A0)>::function(_Fp __f, 825232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type*) 826227825Stheraven : __f_(0) 827227825Stheraven{ 828300770Sdim if (__function::__not_null(__f)) 829227825Stheraven { 830232924Stheraven typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; 831227825Stheraven if (sizeof(_FF) <= sizeof(__buf_)) 832227825Stheraven { 833227825Stheraven __f_ = (__base*)&__buf_; 834227825Stheraven ::new (__f_) _FF(__f); 835227825Stheraven } 836227825Stheraven else 837227825Stheraven { 838232924Stheraven typedef allocator<_FF> _Ap; 839232924Stheraven _Ap __a; 840232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 841232924Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 842232924Stheraven ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); 843227825Stheraven __f_ = __hold.release(); 844227825Stheraven } 845227825Stheraven } 846227825Stheraven} 847227825Stheraven 848232924Stheraventemplate<class _Rp, class _A0> 849232924Stheraventemplate <class _Fp, class _Alloc> 850232924Stheravenfunction<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 851232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type*) 852227825Stheraven : __f_(0) 853227825Stheraven{ 854227825Stheraven typedef allocator_traits<_Alloc> __alloc_traits; 855300770Sdim if (__function::__not_null(__f)) 856227825Stheraven { 857232924Stheraven typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; 858227825Stheraven if (sizeof(_FF) <= sizeof(__buf_)) 859227825Stheraven { 860227825Stheraven __f_ = (__base*)&__buf_; 861288943Sdim ::new (__f_) _FF(__f, __a0); 862227825Stheraven } 863227825Stheraven else 864227825Stheraven { 865288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 866232924Stheraven _Ap __a(__a0); 867232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 868232924Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 869227825Stheraven ::new (__hold.get()) _FF(__f, _Alloc(__a)); 870227825Stheraven __f_ = __hold.release(); 871227825Stheraven } 872227825Stheraven } 873227825Stheraven} 874227825Stheraven 875232924Stheraventemplate<class _Rp, class _A0> 876232924Stheravenfunction<_Rp(_A0)>& 877232924Stheravenfunction<_Rp(_A0)>::operator=(const function& __f) 878227825Stheraven{ 879227825Stheraven function(__f).swap(*this); 880227825Stheraven return *this; 881227825Stheraven} 882227825Stheraven 883232924Stheraventemplate<class _Rp, class _A0> 884232924Stheravenfunction<_Rp(_A0)>& 885232924Stheravenfunction<_Rp(_A0)>::operator=(nullptr_t) 886227825Stheraven{ 887227825Stheraven if (__f_ == (__base*)&__buf_) 888227825Stheraven __f_->destroy(); 889227825Stheraven else if (__f_) 890227825Stheraven __f_->destroy_deallocate(); 891227825Stheraven __f_ = 0; 892288943Sdim return *this; 893227825Stheraven} 894227825Stheraven 895232924Stheraventemplate<class _Rp, class _A0> 896232924Stheraventemplate <class _Fp> 897227825Stheraventypename enable_if 898227825Stheraven< 899232924Stheraven !is_integral<_Fp>::value, 900232924Stheraven function<_Rp(_A0)>& 901227825Stheraven>::type 902232924Stheravenfunction<_Rp(_A0)>::operator=(_Fp __f) 903227825Stheraven{ 904227825Stheraven function(_VSTD::move(__f)).swap(*this); 905227825Stheraven return *this; 906227825Stheraven} 907227825Stheraven 908232924Stheraventemplate<class _Rp, class _A0> 909232924Stheravenfunction<_Rp(_A0)>::~function() 910227825Stheraven{ 911227825Stheraven if (__f_ == (__base*)&__buf_) 912227825Stheraven __f_->destroy(); 913227825Stheraven else if (__f_) 914227825Stheraven __f_->destroy_deallocate(); 915227825Stheraven} 916227825Stheraven 917232924Stheraventemplate<class _Rp, class _A0> 918227825Stheravenvoid 919232924Stheravenfunction<_Rp(_A0)>::swap(function& __f) 920227825Stheraven{ 921227825Stheraven if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 922227825Stheraven { 923227825Stheraven typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 924227825Stheraven __base* __t = (__base*)&__tempbuf; 925227825Stheraven __f_->__clone(__t); 926227825Stheraven __f_->destroy(); 927227825Stheraven __f_ = 0; 928227825Stheraven __f.__f_->__clone((__base*)&__buf_); 929227825Stheraven __f.__f_->destroy(); 930227825Stheraven __f.__f_ = 0; 931227825Stheraven __f_ = (__base*)&__buf_; 932227825Stheraven __t->__clone((__base*)&__f.__buf_); 933227825Stheraven __t->destroy(); 934227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 935227825Stheraven } 936227825Stheraven else if (__f_ == (__base*)&__buf_) 937227825Stheraven { 938227825Stheraven __f_->__clone((__base*)&__f.__buf_); 939227825Stheraven __f_->destroy(); 940227825Stheraven __f_ = __f.__f_; 941227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 942227825Stheraven } 943227825Stheraven else if (__f.__f_ == (__base*)&__f.__buf_) 944227825Stheraven { 945227825Stheraven __f.__f_->__clone((__base*)&__buf_); 946227825Stheraven __f.__f_->destroy(); 947227825Stheraven __f.__f_ = __f_; 948227825Stheraven __f_ = (__base*)&__buf_; 949227825Stheraven } 950227825Stheraven else 951227825Stheraven _VSTD::swap(__f_, __f.__f_); 952227825Stheraven} 953227825Stheraven 954232924Stheraventemplate<class _Rp, class _A0> 955232924Stheraven_Rp 956232924Stheravenfunction<_Rp(_A0)>::operator()(_A0 __a0) const 957227825Stheraven{ 958227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 959227825Stheraven if (__f_ == 0) 960227825Stheraven throw bad_function_call(); 961227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 962227825Stheraven return (*__f_)(__a0); 963227825Stheraven} 964227825Stheraven 965227825Stheraven#ifndef _LIBCPP_NO_RTTI 966227825Stheraven 967232924Stheraventemplate<class _Rp, class _A0> 968227825Stheravenconst std::type_info& 969232924Stheravenfunction<_Rp(_A0)>::target_type() const 970227825Stheraven{ 971227825Stheraven if (__f_ == 0) 972227825Stheraven return typeid(void); 973227825Stheraven return __f_->target_type(); 974227825Stheraven} 975227825Stheraven 976232924Stheraventemplate<class _Rp, class _A0> 977232924Stheraventemplate <typename _Tp> 978232924Stheraven_Tp* 979232924Stheravenfunction<_Rp(_A0)>::target() 980227825Stheraven{ 981227825Stheraven if (__f_ == 0) 982232924Stheraven return (_Tp*)0; 983232924Stheraven return (_Tp*)__f_->target(typeid(_Tp)); 984227825Stheraven} 985227825Stheraven 986232924Stheraventemplate<class _Rp, class _A0> 987232924Stheraventemplate <typename _Tp> 988232924Stheravenconst _Tp* 989232924Stheravenfunction<_Rp(_A0)>::target() const 990227825Stheraven{ 991227825Stheraven if (__f_ == 0) 992232924Stheraven return (const _Tp*)0; 993232924Stheraven return (const _Tp*)__f_->target(typeid(_Tp)); 994227825Stheraven} 995227825Stheraven 996227825Stheraven#endif // _LIBCPP_NO_RTTI 997227825Stheraven 998232924Stheraventemplate<class _Rp, class _A0, class _A1> 999261272Sdimclass _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)> 1000232924Stheraven : public binary_function<_A0, _A1, _Rp> 1001227825Stheraven{ 1002232924Stheraven typedef __function::__base<_Rp(_A0, _A1)> __base; 1003227825Stheraven aligned_storage<3*sizeof(void*)>::type __buf_; 1004227825Stheraven __base* __f_; 1005227825Stheraven 1006227825Stheravenpublic: 1007232924Stheraven typedef _Rp result_type; 1008227825Stheraven 1009227825Stheraven // 20.7.16.2.1, construct/copy/destroy: 1010227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} 1011227825Stheraven _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} 1012227825Stheraven function(const function&); 1013232924Stheraven template<class _Fp> 1014232924Stheraven function(_Fp, 1015232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type* = 0); 1016227825Stheraven 1017227825Stheraven template<class _Alloc> 1018227825Stheraven _LIBCPP_INLINE_VISIBILITY 1019227825Stheraven function(allocator_arg_t, const _Alloc&) : __f_(0) {} 1020227825Stheraven template<class _Alloc> 1021227825Stheraven _LIBCPP_INLINE_VISIBILITY 1022227825Stheraven function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} 1023227825Stheraven template<class _Alloc> 1024227825Stheraven function(allocator_arg_t, const _Alloc&, const function&); 1025232924Stheraven template<class _Fp, class _Alloc> 1026232924Stheraven function(allocator_arg_t, const _Alloc& __a, _Fp __f, 1027232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type* = 0); 1028227825Stheraven 1029227825Stheraven function& operator=(const function&); 1030227825Stheraven function& operator=(nullptr_t); 1031232924Stheraven template<class _Fp> 1032227825Stheraven typename enable_if 1033227825Stheraven < 1034232924Stheraven !is_integral<_Fp>::value, 1035227825Stheraven function& 1036227825Stheraven >::type 1037232924Stheraven operator=(_Fp); 1038227825Stheraven 1039227825Stheraven ~function(); 1040227825Stheraven 1041227825Stheraven // 20.7.16.2.2, function modifiers: 1042227825Stheraven void swap(function&); 1043232924Stheraven template<class _Fp, class _Alloc> 1044227825Stheraven _LIBCPP_INLINE_VISIBILITY 1045232924Stheraven void assign(_Fp __f, const _Alloc& __a) 1046227825Stheraven {function(allocator_arg, __a, __f).swap(*this);} 1047227825Stheraven 1048227825Stheraven // 20.7.16.2.3, function capacity: 1049227825Stheraven operator bool() const {return __f_;} 1050227825Stheraven 1051227825Stheravenprivate: 1052227825Stheraven // deleted overloads close possible hole in the type system 1053227825Stheraven template<class _R2, class _B0, class _B1> 1054227825Stheraven bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete; 1055227825Stheraven template<class _R2, class _B0, class _B1> 1056227825Stheraven bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete; 1057227825Stheravenpublic: 1058227825Stheraven // 20.7.16.2.4, function invocation: 1059232924Stheraven _Rp operator()(_A0, _A1) const; 1060227825Stheraven 1061227825Stheraven#ifndef _LIBCPP_NO_RTTI 1062227825Stheraven // 20.7.16.2.5, function target access: 1063227825Stheraven const std::type_info& target_type() const; 1064232924Stheraven template <typename _Tp> _Tp* target(); 1065232924Stheraven template <typename _Tp> const _Tp* target() const; 1066227825Stheraven#endif // _LIBCPP_NO_RTTI 1067227825Stheraven}; 1068227825Stheraven 1069232924Stheraventemplate<class _Rp, class _A0, class _A1> 1070232924Stheravenfunction<_Rp(_A0, _A1)>::function(const function& __f) 1071227825Stheraven{ 1072227825Stheraven if (__f.__f_ == 0) 1073227825Stheraven __f_ = 0; 1074227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 1075227825Stheraven { 1076227825Stheraven __f_ = (__base*)&__buf_; 1077227825Stheraven __f.__f_->__clone(__f_); 1078227825Stheraven } 1079227825Stheraven else 1080227825Stheraven __f_ = __f.__f_->__clone(); 1081227825Stheraven} 1082227825Stheraven 1083232924Stheraventemplate<class _Rp, class _A0, class _A1> 1084227825Stheraventemplate<class _Alloc> 1085232924Stheravenfunction<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f) 1086227825Stheraven{ 1087227825Stheraven if (__f.__f_ == 0) 1088227825Stheraven __f_ = 0; 1089227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 1090227825Stheraven { 1091227825Stheraven __f_ = (__base*)&__buf_; 1092227825Stheraven __f.__f_->__clone(__f_); 1093227825Stheraven } 1094227825Stheraven else 1095227825Stheraven __f_ = __f.__f_->__clone(); 1096227825Stheraven} 1097227825Stheraven 1098232924Stheraventemplate<class _Rp, class _A0, class _A1> 1099232924Stheraventemplate <class _Fp> 1100232924Stheravenfunction<_Rp(_A0, _A1)>::function(_Fp __f, 1101232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type*) 1102227825Stheraven : __f_(0) 1103227825Stheraven{ 1104300770Sdim if (__function::__not_null(__f)) 1105227825Stheraven { 1106232924Stheraven typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; 1107227825Stheraven if (sizeof(_FF) <= sizeof(__buf_)) 1108227825Stheraven { 1109227825Stheraven __f_ = (__base*)&__buf_; 1110227825Stheraven ::new (__f_) _FF(__f); 1111227825Stheraven } 1112227825Stheraven else 1113227825Stheraven { 1114232924Stheraven typedef allocator<_FF> _Ap; 1115232924Stheraven _Ap __a; 1116232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 1117232924Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1118232924Stheraven ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); 1119227825Stheraven __f_ = __hold.release(); 1120227825Stheraven } 1121227825Stheraven } 1122227825Stheraven} 1123227825Stheraven 1124232924Stheraventemplate<class _Rp, class _A0, class _A1> 1125232924Stheraventemplate <class _Fp, class _Alloc> 1126232924Stheravenfunction<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 1127232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type*) 1128227825Stheraven : __f_(0) 1129227825Stheraven{ 1130227825Stheraven typedef allocator_traits<_Alloc> __alloc_traits; 1131300770Sdim if (__function::__not_null(__f)) 1132227825Stheraven { 1133232924Stheraven typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; 1134227825Stheraven if (sizeof(_FF) <= sizeof(__buf_)) 1135227825Stheraven { 1136227825Stheraven __f_ = (__base*)&__buf_; 1137288943Sdim ::new (__f_) _FF(__f, __a0); 1138227825Stheraven } 1139227825Stheraven else 1140227825Stheraven { 1141288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 1142232924Stheraven _Ap __a(__a0); 1143232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 1144232924Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1145227825Stheraven ::new (__hold.get()) _FF(__f, _Alloc(__a)); 1146227825Stheraven __f_ = __hold.release(); 1147227825Stheraven } 1148227825Stheraven } 1149227825Stheraven} 1150227825Stheraven 1151232924Stheraventemplate<class _Rp, class _A0, class _A1> 1152232924Stheravenfunction<_Rp(_A0, _A1)>& 1153232924Stheravenfunction<_Rp(_A0, _A1)>::operator=(const function& __f) 1154227825Stheraven{ 1155227825Stheraven function(__f).swap(*this); 1156227825Stheraven return *this; 1157227825Stheraven} 1158227825Stheraven 1159232924Stheraventemplate<class _Rp, class _A0, class _A1> 1160232924Stheravenfunction<_Rp(_A0, _A1)>& 1161232924Stheravenfunction<_Rp(_A0, _A1)>::operator=(nullptr_t) 1162227825Stheraven{ 1163227825Stheraven if (__f_ == (__base*)&__buf_) 1164227825Stheraven __f_->destroy(); 1165227825Stheraven else if (__f_) 1166227825Stheraven __f_->destroy_deallocate(); 1167227825Stheraven __f_ = 0; 1168288943Sdim return *this; 1169227825Stheraven} 1170227825Stheraven 1171232924Stheraventemplate<class _Rp, class _A0, class _A1> 1172232924Stheraventemplate <class _Fp> 1173227825Stheraventypename enable_if 1174227825Stheraven< 1175232924Stheraven !is_integral<_Fp>::value, 1176232924Stheraven function<_Rp(_A0, _A1)>& 1177227825Stheraven>::type 1178232924Stheravenfunction<_Rp(_A0, _A1)>::operator=(_Fp __f) 1179227825Stheraven{ 1180227825Stheraven function(_VSTD::move(__f)).swap(*this); 1181227825Stheraven return *this; 1182227825Stheraven} 1183227825Stheraven 1184232924Stheraventemplate<class _Rp, class _A0, class _A1> 1185232924Stheravenfunction<_Rp(_A0, _A1)>::~function() 1186227825Stheraven{ 1187227825Stheraven if (__f_ == (__base*)&__buf_) 1188227825Stheraven __f_->destroy(); 1189227825Stheraven else if (__f_) 1190227825Stheraven __f_->destroy_deallocate(); 1191227825Stheraven} 1192227825Stheraven 1193232924Stheraventemplate<class _Rp, class _A0, class _A1> 1194227825Stheravenvoid 1195232924Stheravenfunction<_Rp(_A0, _A1)>::swap(function& __f) 1196227825Stheraven{ 1197227825Stheraven if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 1198227825Stheraven { 1199227825Stheraven typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 1200227825Stheraven __base* __t = (__base*)&__tempbuf; 1201227825Stheraven __f_->__clone(__t); 1202227825Stheraven __f_->destroy(); 1203227825Stheraven __f_ = 0; 1204227825Stheraven __f.__f_->__clone((__base*)&__buf_); 1205227825Stheraven __f.__f_->destroy(); 1206227825Stheraven __f.__f_ = 0; 1207227825Stheraven __f_ = (__base*)&__buf_; 1208227825Stheraven __t->__clone((__base*)&__f.__buf_); 1209227825Stheraven __t->destroy(); 1210227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 1211227825Stheraven } 1212227825Stheraven else if (__f_ == (__base*)&__buf_) 1213227825Stheraven { 1214227825Stheraven __f_->__clone((__base*)&__f.__buf_); 1215227825Stheraven __f_->destroy(); 1216227825Stheraven __f_ = __f.__f_; 1217227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 1218227825Stheraven } 1219227825Stheraven else if (__f.__f_ == (__base*)&__f.__buf_) 1220227825Stheraven { 1221227825Stheraven __f.__f_->__clone((__base*)&__buf_); 1222227825Stheraven __f.__f_->destroy(); 1223227825Stheraven __f.__f_ = __f_; 1224227825Stheraven __f_ = (__base*)&__buf_; 1225227825Stheraven } 1226227825Stheraven else 1227227825Stheraven _VSTD::swap(__f_, __f.__f_); 1228227825Stheraven} 1229227825Stheraven 1230232924Stheraventemplate<class _Rp, class _A0, class _A1> 1231232924Stheraven_Rp 1232232924Stheravenfunction<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const 1233227825Stheraven{ 1234227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 1235227825Stheraven if (__f_ == 0) 1236227825Stheraven throw bad_function_call(); 1237227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 1238227825Stheraven return (*__f_)(__a0, __a1); 1239227825Stheraven} 1240227825Stheraven 1241227825Stheraven#ifndef _LIBCPP_NO_RTTI 1242227825Stheraven 1243232924Stheraventemplate<class _Rp, class _A0, class _A1> 1244227825Stheravenconst std::type_info& 1245232924Stheravenfunction<_Rp(_A0, _A1)>::target_type() const 1246227825Stheraven{ 1247227825Stheraven if (__f_ == 0) 1248227825Stheraven return typeid(void); 1249227825Stheraven return __f_->target_type(); 1250227825Stheraven} 1251227825Stheraven 1252232924Stheraventemplate<class _Rp, class _A0, class _A1> 1253232924Stheraventemplate <typename _Tp> 1254232924Stheraven_Tp* 1255232924Stheravenfunction<_Rp(_A0, _A1)>::target() 1256227825Stheraven{ 1257227825Stheraven if (__f_ == 0) 1258232924Stheraven return (_Tp*)0; 1259232924Stheraven return (_Tp*)__f_->target(typeid(_Tp)); 1260227825Stheraven} 1261227825Stheraven 1262232924Stheraventemplate<class _Rp, class _A0, class _A1> 1263232924Stheraventemplate <typename _Tp> 1264232924Stheravenconst _Tp* 1265232924Stheravenfunction<_Rp(_A0, _A1)>::target() const 1266227825Stheraven{ 1267227825Stheraven if (__f_ == 0) 1268232924Stheraven return (const _Tp*)0; 1269232924Stheraven return (const _Tp*)__f_->target(typeid(_Tp)); 1270227825Stheraven} 1271227825Stheraven 1272227825Stheraven#endif // _LIBCPP_NO_RTTI 1273227825Stheraven 1274232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1275261272Sdimclass _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)> 1276227825Stheraven{ 1277232924Stheraven typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; 1278227825Stheraven aligned_storage<3*sizeof(void*)>::type __buf_; 1279227825Stheraven __base* __f_; 1280227825Stheraven 1281227825Stheravenpublic: 1282232924Stheraven typedef _Rp result_type; 1283227825Stheraven 1284227825Stheraven // 20.7.16.2.1, construct/copy/destroy: 1285227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} 1286227825Stheraven _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} 1287227825Stheraven function(const function&); 1288232924Stheraven template<class _Fp> 1289232924Stheraven function(_Fp, 1290232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type* = 0); 1291227825Stheraven 1292227825Stheraven template<class _Alloc> 1293227825Stheraven _LIBCPP_INLINE_VISIBILITY 1294227825Stheraven function(allocator_arg_t, const _Alloc&) : __f_(0) {} 1295227825Stheraven template<class _Alloc> 1296227825Stheraven _LIBCPP_INLINE_VISIBILITY 1297227825Stheraven function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} 1298227825Stheraven template<class _Alloc> 1299227825Stheraven function(allocator_arg_t, const _Alloc&, const function&); 1300232924Stheraven template<class _Fp, class _Alloc> 1301232924Stheraven function(allocator_arg_t, const _Alloc& __a, _Fp __f, 1302232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type* = 0); 1303227825Stheraven 1304227825Stheraven function& operator=(const function&); 1305227825Stheraven function& operator=(nullptr_t); 1306232924Stheraven template<class _Fp> 1307227825Stheraven typename enable_if 1308227825Stheraven < 1309232924Stheraven !is_integral<_Fp>::value, 1310227825Stheraven function& 1311227825Stheraven >::type 1312232924Stheraven operator=(_Fp); 1313227825Stheraven 1314227825Stheraven ~function(); 1315227825Stheraven 1316227825Stheraven // 20.7.16.2.2, function modifiers: 1317227825Stheraven void swap(function&); 1318232924Stheraven template<class _Fp, class _Alloc> 1319227825Stheraven _LIBCPP_INLINE_VISIBILITY 1320232924Stheraven void assign(_Fp __f, const _Alloc& __a) 1321227825Stheraven {function(allocator_arg, __a, __f).swap(*this);} 1322227825Stheraven 1323227825Stheraven // 20.7.16.2.3, function capacity: 1324227825Stheraven _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} 1325227825Stheraven 1326227825Stheravenprivate: 1327227825Stheraven // deleted overloads close possible hole in the type system 1328227825Stheraven template<class _R2, class _B0, class _B1, class _B2> 1329227825Stheraven bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; 1330227825Stheraven template<class _R2, class _B0, class _B1, class _B2> 1331227825Stheraven bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; 1332227825Stheravenpublic: 1333227825Stheraven // 20.7.16.2.4, function invocation: 1334232924Stheraven _Rp operator()(_A0, _A1, _A2) const; 1335227825Stheraven 1336227825Stheraven#ifndef _LIBCPP_NO_RTTI 1337227825Stheraven // 20.7.16.2.5, function target access: 1338227825Stheraven const std::type_info& target_type() const; 1339232924Stheraven template <typename _Tp> _Tp* target(); 1340232924Stheraven template <typename _Tp> const _Tp* target() const; 1341227825Stheraven#endif // _LIBCPP_NO_RTTI 1342227825Stheraven}; 1343227825Stheraven 1344232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1345232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::function(const function& __f) 1346227825Stheraven{ 1347227825Stheraven if (__f.__f_ == 0) 1348227825Stheraven __f_ = 0; 1349227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 1350227825Stheraven { 1351227825Stheraven __f_ = (__base*)&__buf_; 1352227825Stheraven __f.__f_->__clone(__f_); 1353227825Stheraven } 1354227825Stheraven else 1355227825Stheraven __f_ = __f.__f_->__clone(); 1356227825Stheraven} 1357227825Stheraven 1358232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1359227825Stheraventemplate<class _Alloc> 1360232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, 1361227825Stheraven const function& __f) 1362227825Stheraven{ 1363227825Stheraven if (__f.__f_ == 0) 1364227825Stheraven __f_ = 0; 1365227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 1366227825Stheraven { 1367227825Stheraven __f_ = (__base*)&__buf_; 1368227825Stheraven __f.__f_->__clone(__f_); 1369227825Stheraven } 1370227825Stheraven else 1371227825Stheraven __f_ = __f.__f_->__clone(); 1372227825Stheraven} 1373227825Stheraven 1374232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1375232924Stheraventemplate <class _Fp> 1376232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::function(_Fp __f, 1377232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type*) 1378227825Stheraven : __f_(0) 1379227825Stheraven{ 1380300770Sdim if (__function::__not_null(__f)) 1381227825Stheraven { 1382232924Stheraven typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; 1383227825Stheraven if (sizeof(_FF) <= sizeof(__buf_)) 1384227825Stheraven { 1385227825Stheraven __f_ = (__base*)&__buf_; 1386227825Stheraven ::new (__f_) _FF(__f); 1387227825Stheraven } 1388227825Stheraven else 1389227825Stheraven { 1390232924Stheraven typedef allocator<_FF> _Ap; 1391232924Stheraven _Ap __a; 1392232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 1393232924Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1394232924Stheraven ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); 1395227825Stheraven __f_ = __hold.release(); 1396227825Stheraven } 1397227825Stheraven } 1398227825Stheraven} 1399227825Stheraven 1400232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1401232924Stheraventemplate <class _Fp, class _Alloc> 1402232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 1403232924Stheraven typename enable_if<!is_integral<_Fp>::value>::type*) 1404227825Stheraven : __f_(0) 1405227825Stheraven{ 1406227825Stheraven typedef allocator_traits<_Alloc> __alloc_traits; 1407300770Sdim if (__function::__not_null(__f)) 1408227825Stheraven { 1409232924Stheraven typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; 1410227825Stheraven if (sizeof(_FF) <= sizeof(__buf_)) 1411227825Stheraven { 1412227825Stheraven __f_ = (__base*)&__buf_; 1413288943Sdim ::new (__f_) _FF(__f, __a0); 1414227825Stheraven } 1415227825Stheraven else 1416227825Stheraven { 1417288943Sdim typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 1418232924Stheraven _Ap __a(__a0); 1419232924Stheraven typedef __allocator_destructor<_Ap> _Dp; 1420232924Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1421227825Stheraven ::new (__hold.get()) _FF(__f, _Alloc(__a)); 1422227825Stheraven __f_ = __hold.release(); 1423227825Stheraven } 1424227825Stheraven } 1425227825Stheraven} 1426227825Stheraven 1427232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1428232924Stheravenfunction<_Rp(_A0, _A1, _A2)>& 1429232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::operator=(const function& __f) 1430227825Stheraven{ 1431227825Stheraven function(__f).swap(*this); 1432227825Stheraven return *this; 1433227825Stheraven} 1434227825Stheraven 1435232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1436232924Stheravenfunction<_Rp(_A0, _A1, _A2)>& 1437232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t) 1438227825Stheraven{ 1439227825Stheraven if (__f_ == (__base*)&__buf_) 1440227825Stheraven __f_->destroy(); 1441227825Stheraven else if (__f_) 1442227825Stheraven __f_->destroy_deallocate(); 1443227825Stheraven __f_ = 0; 1444288943Sdim return *this; 1445227825Stheraven} 1446227825Stheraven 1447232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1448232924Stheraventemplate <class _Fp> 1449227825Stheraventypename enable_if 1450227825Stheraven< 1451232924Stheraven !is_integral<_Fp>::value, 1452232924Stheraven function<_Rp(_A0, _A1, _A2)>& 1453227825Stheraven>::type 1454232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) 1455227825Stheraven{ 1456227825Stheraven function(_VSTD::move(__f)).swap(*this); 1457227825Stheraven return *this; 1458227825Stheraven} 1459227825Stheraven 1460232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1461232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::~function() 1462227825Stheraven{ 1463227825Stheraven if (__f_ == (__base*)&__buf_) 1464227825Stheraven __f_->destroy(); 1465227825Stheraven else if (__f_) 1466227825Stheraven __f_->destroy_deallocate(); 1467227825Stheraven} 1468227825Stheraven 1469232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1470227825Stheravenvoid 1471232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::swap(function& __f) 1472227825Stheraven{ 1473227825Stheraven if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 1474227825Stheraven { 1475227825Stheraven typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 1476227825Stheraven __base* __t = (__base*)&__tempbuf; 1477227825Stheraven __f_->__clone(__t); 1478227825Stheraven __f_->destroy(); 1479227825Stheraven __f_ = 0; 1480227825Stheraven __f.__f_->__clone((__base*)&__buf_); 1481227825Stheraven __f.__f_->destroy(); 1482227825Stheraven __f.__f_ = 0; 1483227825Stheraven __f_ = (__base*)&__buf_; 1484227825Stheraven __t->__clone((__base*)&__f.__buf_); 1485227825Stheraven __t->destroy(); 1486227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 1487227825Stheraven } 1488227825Stheraven else if (__f_ == (__base*)&__buf_) 1489227825Stheraven { 1490227825Stheraven __f_->__clone((__base*)&__f.__buf_); 1491227825Stheraven __f_->destroy(); 1492227825Stheraven __f_ = __f.__f_; 1493227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 1494227825Stheraven } 1495227825Stheraven else if (__f.__f_ == (__base*)&__f.__buf_) 1496227825Stheraven { 1497227825Stheraven __f.__f_->__clone((__base*)&__buf_); 1498227825Stheraven __f.__f_->destroy(); 1499227825Stheraven __f.__f_ = __f_; 1500227825Stheraven __f_ = (__base*)&__buf_; 1501227825Stheraven } 1502227825Stheraven else 1503227825Stheraven _VSTD::swap(__f_, __f.__f_); 1504227825Stheraven} 1505227825Stheraven 1506232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1507232924Stheraven_Rp 1508232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const 1509227825Stheraven{ 1510227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 1511227825Stheraven if (__f_ == 0) 1512227825Stheraven throw bad_function_call(); 1513227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 1514227825Stheraven return (*__f_)(__a0, __a1, __a2); 1515227825Stheraven} 1516227825Stheraven 1517227825Stheraven#ifndef _LIBCPP_NO_RTTI 1518227825Stheraven 1519232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1520227825Stheravenconst std::type_info& 1521232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::target_type() const 1522227825Stheraven{ 1523227825Stheraven if (__f_ == 0) 1524227825Stheraven return typeid(void); 1525227825Stheraven return __f_->target_type(); 1526227825Stheraven} 1527227825Stheraven 1528232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1529232924Stheraventemplate <typename _Tp> 1530232924Stheraven_Tp* 1531232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::target() 1532227825Stheraven{ 1533227825Stheraven if (__f_ == 0) 1534232924Stheraven return (_Tp*)0; 1535232924Stheraven return (_Tp*)__f_->target(typeid(_Tp)); 1536227825Stheraven} 1537227825Stheraven 1538232924Stheraventemplate<class _Rp, class _A0, class _A1, class _A2> 1539232924Stheraventemplate <typename _Tp> 1540232924Stheravenconst _Tp* 1541232924Stheravenfunction<_Rp(_A0, _A1, _A2)>::target() const 1542227825Stheraven{ 1543227825Stheraven if (__f_ == 0) 1544232924Stheraven return (const _Tp*)0; 1545232924Stheraven return (const _Tp*)__f_->target(typeid(_Tp)); 1546227825Stheraven} 1547227825Stheraven 1548227825Stheraven#endif // _LIBCPP_NO_RTTI 1549227825Stheraven 1550232924Stheraventemplate <class _Fp> 1551227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1552227825Stheravenbool 1553232924Stheravenoperator==(const function<_Fp>& __f, nullptr_t) {return !__f;} 1554227825Stheraven 1555232924Stheraventemplate <class _Fp> 1556227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1557227825Stheravenbool 1558232924Stheravenoperator==(nullptr_t, const function<_Fp>& __f) {return !__f;} 1559227825Stheraven 1560232924Stheraventemplate <class _Fp> 1561227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1562227825Stheravenbool 1563232924Stheravenoperator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} 1564227825Stheraven 1565232924Stheraventemplate <class _Fp> 1566227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1567227825Stheravenbool 1568232924Stheravenoperator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} 1569227825Stheraven 1570232924Stheraventemplate <class _Fp> 1571227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1572227825Stheravenvoid 1573232924Stheravenswap(function<_Fp>& __x, function<_Fp>& __y) 1574227825Stheraven{return __x.swap(__y);} 1575227825Stheraven 1576227825Stheraven#endif // _LIBCPP_FUNCTIONAL_03 1577