14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_FUNCTIONAL_03 124684ddb6SLionel Sambuc#define _LIBCPP_FUNCTIONAL_03 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc// manual variadic expansion for <functional> 154684ddb6SLionel Sambuc 164684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 174684ddb6SLionel Sambuc#pragma GCC system_header 184684ddb6SLionel Sambuc#endif 194684ddb6SLionel Sambuc 20*0a6a1f1dSLionel Sambucnamespace __function { 214684ddb6SLionel Sambuc 224684ddb6SLionel Sambuctemplate<class _Fp> class __base; 234684ddb6SLionel Sambuc 244684ddb6SLionel Sambuctemplate<class _Rp> 254684ddb6SLionel Sambucclass __base<_Rp()> 264684ddb6SLionel Sambuc{ 274684ddb6SLionel Sambuc __base(const __base&); 284684ddb6SLionel Sambuc __base& operator=(const __base&); 294684ddb6SLionel Sambucpublic: 304684ddb6SLionel Sambuc __base() {} 314684ddb6SLionel Sambuc virtual ~__base() {} 324684ddb6SLionel Sambuc virtual __base* __clone() const = 0; 334684ddb6SLionel Sambuc virtual void __clone(__base*) const = 0; 344684ddb6SLionel Sambuc virtual void destroy() = 0; 354684ddb6SLionel Sambuc virtual void destroy_deallocate() = 0; 364684ddb6SLionel Sambuc virtual _Rp operator()() = 0; 374684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 384684ddb6SLionel Sambuc virtual const void* target(const type_info&) const = 0; 394684ddb6SLionel Sambuc virtual const std::type_info& target_type() const = 0; 404684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 414684ddb6SLionel Sambuc}; 424684ddb6SLionel Sambuc 434684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 444684ddb6SLionel Sambucclass __base<_Rp(_A0)> 454684ddb6SLionel Sambuc{ 464684ddb6SLionel Sambuc __base(const __base&); 474684ddb6SLionel Sambuc __base& operator=(const __base&); 484684ddb6SLionel Sambucpublic: 494684ddb6SLionel Sambuc __base() {} 504684ddb6SLionel Sambuc virtual ~__base() {} 514684ddb6SLionel Sambuc virtual __base* __clone() const = 0; 524684ddb6SLionel Sambuc virtual void __clone(__base*) const = 0; 534684ddb6SLionel Sambuc virtual void destroy() = 0; 544684ddb6SLionel Sambuc virtual void destroy_deallocate() = 0; 554684ddb6SLionel Sambuc virtual _Rp operator()(_A0) = 0; 564684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 574684ddb6SLionel Sambuc virtual const void* target(const type_info&) const = 0; 584684ddb6SLionel Sambuc virtual const std::type_info& target_type() const = 0; 594684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 604684ddb6SLionel Sambuc}; 614684ddb6SLionel Sambuc 624684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 634684ddb6SLionel Sambucclass __base<_Rp(_A0, _A1)> 644684ddb6SLionel Sambuc{ 654684ddb6SLionel Sambuc __base(const __base&); 664684ddb6SLionel Sambuc __base& operator=(const __base&); 674684ddb6SLionel Sambucpublic: 684684ddb6SLionel Sambuc __base() {} 694684ddb6SLionel Sambuc virtual ~__base() {} 704684ddb6SLionel Sambuc virtual __base* __clone() const = 0; 714684ddb6SLionel Sambuc virtual void __clone(__base*) const = 0; 724684ddb6SLionel Sambuc virtual void destroy() = 0; 734684ddb6SLionel Sambuc virtual void destroy_deallocate() = 0; 744684ddb6SLionel Sambuc virtual _Rp operator()(_A0, _A1) = 0; 754684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 764684ddb6SLionel Sambuc virtual const void* target(const type_info&) const = 0; 774684ddb6SLionel Sambuc virtual const std::type_info& target_type() const = 0; 784684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 794684ddb6SLionel Sambuc}; 804684ddb6SLionel Sambuc 814684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 824684ddb6SLionel Sambucclass __base<_Rp(_A0, _A1, _A2)> 834684ddb6SLionel Sambuc{ 844684ddb6SLionel Sambuc __base(const __base&); 854684ddb6SLionel Sambuc __base& operator=(const __base&); 864684ddb6SLionel Sambucpublic: 874684ddb6SLionel Sambuc __base() {} 884684ddb6SLionel Sambuc virtual ~__base() {} 894684ddb6SLionel Sambuc virtual __base* __clone() const = 0; 904684ddb6SLionel Sambuc virtual void __clone(__base*) const = 0; 914684ddb6SLionel Sambuc virtual void destroy() = 0; 924684ddb6SLionel Sambuc virtual void destroy_deallocate() = 0; 934684ddb6SLionel Sambuc virtual _Rp operator()(_A0, _A1, _A2) = 0; 944684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 954684ddb6SLionel Sambuc virtual const void* target(const type_info&) const = 0; 964684ddb6SLionel Sambuc virtual const std::type_info& target_type() const = 0; 974684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 984684ddb6SLionel Sambuc}; 994684ddb6SLionel Sambuc 1004684ddb6SLionel Sambuctemplate<class _FD, class _Alloc, class _FB> class __func; 1014684ddb6SLionel Sambuc 1024684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp> 1034684ddb6SLionel Sambucclass __func<_Fp, _Alloc, _Rp()> 1044684ddb6SLionel Sambuc : public __base<_Rp()> 1054684ddb6SLionel Sambuc{ 1064684ddb6SLionel Sambuc __compressed_pair<_Fp, _Alloc> __f_; 1074684ddb6SLionel Sambucpublic: 1084684ddb6SLionel Sambuc explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} 1094684ddb6SLionel Sambuc explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 1104684ddb6SLionel Sambuc virtual __base<_Rp()>* __clone() const; 1114684ddb6SLionel Sambuc virtual void __clone(__base<_Rp()>*) const; 1124684ddb6SLionel Sambuc virtual void destroy(); 1134684ddb6SLionel Sambuc virtual void destroy_deallocate(); 1144684ddb6SLionel Sambuc virtual _Rp operator()(); 1154684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 1164684ddb6SLionel Sambuc virtual const void* target(const type_info&) const; 1174684ddb6SLionel Sambuc virtual const std::type_info& target_type() const; 1184684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 1194684ddb6SLionel Sambuc}; 1204684ddb6SLionel Sambuc 1214684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp> 1224684ddb6SLionel Sambuc__base<_Rp()>* 1234684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp()>::__clone() const 1244684ddb6SLionel Sambuc{ 125*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 126*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 1274684ddb6SLionel Sambuc _Ap __a(__f_.second()); 1284684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 1294684ddb6SLionel Sambuc unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1304684ddb6SLionel Sambuc ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 1314684ddb6SLionel Sambuc return __hold.release(); 1324684ddb6SLionel Sambuc} 1334684ddb6SLionel Sambuc 1344684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp> 1354684ddb6SLionel Sambucvoid 1364684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const 1374684ddb6SLionel Sambuc{ 1384684ddb6SLionel Sambuc ::new (__p) __func(__f_.first(), __f_.second()); 1394684ddb6SLionel Sambuc} 1404684ddb6SLionel Sambuc 1414684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp> 1424684ddb6SLionel Sambucvoid 1434684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp()>::destroy() 1444684ddb6SLionel Sambuc{ 1454684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 1464684ddb6SLionel Sambuc} 1474684ddb6SLionel Sambuc 1484684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp> 1494684ddb6SLionel Sambucvoid 1504684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp()>::destroy_deallocate() 1514684ddb6SLionel Sambuc{ 152*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 153*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 1544684ddb6SLionel Sambuc _Ap __a(__f_.second()); 1554684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 1564684ddb6SLionel Sambuc __a.deallocate(this, 1); 1574684ddb6SLionel Sambuc} 1584684ddb6SLionel Sambuc 1594684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp> 1604684ddb6SLionel Sambuc_Rp 1614684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp()>::operator()() 1624684ddb6SLionel Sambuc{ 163*0a6a1f1dSLionel Sambuc typedef __invoke_void_return_wrapper<_Rp> _Invoker; 164*0a6a1f1dSLionel Sambuc return _Invoker::__call(__f_.first()); 1654684ddb6SLionel Sambuc} 1664684ddb6SLionel Sambuc 1674684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 1684684ddb6SLionel Sambuc 1694684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp> 1704684ddb6SLionel Sambucconst void* 1714684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const 1724684ddb6SLionel Sambuc{ 1734684ddb6SLionel Sambuc if (__ti == typeid(_Fp)) 1744684ddb6SLionel Sambuc return &__f_.first(); 1754684ddb6SLionel Sambuc return (const void*)0; 1764684ddb6SLionel Sambuc} 1774684ddb6SLionel Sambuc 1784684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp> 1794684ddb6SLionel Sambucconst std::type_info& 1804684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp()>::target_type() const 1814684ddb6SLionel Sambuc{ 1824684ddb6SLionel Sambuc return typeid(_Fp); 1834684ddb6SLionel Sambuc} 1844684ddb6SLionel Sambuc 1854684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 1864684ddb6SLionel Sambuc 1874684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0> 1884684ddb6SLionel Sambucclass __func<_Fp, _Alloc, _Rp(_A0)> 1894684ddb6SLionel Sambuc : public __base<_Rp(_A0)> 1904684ddb6SLionel Sambuc{ 1914684ddb6SLionel Sambuc __compressed_pair<_Fp, _Alloc> __f_; 1924684ddb6SLionel Sambucpublic: 1934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} 1944684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) 1954684ddb6SLionel Sambuc : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 1964684ddb6SLionel Sambuc virtual __base<_Rp(_A0)>* __clone() const; 1974684ddb6SLionel Sambuc virtual void __clone(__base<_Rp(_A0)>*) const; 1984684ddb6SLionel Sambuc virtual void destroy(); 1994684ddb6SLionel Sambuc virtual void destroy_deallocate(); 2004684ddb6SLionel Sambuc virtual _Rp operator()(_A0); 2014684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 2024684ddb6SLionel Sambuc virtual const void* target(const type_info&) const; 2034684ddb6SLionel Sambuc virtual const std::type_info& target_type() const; 2044684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 2054684ddb6SLionel Sambuc}; 2064684ddb6SLionel Sambuc 2074684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0> 2084684ddb6SLionel Sambuc__base<_Rp(_A0)>* 2094684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0)>::__clone() const 2104684ddb6SLionel Sambuc{ 211*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 212*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 2134684ddb6SLionel Sambuc _Ap __a(__f_.second()); 2144684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 2154684ddb6SLionel Sambuc unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 2164684ddb6SLionel Sambuc ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 2174684ddb6SLionel Sambuc return __hold.release(); 2184684ddb6SLionel Sambuc} 2194684ddb6SLionel Sambuc 2204684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0> 2214684ddb6SLionel Sambucvoid 2224684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const 2234684ddb6SLionel Sambuc{ 2244684ddb6SLionel Sambuc ::new (__p) __func(__f_.first(), __f_.second()); 2254684ddb6SLionel Sambuc} 2264684ddb6SLionel Sambuc 2274684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0> 2284684ddb6SLionel Sambucvoid 2294684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0)>::destroy() 2304684ddb6SLionel Sambuc{ 2314684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 2324684ddb6SLionel Sambuc} 2334684ddb6SLionel Sambuc 2344684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0> 2354684ddb6SLionel Sambucvoid 2364684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate() 2374684ddb6SLionel Sambuc{ 238*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 239*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 2404684ddb6SLionel Sambuc _Ap __a(__f_.second()); 2414684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 2424684ddb6SLionel Sambuc __a.deallocate(this, 1); 2434684ddb6SLionel Sambuc} 2444684ddb6SLionel Sambuc 2454684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0> 2464684ddb6SLionel Sambuc_Rp 2474684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0) 2484684ddb6SLionel Sambuc{ 249*0a6a1f1dSLionel Sambuc typedef __invoke_void_return_wrapper<_Rp> _Invoker; 250*0a6a1f1dSLionel Sambuc return _Invoker::__call(__f_.first(), __a0); 2514684ddb6SLionel Sambuc} 2524684ddb6SLionel Sambuc 2534684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 2544684ddb6SLionel Sambuc 2554684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0> 2564684ddb6SLionel Sambucconst void* 2574684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const 2584684ddb6SLionel Sambuc{ 2594684ddb6SLionel Sambuc if (__ti == typeid(_Fp)) 2604684ddb6SLionel Sambuc return &__f_.first(); 2614684ddb6SLionel Sambuc return (const void*)0; 2624684ddb6SLionel Sambuc} 2634684ddb6SLionel Sambuc 2644684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0> 2654684ddb6SLionel Sambucconst std::type_info& 2664684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0)>::target_type() const 2674684ddb6SLionel Sambuc{ 2684684ddb6SLionel Sambuc return typeid(_Fp); 2694684ddb6SLionel Sambuc} 2704684ddb6SLionel Sambuc 2714684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 2724684ddb6SLionel Sambuc 2734684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 2744684ddb6SLionel Sambucclass __func<_Fp, _Alloc, _Rp(_A0, _A1)> 2754684ddb6SLionel Sambuc : public __base<_Rp(_A0, _A1)> 2764684ddb6SLionel Sambuc{ 2774684ddb6SLionel Sambuc __compressed_pair<_Fp, _Alloc> __f_; 2784684ddb6SLionel Sambucpublic: 2794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} 2804684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) 2814684ddb6SLionel Sambuc : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 2824684ddb6SLionel Sambuc virtual __base<_Rp(_A0, _A1)>* __clone() const; 2834684ddb6SLionel Sambuc virtual void __clone(__base<_Rp(_A0, _A1)>*) const; 2844684ddb6SLionel Sambuc virtual void destroy(); 2854684ddb6SLionel Sambuc virtual void destroy_deallocate(); 2864684ddb6SLionel Sambuc virtual _Rp operator()(_A0, _A1); 2874684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 2884684ddb6SLionel Sambuc virtual const void* target(const type_info&) const; 2894684ddb6SLionel Sambuc virtual const std::type_info& target_type() const; 2904684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 2914684ddb6SLionel Sambuc}; 2924684ddb6SLionel Sambuc 2934684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 2944684ddb6SLionel Sambuc__base<_Rp(_A0, _A1)>* 2954684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const 2964684ddb6SLionel Sambuc{ 297*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 298*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 2994684ddb6SLionel Sambuc _Ap __a(__f_.second()); 3004684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 3014684ddb6SLionel Sambuc unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 3024684ddb6SLionel Sambuc ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 3034684ddb6SLionel Sambuc return __hold.release(); 3044684ddb6SLionel Sambuc} 3054684ddb6SLionel Sambuc 3064684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 3074684ddb6SLionel Sambucvoid 3084684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const 3094684ddb6SLionel Sambuc{ 3104684ddb6SLionel Sambuc ::new (__p) __func(__f_.first(), __f_.second()); 3114684ddb6SLionel Sambuc} 3124684ddb6SLionel Sambuc 3134684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 3144684ddb6SLionel Sambucvoid 3154684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy() 3164684ddb6SLionel Sambuc{ 3174684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 3184684ddb6SLionel Sambuc} 3194684ddb6SLionel Sambuc 3204684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 3214684ddb6SLionel Sambucvoid 3224684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate() 3234684ddb6SLionel Sambuc{ 324*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 325*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 3264684ddb6SLionel Sambuc _Ap __a(__f_.second()); 3274684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 3284684ddb6SLionel Sambuc __a.deallocate(this, 1); 3294684ddb6SLionel Sambuc} 3304684ddb6SLionel Sambuc 3314684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 3324684ddb6SLionel Sambuc_Rp 3334684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) 3344684ddb6SLionel Sambuc{ 335*0a6a1f1dSLionel Sambuc typedef __invoke_void_return_wrapper<_Rp> _Invoker; 336*0a6a1f1dSLionel Sambuc return _Invoker::__call(__f_.first(), __a0, __a1); 3374684ddb6SLionel Sambuc} 3384684ddb6SLionel Sambuc 3394684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 3404684ddb6SLionel Sambuc 3414684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 3424684ddb6SLionel Sambucconst void* 3434684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const 3444684ddb6SLionel Sambuc{ 3454684ddb6SLionel Sambuc if (__ti == typeid(_Fp)) 3464684ddb6SLionel Sambuc return &__f_.first(); 3474684ddb6SLionel Sambuc return (const void*)0; 3484684ddb6SLionel Sambuc} 3494684ddb6SLionel Sambuc 3504684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> 3514684ddb6SLionel Sambucconst std::type_info& 3524684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const 3534684ddb6SLionel Sambuc{ 3544684ddb6SLionel Sambuc return typeid(_Fp); 3554684ddb6SLionel Sambuc} 3564684ddb6SLionel Sambuc 3574684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 3584684ddb6SLionel Sambuc 3594684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 3604684ddb6SLionel Sambucclass __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> 3614684ddb6SLionel Sambuc : public __base<_Rp(_A0, _A1, _A2)> 3624684ddb6SLionel Sambuc{ 3634684ddb6SLionel Sambuc __compressed_pair<_Fp, _Alloc> __f_; 3644684ddb6SLionel Sambucpublic: 3654684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} 3664684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) 3674684ddb6SLionel Sambuc : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} 3684684ddb6SLionel Sambuc virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const; 3694684ddb6SLionel Sambuc virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const; 3704684ddb6SLionel Sambuc virtual void destroy(); 3714684ddb6SLionel Sambuc virtual void destroy_deallocate(); 3724684ddb6SLionel Sambuc virtual _Rp operator()(_A0, _A1, _A2); 3734684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 3744684ddb6SLionel Sambuc virtual const void* target(const type_info&) const; 3754684ddb6SLionel Sambuc virtual const std::type_info& target_type() const; 3764684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 3774684ddb6SLionel Sambuc}; 3784684ddb6SLionel Sambuc 3794684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 3804684ddb6SLionel Sambuc__base<_Rp(_A0, _A1, _A2)>* 3814684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const 3824684ddb6SLionel Sambuc{ 383*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 384*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 3854684ddb6SLionel Sambuc _Ap __a(__f_.second()); 3864684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 3874684ddb6SLionel Sambuc unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 3884684ddb6SLionel Sambuc ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 3894684ddb6SLionel Sambuc return __hold.release(); 3904684ddb6SLionel Sambuc} 3914684ddb6SLionel Sambuc 3924684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 3934684ddb6SLionel Sambucvoid 3944684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const 3954684ddb6SLionel Sambuc{ 3964684ddb6SLionel Sambuc ::new (__p) __func(__f_.first(), __f_.second()); 3974684ddb6SLionel Sambuc} 3984684ddb6SLionel Sambuc 3994684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 4004684ddb6SLionel Sambucvoid 4014684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy() 4024684ddb6SLionel Sambuc{ 4034684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 4044684ddb6SLionel Sambuc} 4054684ddb6SLionel Sambuc 4064684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 4074684ddb6SLionel Sambucvoid 4084684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate() 4094684ddb6SLionel Sambuc{ 410*0a6a1f1dSLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 411*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; 4124684ddb6SLionel Sambuc _Ap __a(__f_.second()); 4134684ddb6SLionel Sambuc __f_.~__compressed_pair<_Fp, _Alloc>(); 4144684ddb6SLionel Sambuc __a.deallocate(this, 1); 4154684ddb6SLionel Sambuc} 4164684ddb6SLionel Sambuc 4174684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 4184684ddb6SLionel Sambuc_Rp 4194684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) 4204684ddb6SLionel Sambuc{ 421*0a6a1f1dSLionel Sambuc typedef __invoke_void_return_wrapper<_Rp> _Invoker; 422*0a6a1f1dSLionel Sambuc return _Invoker::__call(__f_.first(), __a0, __a1, __a2); 4234684ddb6SLionel Sambuc} 4244684ddb6SLionel Sambuc 4254684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 4264684ddb6SLionel Sambuc 4274684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 4284684ddb6SLionel Sambucconst void* 4294684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const 4304684ddb6SLionel Sambuc{ 4314684ddb6SLionel Sambuc if (__ti == typeid(_Fp)) 4324684ddb6SLionel Sambuc return &__f_.first(); 4334684ddb6SLionel Sambuc return (const void*)0; 4344684ddb6SLionel Sambuc} 4354684ddb6SLionel Sambuc 4364684ddb6SLionel Sambuctemplate<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> 4374684ddb6SLionel Sambucconst std::type_info& 4384684ddb6SLionel Sambuc__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const 4394684ddb6SLionel Sambuc{ 4404684ddb6SLionel Sambuc return typeid(_Fp); 4414684ddb6SLionel Sambuc} 4424684ddb6SLionel Sambuc 4434684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 4444684ddb6SLionel Sambuc 4454684ddb6SLionel Sambuc} // __function 4464684ddb6SLionel Sambuc 4474684ddb6SLionel Sambuctemplate<class _Rp> 4484684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY function<_Rp()> 4494684ddb6SLionel Sambuc{ 4504684ddb6SLionel Sambuc typedef __function::__base<_Rp()> __base; 4514684ddb6SLionel Sambuc aligned_storage<3*sizeof(void*)>::type __buf_; 4524684ddb6SLionel Sambuc __base* __f_; 4534684ddb6SLionel Sambuc 4544684ddb6SLionel Sambucpublic: 4554684ddb6SLionel Sambuc typedef _Rp result_type; 4564684ddb6SLionel Sambuc 4574684ddb6SLionel Sambuc // 20.7.16.2.1, construct/copy/destroy: 4584684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} 4594684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} 4604684ddb6SLionel Sambuc function(const function&); 4614684ddb6SLionel Sambuc template<class _Fp> 4624684ddb6SLionel Sambuc function(_Fp, 4634684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type* = 0); 4644684ddb6SLionel Sambuc 4654684ddb6SLionel Sambuc template<class _Alloc> 4664684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 4674684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&) : __f_(0) {} 4684684ddb6SLionel Sambuc template<class _Alloc> 4694684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 4704684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} 4714684ddb6SLionel Sambuc template<class _Alloc> 4724684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&, const function&); 4734684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 4744684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc& __a, _Fp __f, 4754684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type* = 0); 4764684ddb6SLionel Sambuc 4774684ddb6SLionel Sambuc function& operator=(const function&); 4784684ddb6SLionel Sambuc function& operator=(nullptr_t); 4794684ddb6SLionel Sambuc template<class _Fp> 4804684ddb6SLionel Sambuc typename enable_if 4814684ddb6SLionel Sambuc < 4824684ddb6SLionel Sambuc !is_integral<_Fp>::value, 4834684ddb6SLionel Sambuc function& 4844684ddb6SLionel Sambuc >::type 4854684ddb6SLionel Sambuc operator=(_Fp); 4864684ddb6SLionel Sambuc 4874684ddb6SLionel Sambuc ~function(); 4884684ddb6SLionel Sambuc 4894684ddb6SLionel Sambuc // 20.7.16.2.2, function modifiers: 4904684ddb6SLionel Sambuc void swap(function&); 4914684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 4924684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 4934684ddb6SLionel Sambuc void assign(_Fp __f, const _Alloc& __a) 4944684ddb6SLionel Sambuc {function(allocator_arg, __a, __f).swap(*this);} 4954684ddb6SLionel Sambuc 4964684ddb6SLionel Sambuc // 20.7.16.2.3, function capacity: 4974684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} 4984684ddb6SLionel Sambuc 4994684ddb6SLionel Sambucprivate: 5004684ddb6SLionel Sambuc // deleted overloads close possible hole in the type system 5014684ddb6SLionel Sambuc template<class _R2> 5024684ddb6SLionel Sambuc bool operator==(const function<_R2()>&) const;// = delete; 5034684ddb6SLionel Sambuc template<class _R2> 5044684ddb6SLionel Sambuc bool operator!=(const function<_R2()>&) const;// = delete; 5054684ddb6SLionel Sambucpublic: 5064684ddb6SLionel Sambuc // 20.7.16.2.4, function invocation: 5074684ddb6SLionel Sambuc _Rp operator()() const; 5084684ddb6SLionel Sambuc 5094684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 5104684ddb6SLionel Sambuc // 20.7.16.2.5, function target access: 5114684ddb6SLionel Sambuc const std::type_info& target_type() const; 5124684ddb6SLionel Sambuc template <typename _Tp> _Tp* target(); 5134684ddb6SLionel Sambuc template <typename _Tp> const _Tp* target() const; 5144684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 5154684ddb6SLionel Sambuc}; 5164684ddb6SLionel Sambuc 5174684ddb6SLionel Sambuctemplate<class _Rp> 5184684ddb6SLionel Sambucfunction<_Rp()>::function(const function& __f) 5194684ddb6SLionel Sambuc{ 5204684ddb6SLionel Sambuc if (__f.__f_ == 0) 5214684ddb6SLionel Sambuc __f_ = 0; 5224684ddb6SLionel Sambuc else if (__f.__f_ == (const __base*)&__f.__buf_) 5234684ddb6SLionel Sambuc { 5244684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 5254684ddb6SLionel Sambuc __f.__f_->__clone(__f_); 5264684ddb6SLionel Sambuc } 5274684ddb6SLionel Sambuc else 5284684ddb6SLionel Sambuc __f_ = __f.__f_->__clone(); 5294684ddb6SLionel Sambuc} 5304684ddb6SLionel Sambuc 5314684ddb6SLionel Sambuctemplate<class _Rp> 5324684ddb6SLionel Sambuctemplate<class _Alloc> 5334684ddb6SLionel Sambucfunction<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f) 5344684ddb6SLionel Sambuc{ 5354684ddb6SLionel Sambuc if (__f.__f_ == 0) 5364684ddb6SLionel Sambuc __f_ = 0; 5374684ddb6SLionel Sambuc else if (__f.__f_ == (const __base*)&__f.__buf_) 5384684ddb6SLionel Sambuc { 5394684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 5404684ddb6SLionel Sambuc __f.__f_->__clone(__f_); 5414684ddb6SLionel Sambuc } 5424684ddb6SLionel Sambuc else 5434684ddb6SLionel Sambuc __f_ = __f.__f_->__clone(); 5444684ddb6SLionel Sambuc} 5454684ddb6SLionel Sambuc 5464684ddb6SLionel Sambuctemplate<class _Rp> 5474684ddb6SLionel Sambuctemplate <class _Fp> 5484684ddb6SLionel Sambucfunction<_Rp()>::function(_Fp __f, 5494684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type*) 5504684ddb6SLionel Sambuc : __f_(0) 5514684ddb6SLionel Sambuc{ 552*0a6a1f1dSLionel Sambuc if (__function::__not_null(__f)) 5534684ddb6SLionel Sambuc { 5544684ddb6SLionel Sambuc typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF; 5554684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 5564684ddb6SLionel Sambuc { 5574684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 5584684ddb6SLionel Sambuc ::new (__f_) _FF(__f); 5594684ddb6SLionel Sambuc } 5604684ddb6SLionel Sambuc else 5614684ddb6SLionel Sambuc { 5624684ddb6SLionel Sambuc typedef allocator<_FF> _Ap; 5634684ddb6SLionel Sambuc _Ap __a; 5644684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 5654684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 5664684ddb6SLionel Sambuc ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); 5674684ddb6SLionel Sambuc __f_ = __hold.release(); 5684684ddb6SLionel Sambuc } 5694684ddb6SLionel Sambuc } 5704684ddb6SLionel Sambuc} 5714684ddb6SLionel Sambuc 5724684ddb6SLionel Sambuctemplate<class _Rp> 5734684ddb6SLionel Sambuctemplate <class _Fp, class _Alloc> 5744684ddb6SLionel Sambucfunction<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 5754684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type*) 5764684ddb6SLionel Sambuc : __f_(0) 5774684ddb6SLionel Sambuc{ 5784684ddb6SLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 579*0a6a1f1dSLionel Sambuc if (__function::__not_null(__f)) 5804684ddb6SLionel Sambuc { 5814684ddb6SLionel Sambuc typedef __function::__func<_Fp, _Alloc, _Rp()> _FF; 5824684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 5834684ddb6SLionel Sambuc { 5844684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 585*0a6a1f1dSLionel Sambuc ::new (__f_) _FF(__f, __a0); 5864684ddb6SLionel Sambuc } 5874684ddb6SLionel Sambuc else 5884684ddb6SLionel Sambuc { 589*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 5904684ddb6SLionel Sambuc _Ap __a(__a0); 5914684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 5924684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 5934684ddb6SLionel Sambuc ::new (__hold.get()) _FF(__f, _Alloc(__a)); 5944684ddb6SLionel Sambuc __f_ = __hold.release(); 5954684ddb6SLionel Sambuc } 5964684ddb6SLionel Sambuc } 5974684ddb6SLionel Sambuc} 5984684ddb6SLionel Sambuc 5994684ddb6SLionel Sambuctemplate<class _Rp> 6004684ddb6SLionel Sambucfunction<_Rp()>& 6014684ddb6SLionel Sambucfunction<_Rp()>::operator=(const function& __f) 6024684ddb6SLionel Sambuc{ 6034684ddb6SLionel Sambuc function(__f).swap(*this); 6044684ddb6SLionel Sambuc return *this; 6054684ddb6SLionel Sambuc} 6064684ddb6SLionel Sambuc 6074684ddb6SLionel Sambuctemplate<class _Rp> 6084684ddb6SLionel Sambucfunction<_Rp()>& 6094684ddb6SLionel Sambucfunction<_Rp()>::operator=(nullptr_t) 6104684ddb6SLionel Sambuc{ 6114684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 6124684ddb6SLionel Sambuc __f_->destroy(); 6134684ddb6SLionel Sambuc else if (__f_) 6144684ddb6SLionel Sambuc __f_->destroy_deallocate(); 6154684ddb6SLionel Sambuc __f_ = 0; 616*0a6a1f1dSLionel Sambuc return *this; 6174684ddb6SLionel Sambuc} 6184684ddb6SLionel Sambuc 6194684ddb6SLionel Sambuctemplate<class _Rp> 6204684ddb6SLionel Sambuctemplate <class _Fp> 6214684ddb6SLionel Sambuctypename enable_if 6224684ddb6SLionel Sambuc< 6234684ddb6SLionel Sambuc !is_integral<_Fp>::value, 6244684ddb6SLionel Sambuc function<_Rp()>& 6254684ddb6SLionel Sambuc>::type 6264684ddb6SLionel Sambucfunction<_Rp()>::operator=(_Fp __f) 6274684ddb6SLionel Sambuc{ 6284684ddb6SLionel Sambuc function(_VSTD::move(__f)).swap(*this); 6294684ddb6SLionel Sambuc return *this; 6304684ddb6SLionel Sambuc} 6314684ddb6SLionel Sambuc 6324684ddb6SLionel Sambuctemplate<class _Rp> 6334684ddb6SLionel Sambucfunction<_Rp()>::~function() 6344684ddb6SLionel Sambuc{ 6354684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 6364684ddb6SLionel Sambuc __f_->destroy(); 6374684ddb6SLionel Sambuc else if (__f_) 6384684ddb6SLionel Sambuc __f_->destroy_deallocate(); 6394684ddb6SLionel Sambuc} 6404684ddb6SLionel Sambuc 6414684ddb6SLionel Sambuctemplate<class _Rp> 6424684ddb6SLionel Sambucvoid 6434684ddb6SLionel Sambucfunction<_Rp()>::swap(function& __f) 6444684ddb6SLionel Sambuc{ 6454684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 6464684ddb6SLionel Sambuc { 6474684ddb6SLionel Sambuc typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 6484684ddb6SLionel Sambuc __base* __t = (__base*)&__tempbuf; 6494684ddb6SLionel Sambuc __f_->__clone(__t); 6504684ddb6SLionel Sambuc __f_->destroy(); 6514684ddb6SLionel Sambuc __f_ = 0; 6524684ddb6SLionel Sambuc __f.__f_->__clone((__base*)&__buf_); 6534684ddb6SLionel Sambuc __f.__f_->destroy(); 6544684ddb6SLionel Sambuc __f.__f_ = 0; 6554684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 6564684ddb6SLionel Sambuc __t->__clone((__base*)&__f.__buf_); 6574684ddb6SLionel Sambuc __t->destroy(); 6584684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 6594684ddb6SLionel Sambuc } 6604684ddb6SLionel Sambuc else if (__f_ == (__base*)&__buf_) 6614684ddb6SLionel Sambuc { 6624684ddb6SLionel Sambuc __f_->__clone((__base*)&__f.__buf_); 6634684ddb6SLionel Sambuc __f_->destroy(); 6644684ddb6SLionel Sambuc __f_ = __f.__f_; 6654684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 6664684ddb6SLionel Sambuc } 6674684ddb6SLionel Sambuc else if (__f.__f_ == (__base*)&__f.__buf_) 6684684ddb6SLionel Sambuc { 6694684ddb6SLionel Sambuc __f.__f_->__clone((__base*)&__buf_); 6704684ddb6SLionel Sambuc __f.__f_->destroy(); 6714684ddb6SLionel Sambuc __f.__f_ = __f_; 6724684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 6734684ddb6SLionel Sambuc } 6744684ddb6SLionel Sambuc else 6754684ddb6SLionel Sambuc _VSTD::swap(__f_, __f.__f_); 6764684ddb6SLionel Sambuc} 6774684ddb6SLionel Sambuc 6784684ddb6SLionel Sambuctemplate<class _Rp> 6794684ddb6SLionel Sambuc_Rp 6804684ddb6SLionel Sambucfunction<_Rp()>::operator()() const 6814684ddb6SLionel Sambuc{ 6824684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 6834684ddb6SLionel Sambuc if (__f_ == 0) 6844684ddb6SLionel Sambuc throw bad_function_call(); 6854684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 6864684ddb6SLionel Sambuc return (*__f_)(); 6874684ddb6SLionel Sambuc} 6884684ddb6SLionel Sambuc 6894684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 6904684ddb6SLionel Sambuc 6914684ddb6SLionel Sambuctemplate<class _Rp> 6924684ddb6SLionel Sambucconst std::type_info& 6934684ddb6SLionel Sambucfunction<_Rp()>::target_type() const 6944684ddb6SLionel Sambuc{ 6954684ddb6SLionel Sambuc if (__f_ == 0) 6964684ddb6SLionel Sambuc return typeid(void); 6974684ddb6SLionel Sambuc return __f_->target_type(); 6984684ddb6SLionel Sambuc} 6994684ddb6SLionel Sambuc 7004684ddb6SLionel Sambuctemplate<class _Rp> 7014684ddb6SLionel Sambuctemplate <typename _Tp> 7024684ddb6SLionel Sambuc_Tp* 7034684ddb6SLionel Sambucfunction<_Rp()>::target() 7044684ddb6SLionel Sambuc{ 7054684ddb6SLionel Sambuc if (__f_ == 0) 7064684ddb6SLionel Sambuc return (_Tp*)0; 7074684ddb6SLionel Sambuc return (_Tp*)__f_->target(typeid(_Tp)); 7084684ddb6SLionel Sambuc} 7094684ddb6SLionel Sambuc 7104684ddb6SLionel Sambuctemplate<class _Rp> 7114684ddb6SLionel Sambuctemplate <typename _Tp> 7124684ddb6SLionel Sambucconst _Tp* 7134684ddb6SLionel Sambucfunction<_Rp()>::target() const 7144684ddb6SLionel Sambuc{ 7154684ddb6SLionel Sambuc if (__f_ == 0) 7164684ddb6SLionel Sambuc return (const _Tp*)0; 7174684ddb6SLionel Sambuc return (const _Tp*)__f_->target(typeid(_Tp)); 7184684ddb6SLionel Sambuc} 7194684ddb6SLionel Sambuc 7204684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 7214684ddb6SLionel Sambuc 7224684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 7234684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)> 7244684ddb6SLionel Sambuc : public unary_function<_A0, _Rp> 7254684ddb6SLionel Sambuc{ 7264684ddb6SLionel Sambuc typedef __function::__base<_Rp(_A0)> __base; 7274684ddb6SLionel Sambuc aligned_storage<3*sizeof(void*)>::type __buf_; 7284684ddb6SLionel Sambuc __base* __f_; 7294684ddb6SLionel Sambuc 7304684ddb6SLionel Sambucpublic: 7314684ddb6SLionel Sambuc typedef _Rp result_type; 7324684ddb6SLionel Sambuc 7334684ddb6SLionel Sambuc // 20.7.16.2.1, construct/copy/destroy: 7344684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} 7354684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} 7364684ddb6SLionel Sambuc function(const function&); 7374684ddb6SLionel Sambuc template<class _Fp> 7384684ddb6SLionel Sambuc function(_Fp, 7394684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type* = 0); 7404684ddb6SLionel Sambuc 7414684ddb6SLionel Sambuc template<class _Alloc> 7424684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7434684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&) : __f_(0) {} 7444684ddb6SLionel Sambuc template<class _Alloc> 7454684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7464684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} 7474684ddb6SLionel Sambuc template<class _Alloc> 7484684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&, const function&); 7494684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 7504684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc& __a, _Fp __f, 7514684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type* = 0); 7524684ddb6SLionel Sambuc 7534684ddb6SLionel Sambuc function& operator=(const function&); 7544684ddb6SLionel Sambuc function& operator=(nullptr_t); 7554684ddb6SLionel Sambuc template<class _Fp> 7564684ddb6SLionel Sambuc typename enable_if 7574684ddb6SLionel Sambuc < 7584684ddb6SLionel Sambuc !is_integral<_Fp>::value, 7594684ddb6SLionel Sambuc function& 7604684ddb6SLionel Sambuc >::type 7614684ddb6SLionel Sambuc operator=(_Fp); 7624684ddb6SLionel Sambuc 7634684ddb6SLionel Sambuc ~function(); 7644684ddb6SLionel Sambuc 7654684ddb6SLionel Sambuc // 20.7.16.2.2, function modifiers: 7664684ddb6SLionel Sambuc void swap(function&); 7674684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 7684684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 7694684ddb6SLionel Sambuc void assign(_Fp __f, const _Alloc& __a) 7704684ddb6SLionel Sambuc {function(allocator_arg, __a, __f).swap(*this);} 7714684ddb6SLionel Sambuc 7724684ddb6SLionel Sambuc // 20.7.16.2.3, function capacity: 7734684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} 7744684ddb6SLionel Sambuc 7754684ddb6SLionel Sambucprivate: 7764684ddb6SLionel Sambuc // deleted overloads close possible hole in the type system 7774684ddb6SLionel Sambuc template<class _R2, class _B0> 7784684ddb6SLionel Sambuc bool operator==(const function<_R2(_B0)>&) const;// = delete; 7794684ddb6SLionel Sambuc template<class _R2, class _B0> 7804684ddb6SLionel Sambuc bool operator!=(const function<_R2(_B0)>&) const;// = delete; 7814684ddb6SLionel Sambucpublic: 7824684ddb6SLionel Sambuc // 20.7.16.2.4, function invocation: 7834684ddb6SLionel Sambuc _Rp operator()(_A0) const; 7844684ddb6SLionel Sambuc 7854684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 7864684ddb6SLionel Sambuc // 20.7.16.2.5, function target access: 7874684ddb6SLionel Sambuc const std::type_info& target_type() const; 7884684ddb6SLionel Sambuc template <typename _Tp> _Tp* target(); 7894684ddb6SLionel Sambuc template <typename _Tp> const _Tp* target() const; 7904684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 7914684ddb6SLionel Sambuc}; 7924684ddb6SLionel Sambuc 7934684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 7944684ddb6SLionel Sambucfunction<_Rp(_A0)>::function(const function& __f) 7954684ddb6SLionel Sambuc{ 7964684ddb6SLionel Sambuc if (__f.__f_ == 0) 7974684ddb6SLionel Sambuc __f_ = 0; 7984684ddb6SLionel Sambuc else if (__f.__f_ == (const __base*)&__f.__buf_) 7994684ddb6SLionel Sambuc { 8004684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 8014684ddb6SLionel Sambuc __f.__f_->__clone(__f_); 8024684ddb6SLionel Sambuc } 8034684ddb6SLionel Sambuc else 8044684ddb6SLionel Sambuc __f_ = __f.__f_->__clone(); 8054684ddb6SLionel Sambuc} 8064684ddb6SLionel Sambuc 8074684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 8084684ddb6SLionel Sambuctemplate<class _Alloc> 8094684ddb6SLionel Sambucfunction<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) 8104684ddb6SLionel Sambuc{ 8114684ddb6SLionel Sambuc if (__f.__f_ == 0) 8124684ddb6SLionel Sambuc __f_ = 0; 8134684ddb6SLionel Sambuc else if (__f.__f_ == (const __base*)&__f.__buf_) 8144684ddb6SLionel Sambuc { 8154684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 8164684ddb6SLionel Sambuc __f.__f_->__clone(__f_); 8174684ddb6SLionel Sambuc } 8184684ddb6SLionel Sambuc else 8194684ddb6SLionel Sambuc __f_ = __f.__f_->__clone(); 8204684ddb6SLionel Sambuc} 8214684ddb6SLionel Sambuc 8224684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 8234684ddb6SLionel Sambuctemplate <class _Fp> 8244684ddb6SLionel Sambucfunction<_Rp(_A0)>::function(_Fp __f, 8254684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type*) 8264684ddb6SLionel Sambuc : __f_(0) 8274684ddb6SLionel Sambuc{ 828*0a6a1f1dSLionel Sambuc if (__function::__not_null(__f)) 8294684ddb6SLionel Sambuc { 8304684ddb6SLionel Sambuc typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; 8314684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 8324684ddb6SLionel Sambuc { 8334684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 8344684ddb6SLionel Sambuc ::new (__f_) _FF(__f); 8354684ddb6SLionel Sambuc } 8364684ddb6SLionel Sambuc else 8374684ddb6SLionel Sambuc { 8384684ddb6SLionel Sambuc typedef allocator<_FF> _Ap; 8394684ddb6SLionel Sambuc _Ap __a; 8404684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 8414684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 8424684ddb6SLionel Sambuc ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); 8434684ddb6SLionel Sambuc __f_ = __hold.release(); 8444684ddb6SLionel Sambuc } 8454684ddb6SLionel Sambuc } 8464684ddb6SLionel Sambuc} 8474684ddb6SLionel Sambuc 8484684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 8494684ddb6SLionel Sambuctemplate <class _Fp, class _Alloc> 8504684ddb6SLionel Sambucfunction<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 8514684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type*) 8524684ddb6SLionel Sambuc : __f_(0) 8534684ddb6SLionel Sambuc{ 8544684ddb6SLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 855*0a6a1f1dSLionel Sambuc if (__function::__not_null(__f)) 8564684ddb6SLionel Sambuc { 8574684ddb6SLionel Sambuc typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; 8584684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 8594684ddb6SLionel Sambuc { 8604684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 861*0a6a1f1dSLionel Sambuc ::new (__f_) _FF(__f, __a0); 8624684ddb6SLionel Sambuc } 8634684ddb6SLionel Sambuc else 8644684ddb6SLionel Sambuc { 865*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 8664684ddb6SLionel Sambuc _Ap __a(__a0); 8674684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 8684684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 8694684ddb6SLionel Sambuc ::new (__hold.get()) _FF(__f, _Alloc(__a)); 8704684ddb6SLionel Sambuc __f_ = __hold.release(); 8714684ddb6SLionel Sambuc } 8724684ddb6SLionel Sambuc } 8734684ddb6SLionel Sambuc} 8744684ddb6SLionel Sambuc 8754684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 8764684ddb6SLionel Sambucfunction<_Rp(_A0)>& 8774684ddb6SLionel Sambucfunction<_Rp(_A0)>::operator=(const function& __f) 8784684ddb6SLionel Sambuc{ 8794684ddb6SLionel Sambuc function(__f).swap(*this); 8804684ddb6SLionel Sambuc return *this; 8814684ddb6SLionel Sambuc} 8824684ddb6SLionel Sambuc 8834684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 8844684ddb6SLionel Sambucfunction<_Rp(_A0)>& 8854684ddb6SLionel Sambucfunction<_Rp(_A0)>::operator=(nullptr_t) 8864684ddb6SLionel Sambuc{ 8874684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 8884684ddb6SLionel Sambuc __f_->destroy(); 8894684ddb6SLionel Sambuc else if (__f_) 8904684ddb6SLionel Sambuc __f_->destroy_deallocate(); 8914684ddb6SLionel Sambuc __f_ = 0; 892*0a6a1f1dSLionel Sambuc return *this; 8934684ddb6SLionel Sambuc} 8944684ddb6SLionel Sambuc 8954684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 8964684ddb6SLionel Sambuctemplate <class _Fp> 8974684ddb6SLionel Sambuctypename enable_if 8984684ddb6SLionel Sambuc< 8994684ddb6SLionel Sambuc !is_integral<_Fp>::value, 9004684ddb6SLionel Sambuc function<_Rp(_A0)>& 9014684ddb6SLionel Sambuc>::type 9024684ddb6SLionel Sambucfunction<_Rp(_A0)>::operator=(_Fp __f) 9034684ddb6SLionel Sambuc{ 9044684ddb6SLionel Sambuc function(_VSTD::move(__f)).swap(*this); 9054684ddb6SLionel Sambuc return *this; 9064684ddb6SLionel Sambuc} 9074684ddb6SLionel Sambuc 9084684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 9094684ddb6SLionel Sambucfunction<_Rp(_A0)>::~function() 9104684ddb6SLionel Sambuc{ 9114684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 9124684ddb6SLionel Sambuc __f_->destroy(); 9134684ddb6SLionel Sambuc else if (__f_) 9144684ddb6SLionel Sambuc __f_->destroy_deallocate(); 9154684ddb6SLionel Sambuc} 9164684ddb6SLionel Sambuc 9174684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 9184684ddb6SLionel Sambucvoid 9194684ddb6SLionel Sambucfunction<_Rp(_A0)>::swap(function& __f) 9204684ddb6SLionel Sambuc{ 9214684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 9224684ddb6SLionel Sambuc { 9234684ddb6SLionel Sambuc typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 9244684ddb6SLionel Sambuc __base* __t = (__base*)&__tempbuf; 9254684ddb6SLionel Sambuc __f_->__clone(__t); 9264684ddb6SLionel Sambuc __f_->destroy(); 9274684ddb6SLionel Sambuc __f_ = 0; 9284684ddb6SLionel Sambuc __f.__f_->__clone((__base*)&__buf_); 9294684ddb6SLionel Sambuc __f.__f_->destroy(); 9304684ddb6SLionel Sambuc __f.__f_ = 0; 9314684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 9324684ddb6SLionel Sambuc __t->__clone((__base*)&__f.__buf_); 9334684ddb6SLionel Sambuc __t->destroy(); 9344684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 9354684ddb6SLionel Sambuc } 9364684ddb6SLionel Sambuc else if (__f_ == (__base*)&__buf_) 9374684ddb6SLionel Sambuc { 9384684ddb6SLionel Sambuc __f_->__clone((__base*)&__f.__buf_); 9394684ddb6SLionel Sambuc __f_->destroy(); 9404684ddb6SLionel Sambuc __f_ = __f.__f_; 9414684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 9424684ddb6SLionel Sambuc } 9434684ddb6SLionel Sambuc else if (__f.__f_ == (__base*)&__f.__buf_) 9444684ddb6SLionel Sambuc { 9454684ddb6SLionel Sambuc __f.__f_->__clone((__base*)&__buf_); 9464684ddb6SLionel Sambuc __f.__f_->destroy(); 9474684ddb6SLionel Sambuc __f.__f_ = __f_; 9484684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 9494684ddb6SLionel Sambuc } 9504684ddb6SLionel Sambuc else 9514684ddb6SLionel Sambuc _VSTD::swap(__f_, __f.__f_); 9524684ddb6SLionel Sambuc} 9534684ddb6SLionel Sambuc 9544684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 9554684ddb6SLionel Sambuc_Rp 9564684ddb6SLionel Sambucfunction<_Rp(_A0)>::operator()(_A0 __a0) const 9574684ddb6SLionel Sambuc{ 9584684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 9594684ddb6SLionel Sambuc if (__f_ == 0) 9604684ddb6SLionel Sambuc throw bad_function_call(); 9614684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 9624684ddb6SLionel Sambuc return (*__f_)(__a0); 9634684ddb6SLionel Sambuc} 9644684ddb6SLionel Sambuc 9654684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 9664684ddb6SLionel Sambuc 9674684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 9684684ddb6SLionel Sambucconst std::type_info& 9694684ddb6SLionel Sambucfunction<_Rp(_A0)>::target_type() const 9704684ddb6SLionel Sambuc{ 9714684ddb6SLionel Sambuc if (__f_ == 0) 9724684ddb6SLionel Sambuc return typeid(void); 9734684ddb6SLionel Sambuc return __f_->target_type(); 9744684ddb6SLionel Sambuc} 9754684ddb6SLionel Sambuc 9764684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 9774684ddb6SLionel Sambuctemplate <typename _Tp> 9784684ddb6SLionel Sambuc_Tp* 9794684ddb6SLionel Sambucfunction<_Rp(_A0)>::target() 9804684ddb6SLionel Sambuc{ 9814684ddb6SLionel Sambuc if (__f_ == 0) 9824684ddb6SLionel Sambuc return (_Tp*)0; 9834684ddb6SLionel Sambuc return (_Tp*)__f_->target(typeid(_Tp)); 9844684ddb6SLionel Sambuc} 9854684ddb6SLionel Sambuc 9864684ddb6SLionel Sambuctemplate<class _Rp, class _A0> 9874684ddb6SLionel Sambuctemplate <typename _Tp> 9884684ddb6SLionel Sambucconst _Tp* 9894684ddb6SLionel Sambucfunction<_Rp(_A0)>::target() const 9904684ddb6SLionel Sambuc{ 9914684ddb6SLionel Sambuc if (__f_ == 0) 9924684ddb6SLionel Sambuc return (const _Tp*)0; 9934684ddb6SLionel Sambuc return (const _Tp*)__f_->target(typeid(_Tp)); 9944684ddb6SLionel Sambuc} 9954684ddb6SLionel Sambuc 9964684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 9974684ddb6SLionel Sambuc 9984684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 9994684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)> 10004684ddb6SLionel Sambuc : public binary_function<_A0, _A1, _Rp> 10014684ddb6SLionel Sambuc{ 10024684ddb6SLionel Sambuc typedef __function::__base<_Rp(_A0, _A1)> __base; 10034684ddb6SLionel Sambuc aligned_storage<3*sizeof(void*)>::type __buf_; 10044684ddb6SLionel Sambuc __base* __f_; 10054684ddb6SLionel Sambuc 10064684ddb6SLionel Sambucpublic: 10074684ddb6SLionel Sambuc typedef _Rp result_type; 10084684ddb6SLionel Sambuc 10094684ddb6SLionel Sambuc // 20.7.16.2.1, construct/copy/destroy: 10104684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} 10114684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} 10124684ddb6SLionel Sambuc function(const function&); 10134684ddb6SLionel Sambuc template<class _Fp> 10144684ddb6SLionel Sambuc function(_Fp, 10154684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type* = 0); 10164684ddb6SLionel Sambuc 10174684ddb6SLionel Sambuc template<class _Alloc> 10184684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 10194684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&) : __f_(0) {} 10204684ddb6SLionel Sambuc template<class _Alloc> 10214684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 10224684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} 10234684ddb6SLionel Sambuc template<class _Alloc> 10244684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&, const function&); 10254684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 10264684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc& __a, _Fp __f, 10274684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type* = 0); 10284684ddb6SLionel Sambuc 10294684ddb6SLionel Sambuc function& operator=(const function&); 10304684ddb6SLionel Sambuc function& operator=(nullptr_t); 10314684ddb6SLionel Sambuc template<class _Fp> 10324684ddb6SLionel Sambuc typename enable_if 10334684ddb6SLionel Sambuc < 10344684ddb6SLionel Sambuc !is_integral<_Fp>::value, 10354684ddb6SLionel Sambuc function& 10364684ddb6SLionel Sambuc >::type 10374684ddb6SLionel Sambuc operator=(_Fp); 10384684ddb6SLionel Sambuc 10394684ddb6SLionel Sambuc ~function(); 10404684ddb6SLionel Sambuc 10414684ddb6SLionel Sambuc // 20.7.16.2.2, function modifiers: 10424684ddb6SLionel Sambuc void swap(function&); 10434684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 10444684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 10454684ddb6SLionel Sambuc void assign(_Fp __f, const _Alloc& __a) 10464684ddb6SLionel Sambuc {function(allocator_arg, __a, __f).swap(*this);} 10474684ddb6SLionel Sambuc 10484684ddb6SLionel Sambuc // 20.7.16.2.3, function capacity: 10494684ddb6SLionel Sambuc operator bool() const {return __f_;} 10504684ddb6SLionel Sambuc 10514684ddb6SLionel Sambucprivate: 10524684ddb6SLionel Sambuc // deleted overloads close possible hole in the type system 10534684ddb6SLionel Sambuc template<class _R2, class _B0, class _B1> 10544684ddb6SLionel Sambuc bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete; 10554684ddb6SLionel Sambuc template<class _R2, class _B0, class _B1> 10564684ddb6SLionel Sambuc bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete; 10574684ddb6SLionel Sambucpublic: 10584684ddb6SLionel Sambuc // 20.7.16.2.4, function invocation: 10594684ddb6SLionel Sambuc _Rp operator()(_A0, _A1) const; 10604684ddb6SLionel Sambuc 10614684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 10624684ddb6SLionel Sambuc // 20.7.16.2.5, function target access: 10634684ddb6SLionel Sambuc const std::type_info& target_type() const; 10644684ddb6SLionel Sambuc template <typename _Tp> _Tp* target(); 10654684ddb6SLionel Sambuc template <typename _Tp> const _Tp* target() const; 10664684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 10674684ddb6SLionel Sambuc}; 10684684ddb6SLionel Sambuc 10694684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 10704684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::function(const function& __f) 10714684ddb6SLionel Sambuc{ 10724684ddb6SLionel Sambuc if (__f.__f_ == 0) 10734684ddb6SLionel Sambuc __f_ = 0; 10744684ddb6SLionel Sambuc else if (__f.__f_ == (const __base*)&__f.__buf_) 10754684ddb6SLionel Sambuc { 10764684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 10774684ddb6SLionel Sambuc __f.__f_->__clone(__f_); 10784684ddb6SLionel Sambuc } 10794684ddb6SLionel Sambuc else 10804684ddb6SLionel Sambuc __f_ = __f.__f_->__clone(); 10814684ddb6SLionel Sambuc} 10824684ddb6SLionel Sambuc 10834684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 10844684ddb6SLionel Sambuctemplate<class _Alloc> 10854684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f) 10864684ddb6SLionel Sambuc{ 10874684ddb6SLionel Sambuc if (__f.__f_ == 0) 10884684ddb6SLionel Sambuc __f_ = 0; 10894684ddb6SLionel Sambuc else if (__f.__f_ == (const __base*)&__f.__buf_) 10904684ddb6SLionel Sambuc { 10914684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 10924684ddb6SLionel Sambuc __f.__f_->__clone(__f_); 10934684ddb6SLionel Sambuc } 10944684ddb6SLionel Sambuc else 10954684ddb6SLionel Sambuc __f_ = __f.__f_->__clone(); 10964684ddb6SLionel Sambuc} 10974684ddb6SLionel Sambuc 10984684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 10994684ddb6SLionel Sambuctemplate <class _Fp> 11004684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::function(_Fp __f, 11014684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type*) 11024684ddb6SLionel Sambuc : __f_(0) 11034684ddb6SLionel Sambuc{ 1104*0a6a1f1dSLionel Sambuc if (__function::__not_null(__f)) 11054684ddb6SLionel Sambuc { 11064684ddb6SLionel Sambuc typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; 11074684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 11084684ddb6SLionel Sambuc { 11094684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 11104684ddb6SLionel Sambuc ::new (__f_) _FF(__f); 11114684ddb6SLionel Sambuc } 11124684ddb6SLionel Sambuc else 11134684ddb6SLionel Sambuc { 11144684ddb6SLionel Sambuc typedef allocator<_FF> _Ap; 11154684ddb6SLionel Sambuc _Ap __a; 11164684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 11174684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 11184684ddb6SLionel Sambuc ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); 11194684ddb6SLionel Sambuc __f_ = __hold.release(); 11204684ddb6SLionel Sambuc } 11214684ddb6SLionel Sambuc } 11224684ddb6SLionel Sambuc} 11234684ddb6SLionel Sambuc 11244684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 11254684ddb6SLionel Sambuctemplate <class _Fp, class _Alloc> 11264684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 11274684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type*) 11284684ddb6SLionel Sambuc : __f_(0) 11294684ddb6SLionel Sambuc{ 11304684ddb6SLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 1131*0a6a1f1dSLionel Sambuc if (__function::__not_null(__f)) 11324684ddb6SLionel Sambuc { 11334684ddb6SLionel Sambuc typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; 11344684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 11354684ddb6SLionel Sambuc { 11364684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 1137*0a6a1f1dSLionel Sambuc ::new (__f_) _FF(__f, __a0); 11384684ddb6SLionel Sambuc } 11394684ddb6SLionel Sambuc else 11404684ddb6SLionel Sambuc { 1141*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 11424684ddb6SLionel Sambuc _Ap __a(__a0); 11434684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 11444684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 11454684ddb6SLionel Sambuc ::new (__hold.get()) _FF(__f, _Alloc(__a)); 11464684ddb6SLionel Sambuc __f_ = __hold.release(); 11474684ddb6SLionel Sambuc } 11484684ddb6SLionel Sambuc } 11494684ddb6SLionel Sambuc} 11504684ddb6SLionel Sambuc 11514684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 11524684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>& 11534684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::operator=(const function& __f) 11544684ddb6SLionel Sambuc{ 11554684ddb6SLionel Sambuc function(__f).swap(*this); 11564684ddb6SLionel Sambuc return *this; 11574684ddb6SLionel Sambuc} 11584684ddb6SLionel Sambuc 11594684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 11604684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>& 11614684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::operator=(nullptr_t) 11624684ddb6SLionel Sambuc{ 11634684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 11644684ddb6SLionel Sambuc __f_->destroy(); 11654684ddb6SLionel Sambuc else if (__f_) 11664684ddb6SLionel Sambuc __f_->destroy_deallocate(); 11674684ddb6SLionel Sambuc __f_ = 0; 1168*0a6a1f1dSLionel Sambuc return *this; 11694684ddb6SLionel Sambuc} 11704684ddb6SLionel Sambuc 11714684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 11724684ddb6SLionel Sambuctemplate <class _Fp> 11734684ddb6SLionel Sambuctypename enable_if 11744684ddb6SLionel Sambuc< 11754684ddb6SLionel Sambuc !is_integral<_Fp>::value, 11764684ddb6SLionel Sambuc function<_Rp(_A0, _A1)>& 11774684ddb6SLionel Sambuc>::type 11784684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::operator=(_Fp __f) 11794684ddb6SLionel Sambuc{ 11804684ddb6SLionel Sambuc function(_VSTD::move(__f)).swap(*this); 11814684ddb6SLionel Sambuc return *this; 11824684ddb6SLionel Sambuc} 11834684ddb6SLionel Sambuc 11844684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 11854684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::~function() 11864684ddb6SLionel Sambuc{ 11874684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 11884684ddb6SLionel Sambuc __f_->destroy(); 11894684ddb6SLionel Sambuc else if (__f_) 11904684ddb6SLionel Sambuc __f_->destroy_deallocate(); 11914684ddb6SLionel Sambuc} 11924684ddb6SLionel Sambuc 11934684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 11944684ddb6SLionel Sambucvoid 11954684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::swap(function& __f) 11964684ddb6SLionel Sambuc{ 11974684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 11984684ddb6SLionel Sambuc { 11994684ddb6SLionel Sambuc typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 12004684ddb6SLionel Sambuc __base* __t = (__base*)&__tempbuf; 12014684ddb6SLionel Sambuc __f_->__clone(__t); 12024684ddb6SLionel Sambuc __f_->destroy(); 12034684ddb6SLionel Sambuc __f_ = 0; 12044684ddb6SLionel Sambuc __f.__f_->__clone((__base*)&__buf_); 12054684ddb6SLionel Sambuc __f.__f_->destroy(); 12064684ddb6SLionel Sambuc __f.__f_ = 0; 12074684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 12084684ddb6SLionel Sambuc __t->__clone((__base*)&__f.__buf_); 12094684ddb6SLionel Sambuc __t->destroy(); 12104684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 12114684ddb6SLionel Sambuc } 12124684ddb6SLionel Sambuc else if (__f_ == (__base*)&__buf_) 12134684ddb6SLionel Sambuc { 12144684ddb6SLionel Sambuc __f_->__clone((__base*)&__f.__buf_); 12154684ddb6SLionel Sambuc __f_->destroy(); 12164684ddb6SLionel Sambuc __f_ = __f.__f_; 12174684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 12184684ddb6SLionel Sambuc } 12194684ddb6SLionel Sambuc else if (__f.__f_ == (__base*)&__f.__buf_) 12204684ddb6SLionel Sambuc { 12214684ddb6SLionel Sambuc __f.__f_->__clone((__base*)&__buf_); 12224684ddb6SLionel Sambuc __f.__f_->destroy(); 12234684ddb6SLionel Sambuc __f.__f_ = __f_; 12244684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 12254684ddb6SLionel Sambuc } 12264684ddb6SLionel Sambuc else 12274684ddb6SLionel Sambuc _VSTD::swap(__f_, __f.__f_); 12284684ddb6SLionel Sambuc} 12294684ddb6SLionel Sambuc 12304684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 12314684ddb6SLionel Sambuc_Rp 12324684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const 12334684ddb6SLionel Sambuc{ 12344684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 12354684ddb6SLionel Sambuc if (__f_ == 0) 12364684ddb6SLionel Sambuc throw bad_function_call(); 12374684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 12384684ddb6SLionel Sambuc return (*__f_)(__a0, __a1); 12394684ddb6SLionel Sambuc} 12404684ddb6SLionel Sambuc 12414684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 12424684ddb6SLionel Sambuc 12434684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 12444684ddb6SLionel Sambucconst std::type_info& 12454684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::target_type() const 12464684ddb6SLionel Sambuc{ 12474684ddb6SLionel Sambuc if (__f_ == 0) 12484684ddb6SLionel Sambuc return typeid(void); 12494684ddb6SLionel Sambuc return __f_->target_type(); 12504684ddb6SLionel Sambuc} 12514684ddb6SLionel Sambuc 12524684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 12534684ddb6SLionel Sambuctemplate <typename _Tp> 12544684ddb6SLionel Sambuc_Tp* 12554684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::target() 12564684ddb6SLionel Sambuc{ 12574684ddb6SLionel Sambuc if (__f_ == 0) 12584684ddb6SLionel Sambuc return (_Tp*)0; 12594684ddb6SLionel Sambuc return (_Tp*)__f_->target(typeid(_Tp)); 12604684ddb6SLionel Sambuc} 12614684ddb6SLionel Sambuc 12624684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1> 12634684ddb6SLionel Sambuctemplate <typename _Tp> 12644684ddb6SLionel Sambucconst _Tp* 12654684ddb6SLionel Sambucfunction<_Rp(_A0, _A1)>::target() const 12664684ddb6SLionel Sambuc{ 12674684ddb6SLionel Sambuc if (__f_ == 0) 12684684ddb6SLionel Sambuc return (const _Tp*)0; 12694684ddb6SLionel Sambuc return (const _Tp*)__f_->target(typeid(_Tp)); 12704684ddb6SLionel Sambuc} 12714684ddb6SLionel Sambuc 12724684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 12734684ddb6SLionel Sambuc 12744684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 12754684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)> 12764684ddb6SLionel Sambuc{ 12774684ddb6SLionel Sambuc typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; 12784684ddb6SLionel Sambuc aligned_storage<3*sizeof(void*)>::type __buf_; 12794684ddb6SLionel Sambuc __base* __f_; 12804684ddb6SLionel Sambuc 12814684ddb6SLionel Sambucpublic: 12824684ddb6SLionel Sambuc typedef _Rp result_type; 12834684ddb6SLionel Sambuc 12844684ddb6SLionel Sambuc // 20.7.16.2.1, construct/copy/destroy: 12854684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} 12864684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} 12874684ddb6SLionel Sambuc function(const function&); 12884684ddb6SLionel Sambuc template<class _Fp> 12894684ddb6SLionel Sambuc function(_Fp, 12904684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type* = 0); 12914684ddb6SLionel Sambuc 12924684ddb6SLionel Sambuc template<class _Alloc> 12934684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12944684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&) : __f_(0) {} 12954684ddb6SLionel Sambuc template<class _Alloc> 12964684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 12974684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} 12984684ddb6SLionel Sambuc template<class _Alloc> 12994684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc&, const function&); 13004684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 13014684ddb6SLionel Sambuc function(allocator_arg_t, const _Alloc& __a, _Fp __f, 13024684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type* = 0); 13034684ddb6SLionel Sambuc 13044684ddb6SLionel Sambuc function& operator=(const function&); 13054684ddb6SLionel Sambuc function& operator=(nullptr_t); 13064684ddb6SLionel Sambuc template<class _Fp> 13074684ddb6SLionel Sambuc typename enable_if 13084684ddb6SLionel Sambuc < 13094684ddb6SLionel Sambuc !is_integral<_Fp>::value, 13104684ddb6SLionel Sambuc function& 13114684ddb6SLionel Sambuc >::type 13124684ddb6SLionel Sambuc operator=(_Fp); 13134684ddb6SLionel Sambuc 13144684ddb6SLionel Sambuc ~function(); 13154684ddb6SLionel Sambuc 13164684ddb6SLionel Sambuc // 20.7.16.2.2, function modifiers: 13174684ddb6SLionel Sambuc void swap(function&); 13184684ddb6SLionel Sambuc template<class _Fp, class _Alloc> 13194684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 13204684ddb6SLionel Sambuc void assign(_Fp __f, const _Alloc& __a) 13214684ddb6SLionel Sambuc {function(allocator_arg, __a, __f).swap(*this);} 13224684ddb6SLionel Sambuc 13234684ddb6SLionel Sambuc // 20.7.16.2.3, function capacity: 13244684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} 13254684ddb6SLionel Sambuc 13264684ddb6SLionel Sambucprivate: 13274684ddb6SLionel Sambuc // deleted overloads close possible hole in the type system 13284684ddb6SLionel Sambuc template<class _R2, class _B0, class _B1, class _B2> 13294684ddb6SLionel Sambuc bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; 13304684ddb6SLionel Sambuc template<class _R2, class _B0, class _B1, class _B2> 13314684ddb6SLionel Sambuc bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; 13324684ddb6SLionel Sambucpublic: 13334684ddb6SLionel Sambuc // 20.7.16.2.4, function invocation: 13344684ddb6SLionel Sambuc _Rp operator()(_A0, _A1, _A2) const; 13354684ddb6SLionel Sambuc 13364684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 13374684ddb6SLionel Sambuc // 20.7.16.2.5, function target access: 13384684ddb6SLionel Sambuc const std::type_info& target_type() const; 13394684ddb6SLionel Sambuc template <typename _Tp> _Tp* target(); 13404684ddb6SLionel Sambuc template <typename _Tp> const _Tp* target() const; 13414684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 13424684ddb6SLionel Sambuc}; 13434684ddb6SLionel Sambuc 13444684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 13454684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::function(const function& __f) 13464684ddb6SLionel Sambuc{ 13474684ddb6SLionel Sambuc if (__f.__f_ == 0) 13484684ddb6SLionel Sambuc __f_ = 0; 13494684ddb6SLionel Sambuc else if (__f.__f_ == (const __base*)&__f.__buf_) 13504684ddb6SLionel Sambuc { 13514684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 13524684ddb6SLionel Sambuc __f.__f_->__clone(__f_); 13534684ddb6SLionel Sambuc } 13544684ddb6SLionel Sambuc else 13554684ddb6SLionel Sambuc __f_ = __f.__f_->__clone(); 13564684ddb6SLionel Sambuc} 13574684ddb6SLionel Sambuc 13584684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 13594684ddb6SLionel Sambuctemplate<class _Alloc> 13604684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, 13614684ddb6SLionel Sambuc const function& __f) 13624684ddb6SLionel Sambuc{ 13634684ddb6SLionel Sambuc if (__f.__f_ == 0) 13644684ddb6SLionel Sambuc __f_ = 0; 13654684ddb6SLionel Sambuc else if (__f.__f_ == (const __base*)&__f.__buf_) 13664684ddb6SLionel Sambuc { 13674684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 13684684ddb6SLionel Sambuc __f.__f_->__clone(__f_); 13694684ddb6SLionel Sambuc } 13704684ddb6SLionel Sambuc else 13714684ddb6SLionel Sambuc __f_ = __f.__f_->__clone(); 13724684ddb6SLionel Sambuc} 13734684ddb6SLionel Sambuc 13744684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 13754684ddb6SLionel Sambuctemplate <class _Fp> 13764684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::function(_Fp __f, 13774684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type*) 13784684ddb6SLionel Sambuc : __f_(0) 13794684ddb6SLionel Sambuc{ 1380*0a6a1f1dSLionel Sambuc if (__function::__not_null(__f)) 13814684ddb6SLionel Sambuc { 13824684ddb6SLionel Sambuc typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; 13834684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 13844684ddb6SLionel Sambuc { 13854684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 13864684ddb6SLionel Sambuc ::new (__f_) _FF(__f); 13874684ddb6SLionel Sambuc } 13884684ddb6SLionel Sambuc else 13894684ddb6SLionel Sambuc { 13904684ddb6SLionel Sambuc typedef allocator<_FF> _Ap; 13914684ddb6SLionel Sambuc _Ap __a; 13924684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 13934684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 13944684ddb6SLionel Sambuc ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); 13954684ddb6SLionel Sambuc __f_ = __hold.release(); 13964684ddb6SLionel Sambuc } 13974684ddb6SLionel Sambuc } 13984684ddb6SLionel Sambuc} 13994684ddb6SLionel Sambuc 14004684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 14014684ddb6SLionel Sambuctemplate <class _Fp, class _Alloc> 14024684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 14034684ddb6SLionel Sambuc typename enable_if<!is_integral<_Fp>::value>::type*) 14044684ddb6SLionel Sambuc : __f_(0) 14054684ddb6SLionel Sambuc{ 14064684ddb6SLionel Sambuc typedef allocator_traits<_Alloc> __alloc_traits; 1407*0a6a1f1dSLionel Sambuc if (__function::__not_null(__f)) 14084684ddb6SLionel Sambuc { 14094684ddb6SLionel Sambuc typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; 14104684ddb6SLionel Sambuc if (sizeof(_FF) <= sizeof(__buf_)) 14114684ddb6SLionel Sambuc { 14124684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 1413*0a6a1f1dSLionel Sambuc ::new (__f_) _FF(__f, __a0); 14144684ddb6SLionel Sambuc } 14154684ddb6SLionel Sambuc else 14164684ddb6SLionel Sambuc { 1417*0a6a1f1dSLionel Sambuc typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; 14184684ddb6SLionel Sambuc _Ap __a(__a0); 14194684ddb6SLionel Sambuc typedef __allocator_destructor<_Ap> _Dp; 14204684ddb6SLionel Sambuc unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 14214684ddb6SLionel Sambuc ::new (__hold.get()) _FF(__f, _Alloc(__a)); 14224684ddb6SLionel Sambuc __f_ = __hold.release(); 14234684ddb6SLionel Sambuc } 14244684ddb6SLionel Sambuc } 14254684ddb6SLionel Sambuc} 14264684ddb6SLionel Sambuc 14274684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 14284684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>& 14294684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::operator=(const function& __f) 14304684ddb6SLionel Sambuc{ 14314684ddb6SLionel Sambuc function(__f).swap(*this); 14324684ddb6SLionel Sambuc return *this; 14334684ddb6SLionel Sambuc} 14344684ddb6SLionel Sambuc 14354684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 14364684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>& 14374684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t) 14384684ddb6SLionel Sambuc{ 14394684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 14404684ddb6SLionel Sambuc __f_->destroy(); 14414684ddb6SLionel Sambuc else if (__f_) 14424684ddb6SLionel Sambuc __f_->destroy_deallocate(); 14434684ddb6SLionel Sambuc __f_ = 0; 1444*0a6a1f1dSLionel Sambuc return *this; 14454684ddb6SLionel Sambuc} 14464684ddb6SLionel Sambuc 14474684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 14484684ddb6SLionel Sambuctemplate <class _Fp> 14494684ddb6SLionel Sambuctypename enable_if 14504684ddb6SLionel Sambuc< 14514684ddb6SLionel Sambuc !is_integral<_Fp>::value, 14524684ddb6SLionel Sambuc function<_Rp(_A0, _A1, _A2)>& 14534684ddb6SLionel Sambuc>::type 14544684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) 14554684ddb6SLionel Sambuc{ 14564684ddb6SLionel Sambuc function(_VSTD::move(__f)).swap(*this); 14574684ddb6SLionel Sambuc return *this; 14584684ddb6SLionel Sambuc} 14594684ddb6SLionel Sambuc 14604684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 14614684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::~function() 14624684ddb6SLionel Sambuc{ 14634684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_) 14644684ddb6SLionel Sambuc __f_->destroy(); 14654684ddb6SLionel Sambuc else if (__f_) 14664684ddb6SLionel Sambuc __f_->destroy_deallocate(); 14674684ddb6SLionel Sambuc} 14684684ddb6SLionel Sambuc 14694684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 14704684ddb6SLionel Sambucvoid 14714684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::swap(function& __f) 14724684ddb6SLionel Sambuc{ 14734684ddb6SLionel Sambuc if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 14744684ddb6SLionel Sambuc { 14754684ddb6SLionel Sambuc typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 14764684ddb6SLionel Sambuc __base* __t = (__base*)&__tempbuf; 14774684ddb6SLionel Sambuc __f_->__clone(__t); 14784684ddb6SLionel Sambuc __f_->destroy(); 14794684ddb6SLionel Sambuc __f_ = 0; 14804684ddb6SLionel Sambuc __f.__f_->__clone((__base*)&__buf_); 14814684ddb6SLionel Sambuc __f.__f_->destroy(); 14824684ddb6SLionel Sambuc __f.__f_ = 0; 14834684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 14844684ddb6SLionel Sambuc __t->__clone((__base*)&__f.__buf_); 14854684ddb6SLionel Sambuc __t->destroy(); 14864684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 14874684ddb6SLionel Sambuc } 14884684ddb6SLionel Sambuc else if (__f_ == (__base*)&__buf_) 14894684ddb6SLionel Sambuc { 14904684ddb6SLionel Sambuc __f_->__clone((__base*)&__f.__buf_); 14914684ddb6SLionel Sambuc __f_->destroy(); 14924684ddb6SLionel Sambuc __f_ = __f.__f_; 14934684ddb6SLionel Sambuc __f.__f_ = (__base*)&__f.__buf_; 14944684ddb6SLionel Sambuc } 14954684ddb6SLionel Sambuc else if (__f.__f_ == (__base*)&__f.__buf_) 14964684ddb6SLionel Sambuc { 14974684ddb6SLionel Sambuc __f.__f_->__clone((__base*)&__buf_); 14984684ddb6SLionel Sambuc __f.__f_->destroy(); 14994684ddb6SLionel Sambuc __f.__f_ = __f_; 15004684ddb6SLionel Sambuc __f_ = (__base*)&__buf_; 15014684ddb6SLionel Sambuc } 15024684ddb6SLionel Sambuc else 15034684ddb6SLionel Sambuc _VSTD::swap(__f_, __f.__f_); 15044684ddb6SLionel Sambuc} 15054684ddb6SLionel Sambuc 15064684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 15074684ddb6SLionel Sambuc_Rp 15084684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const 15094684ddb6SLionel Sambuc{ 15104684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 15114684ddb6SLionel Sambuc if (__f_ == 0) 15124684ddb6SLionel Sambuc throw bad_function_call(); 15134684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 15144684ddb6SLionel Sambuc return (*__f_)(__a0, __a1, __a2); 15154684ddb6SLionel Sambuc} 15164684ddb6SLionel Sambuc 15174684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_RTTI 15184684ddb6SLionel Sambuc 15194684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 15204684ddb6SLionel Sambucconst std::type_info& 15214684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::target_type() const 15224684ddb6SLionel Sambuc{ 15234684ddb6SLionel Sambuc if (__f_ == 0) 15244684ddb6SLionel Sambuc return typeid(void); 15254684ddb6SLionel Sambuc return __f_->target_type(); 15264684ddb6SLionel Sambuc} 15274684ddb6SLionel Sambuc 15284684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 15294684ddb6SLionel Sambuctemplate <typename _Tp> 15304684ddb6SLionel Sambuc_Tp* 15314684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::target() 15324684ddb6SLionel Sambuc{ 15334684ddb6SLionel Sambuc if (__f_ == 0) 15344684ddb6SLionel Sambuc return (_Tp*)0; 15354684ddb6SLionel Sambuc return (_Tp*)__f_->target(typeid(_Tp)); 15364684ddb6SLionel Sambuc} 15374684ddb6SLionel Sambuc 15384684ddb6SLionel Sambuctemplate<class _Rp, class _A0, class _A1, class _A2> 15394684ddb6SLionel Sambuctemplate <typename _Tp> 15404684ddb6SLionel Sambucconst _Tp* 15414684ddb6SLionel Sambucfunction<_Rp(_A0, _A1, _A2)>::target() const 15424684ddb6SLionel Sambuc{ 15434684ddb6SLionel Sambuc if (__f_ == 0) 15444684ddb6SLionel Sambuc return (const _Tp*)0; 15454684ddb6SLionel Sambuc return (const _Tp*)__f_->target(typeid(_Tp)); 15464684ddb6SLionel Sambuc} 15474684ddb6SLionel Sambuc 15484684ddb6SLionel Sambuc#endif // _LIBCPP_NO_RTTI 15494684ddb6SLionel Sambuc 15504684ddb6SLionel Sambuctemplate <class _Fp> 15514684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15524684ddb6SLionel Sambucbool 15534684ddb6SLionel Sambucoperator==(const function<_Fp>& __f, nullptr_t) {return !__f;} 15544684ddb6SLionel Sambuc 15554684ddb6SLionel Sambuctemplate <class _Fp> 15564684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15574684ddb6SLionel Sambucbool 15584684ddb6SLionel Sambucoperator==(nullptr_t, const function<_Fp>& __f) {return !__f;} 15594684ddb6SLionel Sambuc 15604684ddb6SLionel Sambuctemplate <class _Fp> 15614684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15624684ddb6SLionel Sambucbool 15634684ddb6SLionel Sambucoperator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} 15644684ddb6SLionel Sambuc 15654684ddb6SLionel Sambuctemplate <class _Fp> 15664684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15674684ddb6SLionel Sambucbool 15684684ddb6SLionel Sambucoperator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} 15694684ddb6SLionel Sambuc 15704684ddb6SLionel Sambuctemplate <class _Fp> 15714684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 15724684ddb6SLionel Sambucvoid 15734684ddb6SLionel Sambucswap(function<_Fp>& __x, function<_Fp>& __y) 15744684ddb6SLionel Sambuc{return __x.swap(__y);} 15754684ddb6SLionel Sambuc 15764684ddb6SLionel Sambuc#endif // _LIBCPP_FUNCTIONAL_03 1577