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