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> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 448 | class _LIBCPP_TEMPLATE_VIS 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 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 455 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 456 | |
| 457 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 458 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 459 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 460 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 461 | template<class _Fp> |
| 462 | function(_Fp, |
| 463 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 464 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 465 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 466 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 467 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 468 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 469 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 470 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 471 | template<class _Alloc> |
| 472 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 473 | template<class _Fp, class _Alloc> |
| 474 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 475 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | |
| 477 | function& operator=(const function&); |
| 478 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 479 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 480 | typename enable_if |
| 481 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 482 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | function& |
| 484 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 485 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 486 | |
| 487 | ~function(); |
| 488 | |
| 489 | // 20.7.16.2.2, function modifiers: |
| 490 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 491 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 492 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 493 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 494 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 495 | |
| 496 | // 20.7.16.2.3, function capacity: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 497 | _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 498 | |
| 499 | private: |
| 500 | // deleted overloads close possible hole in the type system |
| 501 | template<class _R2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 502 | bool operator==(const function<_R2()>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | template<class _R2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 504 | bool operator!=(const function<_R2()>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 505 | public: |
| 506 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 507 | _Rp operator()() const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 508 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 509 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | // 20.7.16.2.5, function target access: |
| 511 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 512 | template <typename _Tp> _Tp* target(); |
| 513 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 514 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | }; |
| 516 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 517 | template<class _Rp> |
| 518 | function<_Rp()>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 519 | { |
| 520 | if (__f.__f_ == 0) |
| 521 | __f_ = 0; |
| 522 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 523 | { |
| 524 | __f_ = (__base*)&__buf_; |
| 525 | __f.__f_->__clone(__f_); |
| 526 | } |
| 527 | else |
| 528 | __f_ = __f.__f_->__clone(); |
| 529 | } |
| 530 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 531 | template<class _Rp> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 532 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 533 | function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 534 | { |
| 535 | if (__f.__f_ == 0) |
| 536 | __f_ = 0; |
| 537 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 538 | { |
| 539 | __f_ = (__base*)&__buf_; |
| 540 | __f.__f_->__clone(__f_); |
| 541 | } |
| 542 | else |
| 543 | __f_ = __f.__f_->__clone(); |
| 544 | } |
| 545 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 546 | template<class _Rp> |
| 547 | template <class _Fp> |
| 548 | function<_Rp()>::function(_Fp __f, |
| 549 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | : __f_(0) |
| 551 | { |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 552 | if (__function::__not_null(__f)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 553 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 554 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 555 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 556 | { |
| 557 | __f_ = (__base*)&__buf_; |
| 558 | ::new (__f_) _FF(__f); |
| 559 | } |
| 560 | else |
| 561 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 562 | typedef allocator<_FF> _Ap; |
| 563 | _Ap __a; |
| 564 | typedef __allocator_destructor<_Ap> _Dp; |
| 565 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 566 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 567 | __f_ = __hold.release(); |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 572 | template<class _Rp> |
| 573 | template <class _Fp, class _Alloc> |
| 574 | function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 575 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 576 | : __f_(0) |
| 577 | { |
| 578 | typedef allocator_traits<_Alloc> __alloc_traits; |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 579 | if (__function::__not_null(__f)) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 580 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 581 | typedef __function::__func<_Fp, _Alloc, _Rp()> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 582 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 583 | { |
| 584 | __f_ = (__base*)&__buf_; |
Eric Fiselier | b05f059 | 2015-06-14 23:30:09 +0000 | [diff] [blame] | 585 | ::new (__f_) _FF(__f, __a0); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 586 | } |
| 587 | else |
| 588 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 589 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 590 | _Ap __a(__a0); |
| 591 | typedef __allocator_destructor<_Ap> _Dp; |
| 592 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 593 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 594 | __f_ = __hold.release(); |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 599 | template<class _Rp> |
| 600 | function<_Rp()>& |
| 601 | function<_Rp()>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 602 | { |
| 603 | function(__f).swap(*this); |
| 604 | return *this; |
| 605 | } |
| 606 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 607 | template<class _Rp> |
| 608 | function<_Rp()>& |
| 609 | function<_Rp()>::operator=(nullptr_t) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 610 | { |
| 611 | if (__f_ == (__base*)&__buf_) |
| 612 | __f_->destroy(); |
| 613 | else if (__f_) |
| 614 | __f_->destroy_deallocate(); |
| 615 | __f_ = 0; |
Eric Fiselier | fa97c2e | 2015-06-02 01:31:33 +0000 | [diff] [blame] | 616 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 619 | template<class _Rp> |
| 620 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 621 | typename enable_if |
| 622 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 623 | !is_integral<_Fp>::value, |
| 624 | function<_Rp()>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 625 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 626 | function<_Rp()>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 627 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 628 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | return *this; |
| 630 | } |
| 631 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 632 | template<class _Rp> |
| 633 | function<_Rp()>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | { |
| 635 | if (__f_ == (__base*)&__buf_) |
| 636 | __f_->destroy(); |
| 637 | else if (__f_) |
| 638 | __f_->destroy_deallocate(); |
| 639 | } |
| 640 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 641 | template<class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 642 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 643 | function<_Rp()>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 644 | { |
Eric Fiselier | 152e5e6 | 2016-12-29 20:03:55 +0000 | [diff] [blame] | 645 | if (_VSTD::addressof(__f) == this) |
| 646 | return; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 648 | { |
| 649 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 650 | __base* __t = (__base*)&__tempbuf; |
| 651 | __f_->__clone(__t); |
| 652 | __f_->destroy(); |
| 653 | __f_ = 0; |
| 654 | __f.__f_->__clone((__base*)&__buf_); |
| 655 | __f.__f_->destroy(); |
| 656 | __f.__f_ = 0; |
| 657 | __f_ = (__base*)&__buf_; |
| 658 | __t->__clone((__base*)&__f.__buf_); |
| 659 | __t->destroy(); |
| 660 | __f.__f_ = (__base*)&__f.__buf_; |
| 661 | } |
| 662 | else if (__f_ == (__base*)&__buf_) |
| 663 | { |
| 664 | __f_->__clone((__base*)&__f.__buf_); |
| 665 | __f_->destroy(); |
| 666 | __f_ = __f.__f_; |
| 667 | __f.__f_ = (__base*)&__f.__buf_; |
| 668 | } |
| 669 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 670 | { |
| 671 | __f.__f_->__clone((__base*)&__buf_); |
| 672 | __f.__f_->destroy(); |
| 673 | __f.__f_ = __f_; |
| 674 | __f_ = (__base*)&__buf_; |
| 675 | } |
| 676 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 677 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 680 | template<class _Rp> |
| 681 | _Rp |
| 682 | function<_Rp()>::operator()() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 683 | { |
| 684 | if (__f_ == 0) |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 685 | __throw_bad_function_call(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 686 | return (*__f_)(); |
| 687 | } |
| 688 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 689 | #ifndef _LIBCPP_NO_RTTI |
| 690 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 691 | template<class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 692 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 693 | function<_Rp()>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 694 | { |
| 695 | if (__f_ == 0) |
| 696 | return typeid(void); |
| 697 | return __f_->target_type(); |
| 698 | } |
| 699 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 700 | template<class _Rp> |
| 701 | template <typename _Tp> |
| 702 | _Tp* |
| 703 | function<_Rp()>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 704 | { |
| 705 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 706 | return (_Tp*)0; |
Marshall Clow | ff5f9b2 | 2017-06-14 20:00:36 +0000 | [diff] [blame] | 707 | return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 710 | template<class _Rp> |
| 711 | template <typename _Tp> |
| 712 | const _Tp* |
| 713 | function<_Rp()>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 714 | { |
| 715 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 716 | return (const _Tp*)0; |
| 717 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 720 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 721 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 722 | template<class _Rp, class _A0> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 723 | class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0)> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 724 | : public unary_function<_A0, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 725 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 726 | typedef __function::__base<_Rp(_A0)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 727 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 728 | __base* __f_; |
| 729 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 730 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 731 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 732 | |
| 733 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 734 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 735 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 736 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 737 | template<class _Fp> |
| 738 | function(_Fp, |
| 739 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 740 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 741 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 742 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 743 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 744 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 745 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 746 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 747 | template<class _Alloc> |
| 748 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 749 | template<class _Fp, class _Alloc> |
| 750 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 751 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 752 | |
| 753 | function& operator=(const function&); |
| 754 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 755 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 756 | typename enable_if |
| 757 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 758 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 759 | function& |
| 760 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 761 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 762 | |
| 763 | ~function(); |
| 764 | |
| 765 | // 20.7.16.2.2, function modifiers: |
| 766 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 767 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 768 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 769 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 770 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 771 | |
| 772 | // 20.7.16.2.3, function capacity: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 773 | _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 774 | |
| 775 | private: |
| 776 | // deleted overloads close possible hole in the type system |
| 777 | template<class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 778 | bool operator==(const function<_R2(_B0)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 779 | template<class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 780 | bool operator!=(const function<_R2(_B0)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 781 | public: |
| 782 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 783 | _Rp operator()(_A0) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 784 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 785 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 786 | // 20.7.16.2.5, function target access: |
| 787 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 788 | template <typename _Tp> _Tp* target(); |
| 789 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 790 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | }; |
| 792 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 793 | template<class _Rp, class _A0> |
| 794 | function<_Rp(_A0)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 795 | { |
| 796 | if (__f.__f_ == 0) |
| 797 | __f_ = 0; |
| 798 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 799 | { |
| 800 | __f_ = (__base*)&__buf_; |
| 801 | __f.__f_->__clone(__f_); |
| 802 | } |
| 803 | else |
| 804 | __f_ = __f.__f_->__clone(); |
| 805 | } |
| 806 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 807 | template<class _Rp, class _A0> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 808 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 809 | function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 810 | { |
| 811 | if (__f.__f_ == 0) |
| 812 | __f_ = 0; |
| 813 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 814 | { |
| 815 | __f_ = (__base*)&__buf_; |
| 816 | __f.__f_->__clone(__f_); |
| 817 | } |
| 818 | else |
| 819 | __f_ = __f.__f_->__clone(); |
| 820 | } |
| 821 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 822 | template<class _Rp, class _A0> |
| 823 | template <class _Fp> |
| 824 | function<_Rp(_A0)>::function(_Fp __f, |
| 825 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 826 | : __f_(0) |
| 827 | { |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 828 | if (__function::__not_null(__f)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 829 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 830 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 832 | { |
| 833 | __f_ = (__base*)&__buf_; |
| 834 | ::new (__f_) _FF(__f); |
| 835 | } |
| 836 | else |
| 837 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 838 | typedef allocator<_FF> _Ap; |
| 839 | _Ap __a; |
| 840 | typedef __allocator_destructor<_Ap> _Dp; |
| 841 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 842 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 843 | __f_ = __hold.release(); |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 848 | template<class _Rp, class _A0> |
| 849 | template <class _Fp, class _Alloc> |
| 850 | function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 851 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 852 | : __f_(0) |
| 853 | { |
| 854 | typedef allocator_traits<_Alloc> __alloc_traits; |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 855 | if (__function::__not_null(__f)) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 856 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 857 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 858 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 859 | { |
| 860 | __f_ = (__base*)&__buf_; |
Eric Fiselier | b05f059 | 2015-06-14 23:30:09 +0000 | [diff] [blame] | 861 | ::new (__f_) _FF(__f, __a0); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 862 | } |
| 863 | else |
| 864 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 865 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 866 | _Ap __a(__a0); |
| 867 | typedef __allocator_destructor<_Ap> _Dp; |
| 868 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 869 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 870 | __f_ = __hold.release(); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 875 | template<class _Rp, class _A0> |
| 876 | function<_Rp(_A0)>& |
| 877 | function<_Rp(_A0)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 878 | { |
| 879 | function(__f).swap(*this); |
| 880 | return *this; |
| 881 | } |
| 882 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 883 | template<class _Rp, class _A0> |
| 884 | function<_Rp(_A0)>& |
| 885 | function<_Rp(_A0)>::operator=(nullptr_t) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 886 | { |
| 887 | if (__f_ == (__base*)&__buf_) |
| 888 | __f_->destroy(); |
| 889 | else if (__f_) |
| 890 | __f_->destroy_deallocate(); |
| 891 | __f_ = 0; |
Eric Fiselier | fa97c2e | 2015-06-02 01:31:33 +0000 | [diff] [blame] | 892 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 895 | template<class _Rp, class _A0> |
| 896 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 897 | typename enable_if |
| 898 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 899 | !is_integral<_Fp>::value, |
| 900 | function<_Rp(_A0)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 901 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 902 | function<_Rp(_A0)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 903 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 904 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 905 | return *this; |
| 906 | } |
| 907 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 908 | template<class _Rp, class _A0> |
| 909 | function<_Rp(_A0)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 910 | { |
| 911 | if (__f_ == (__base*)&__buf_) |
| 912 | __f_->destroy(); |
| 913 | else if (__f_) |
| 914 | __f_->destroy_deallocate(); |
| 915 | } |
| 916 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 917 | template<class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 918 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 919 | function<_Rp(_A0)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 920 | { |
Eric Fiselier | 152e5e6 | 2016-12-29 20:03:55 +0000 | [diff] [blame] | 921 | if (_VSTD::addressof(__f) == this) |
| 922 | return; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 923 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 924 | { |
| 925 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 926 | __base* __t = (__base*)&__tempbuf; |
| 927 | __f_->__clone(__t); |
| 928 | __f_->destroy(); |
| 929 | __f_ = 0; |
| 930 | __f.__f_->__clone((__base*)&__buf_); |
| 931 | __f.__f_->destroy(); |
| 932 | __f.__f_ = 0; |
| 933 | __f_ = (__base*)&__buf_; |
| 934 | __t->__clone((__base*)&__f.__buf_); |
| 935 | __t->destroy(); |
| 936 | __f.__f_ = (__base*)&__f.__buf_; |
| 937 | } |
| 938 | else if (__f_ == (__base*)&__buf_) |
| 939 | { |
| 940 | __f_->__clone((__base*)&__f.__buf_); |
| 941 | __f_->destroy(); |
| 942 | __f_ = __f.__f_; |
| 943 | __f.__f_ = (__base*)&__f.__buf_; |
| 944 | } |
| 945 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 946 | { |
| 947 | __f.__f_->__clone((__base*)&__buf_); |
| 948 | __f.__f_->destroy(); |
| 949 | __f.__f_ = __f_; |
| 950 | __f_ = (__base*)&__buf_; |
| 951 | } |
| 952 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 953 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 956 | template<class _Rp, class _A0> |
| 957 | _Rp |
| 958 | function<_Rp(_A0)>::operator()(_A0 __a0) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | { |
| 960 | if (__f_ == 0) |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 961 | __throw_bad_function_call(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 962 | return (*__f_)(__a0); |
| 963 | } |
| 964 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 965 | #ifndef _LIBCPP_NO_RTTI |
| 966 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 967 | template<class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 968 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 969 | function<_Rp(_A0)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 970 | { |
| 971 | if (__f_ == 0) |
| 972 | return typeid(void); |
| 973 | return __f_->target_type(); |
| 974 | } |
| 975 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 976 | template<class _Rp, class _A0> |
| 977 | template <typename _Tp> |
| 978 | _Tp* |
| 979 | function<_Rp(_A0)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 980 | { |
| 981 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 982 | return (_Tp*)0; |
Marshall Clow | ff5f9b2 | 2017-06-14 20:00:36 +0000 | [diff] [blame] | 983 | return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 986 | template<class _Rp, class _A0> |
| 987 | template <typename _Tp> |
| 988 | const _Tp* |
| 989 | function<_Rp(_A0)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 990 | { |
| 991 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 992 | return (const _Tp*)0; |
| 993 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 996 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 997 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 998 | template<class _Rp, class _A0, class _A1> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 999 | class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1)> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1000 | : public binary_function<_A0, _A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1001 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1002 | typedef __function::__base<_Rp(_A0, _A1)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1003 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1004 | __base* __f_; |
| 1005 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1006 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1007 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1008 | |
| 1009 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1010 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 1011 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1012 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1013 | template<class _Fp> |
| 1014 | function(_Fp, |
| 1015 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1016 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1017 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1018 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1019 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 1020 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1021 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1022 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 1023 | template<class _Alloc> |
| 1024 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1025 | template<class _Fp, class _Alloc> |
| 1026 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 1027 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1028 | |
| 1029 | function& operator=(const function&); |
| 1030 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1031 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1032 | typename enable_if |
| 1033 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1034 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1035 | function& |
| 1036 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1037 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1038 | |
| 1039 | ~function(); |
| 1040 | |
| 1041 | // 20.7.16.2.2, function modifiers: |
| 1042 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1043 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1044 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1045 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1046 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1047 | |
| 1048 | // 20.7.16.2.3, function capacity: |
| 1049 | operator bool() const {return __f_;} |
| 1050 | |
| 1051 | private: |
| 1052 | // deleted overloads close possible hole in the type system |
| 1053 | template<class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1054 | bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1055 | template<class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1056 | bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1057 | public: |
| 1058 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1059 | _Rp operator()(_A0, _A1) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1061 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1062 | // 20.7.16.2.5, function target access: |
| 1063 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1064 | template <typename _Tp> _Tp* target(); |
| 1065 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1066 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1067 | }; |
| 1068 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1069 | template<class _Rp, class _A0, class _A1> |
| 1070 | function<_Rp(_A0, _A1)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1071 | { |
| 1072 | if (__f.__f_ == 0) |
| 1073 | __f_ = 0; |
| 1074 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1075 | { |
| 1076 | __f_ = (__base*)&__buf_; |
| 1077 | __f.__f_->__clone(__f_); |
| 1078 | } |
| 1079 | else |
| 1080 | __f_ = __f.__f_->__clone(); |
| 1081 | } |
| 1082 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1083 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1084 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1085 | 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] | 1086 | { |
| 1087 | if (__f.__f_ == 0) |
| 1088 | __f_ = 0; |
| 1089 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1090 | { |
| 1091 | __f_ = (__base*)&__buf_; |
| 1092 | __f.__f_->__clone(__f_); |
| 1093 | } |
| 1094 | else |
| 1095 | __f_ = __f.__f_->__clone(); |
| 1096 | } |
| 1097 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1098 | template<class _Rp, class _A0, class _A1> |
| 1099 | template <class _Fp> |
| 1100 | function<_Rp(_A0, _A1)>::function(_Fp __f, |
| 1101 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1102 | : __f_(0) |
| 1103 | { |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1104 | if (__function::__not_null(__f)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1105 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1106 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1107 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1108 | { |
| 1109 | __f_ = (__base*)&__buf_; |
| 1110 | ::new (__f_) _FF(__f); |
| 1111 | } |
| 1112 | else |
| 1113 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1114 | typedef allocator<_FF> _Ap; |
| 1115 | _Ap __a; |
| 1116 | typedef __allocator_destructor<_Ap> _Dp; |
| 1117 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1118 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1119 | __f_ = __hold.release(); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1124 | template<class _Rp, class _A0, class _A1> |
| 1125 | template <class _Fp, class _Alloc> |
| 1126 | function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1127 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1128 | : __f_(0) |
| 1129 | { |
| 1130 | typedef allocator_traits<_Alloc> __alloc_traits; |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1131 | if (__function::__not_null(__f)) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1132 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1133 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1134 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1135 | { |
| 1136 | __f_ = (__base*)&__buf_; |
Eric Fiselier | b05f059 | 2015-06-14 23:30:09 +0000 | [diff] [blame] | 1137 | ::new (__f_) _FF(__f, __a0); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1138 | } |
| 1139 | else |
| 1140 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1141 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1142 | _Ap __a(__a0); |
| 1143 | typedef __allocator_destructor<_Ap> _Dp; |
| 1144 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1145 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 1146 | __f_ = __hold.release(); |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1151 | template<class _Rp, class _A0, class _A1> |
| 1152 | function<_Rp(_A0, _A1)>& |
| 1153 | function<_Rp(_A0, _A1)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | { |
| 1155 | function(__f).swap(*this); |
| 1156 | return *this; |
| 1157 | } |
| 1158 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1159 | template<class _Rp, class _A0, class _A1> |
| 1160 | function<_Rp(_A0, _A1)>& |
| 1161 | function<_Rp(_A0, _A1)>::operator=(nullptr_t) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1162 | { |
| 1163 | if (__f_ == (__base*)&__buf_) |
| 1164 | __f_->destroy(); |
| 1165 | else if (__f_) |
| 1166 | __f_->destroy_deallocate(); |
| 1167 | __f_ = 0; |
Eric Fiselier | fa97c2e | 2015-06-02 01:31:33 +0000 | [diff] [blame] | 1168 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1171 | template<class _Rp, class _A0, class _A1> |
| 1172 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1173 | typename enable_if |
| 1174 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1175 | !is_integral<_Fp>::value, |
| 1176 | function<_Rp(_A0, _A1)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1177 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1178 | function<_Rp(_A0, _A1)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1179 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1180 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1181 | return *this; |
| 1182 | } |
| 1183 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1184 | template<class _Rp, class _A0, class _A1> |
| 1185 | function<_Rp(_A0, _A1)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1186 | { |
| 1187 | if (__f_ == (__base*)&__buf_) |
| 1188 | __f_->destroy(); |
| 1189 | else if (__f_) |
| 1190 | __f_->destroy_deallocate(); |
| 1191 | } |
| 1192 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1193 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1194 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1195 | function<_Rp(_A0, _A1)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1196 | { |
Eric Fiselier | 152e5e6 | 2016-12-29 20:03:55 +0000 | [diff] [blame] | 1197 | if (_VSTD::addressof(__f) == this) |
| 1198 | return; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1199 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1200 | { |
| 1201 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1202 | __base* __t = (__base*)&__tempbuf; |
| 1203 | __f_->__clone(__t); |
| 1204 | __f_->destroy(); |
| 1205 | __f_ = 0; |
| 1206 | __f.__f_->__clone((__base*)&__buf_); |
| 1207 | __f.__f_->destroy(); |
| 1208 | __f.__f_ = 0; |
| 1209 | __f_ = (__base*)&__buf_; |
| 1210 | __t->__clone((__base*)&__f.__buf_); |
| 1211 | __t->destroy(); |
| 1212 | __f.__f_ = (__base*)&__f.__buf_; |
| 1213 | } |
| 1214 | else if (__f_ == (__base*)&__buf_) |
| 1215 | { |
| 1216 | __f_->__clone((__base*)&__f.__buf_); |
| 1217 | __f_->destroy(); |
| 1218 | __f_ = __f.__f_; |
| 1219 | __f.__f_ = (__base*)&__f.__buf_; |
| 1220 | } |
| 1221 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1222 | { |
| 1223 | __f.__f_->__clone((__base*)&__buf_); |
| 1224 | __f.__f_->destroy(); |
| 1225 | __f.__f_ = __f_; |
| 1226 | __f_ = (__base*)&__buf_; |
| 1227 | } |
| 1228 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1229 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1232 | template<class _Rp, class _A0, class _A1> |
| 1233 | _Rp |
| 1234 | function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1235 | { |
| 1236 | if (__f_ == 0) |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1237 | __throw_bad_function_call(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1238 | return (*__f_)(__a0, __a1); |
| 1239 | } |
| 1240 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1241 | #ifndef _LIBCPP_NO_RTTI |
| 1242 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1243 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1244 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1245 | function<_Rp(_A0, _A1)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | { |
| 1247 | if (__f_ == 0) |
| 1248 | return typeid(void); |
| 1249 | return __f_->target_type(); |
| 1250 | } |
| 1251 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1252 | template<class _Rp, class _A0, class _A1> |
| 1253 | template <typename _Tp> |
| 1254 | _Tp* |
| 1255 | function<_Rp(_A0, _A1)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1256 | { |
| 1257 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1258 | return (_Tp*)0; |
Marshall Clow | ff5f9b2 | 2017-06-14 20:00:36 +0000 | [diff] [blame] | 1259 | return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1262 | template<class _Rp, class _A0, class _A1> |
| 1263 | template <typename _Tp> |
| 1264 | const _Tp* |
| 1265 | function<_Rp(_A0, _A1)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1266 | { |
| 1267 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1268 | return (const _Tp*)0; |
| 1269 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1272 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1273 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1274 | template<class _Rp, class _A0, class _A1, class _A2> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1275 | class _LIBCPP_TEMPLATE_VIS function<_Rp(_A0, _A1, _A2)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1276 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1277 | typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1278 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1279 | __base* __f_; |
| 1280 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1281 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1282 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1283 | |
| 1284 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1285 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 1286 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1287 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1288 | template<class _Fp> |
| 1289 | function(_Fp, |
| 1290 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1291 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1292 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1293 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1294 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 1295 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1297 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 1298 | template<class _Alloc> |
| 1299 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1300 | template<class _Fp, class _Alloc> |
| 1301 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 1302 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1303 | |
| 1304 | function& operator=(const function&); |
| 1305 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1306 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1307 | typename enable_if |
| 1308 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1309 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1310 | function& |
| 1311 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1312 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1313 | |
| 1314 | ~function(); |
| 1315 | |
| 1316 | // 20.7.16.2.2, function modifiers: |
| 1317 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1318 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1320 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1321 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1322 | |
| 1323 | // 20.7.16.2.3, function capacity: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1324 | _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | |
| 1326 | private: |
| 1327 | // deleted overloads close possible hole in the type system |
| 1328 | template<class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1329 | bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1330 | template<class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1331 | bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1332 | public: |
| 1333 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1334 | _Rp operator()(_A0, _A1, _A2) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1335 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1336 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1337 | // 20.7.16.2.5, function target access: |
| 1338 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1339 | template <typename _Tp> _Tp* target(); |
| 1340 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1341 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1342 | }; |
| 1343 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1344 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1345 | function<_Rp(_A0, _A1, _A2)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1346 | { |
| 1347 | if (__f.__f_ == 0) |
| 1348 | __f_ = 0; |
| 1349 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1350 | { |
| 1351 | __f_ = (__base*)&__buf_; |
| 1352 | __f.__f_->__clone(__f_); |
| 1353 | } |
| 1354 | else |
| 1355 | __f_ = __f.__f_->__clone(); |
| 1356 | } |
| 1357 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1358 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1359 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1360 | function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1361 | const function& __f) |
| 1362 | { |
| 1363 | if (__f.__f_ == 0) |
| 1364 | __f_ = 0; |
| 1365 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1366 | { |
| 1367 | __f_ = (__base*)&__buf_; |
| 1368 | __f.__f_->__clone(__f_); |
| 1369 | } |
| 1370 | else |
| 1371 | __f_ = __f.__f_->__clone(); |
| 1372 | } |
| 1373 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1374 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1375 | template <class _Fp> |
| 1376 | function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, |
| 1377 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1378 | : __f_(0) |
| 1379 | { |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1380 | if (__function::__not_null(__f)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1381 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1382 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1383 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1384 | { |
| 1385 | __f_ = (__base*)&__buf_; |
| 1386 | ::new (__f_) _FF(__f); |
| 1387 | } |
| 1388 | else |
| 1389 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1390 | typedef allocator<_FF> _Ap; |
| 1391 | _Ap __a; |
| 1392 | typedef __allocator_destructor<_Ap> _Dp; |
| 1393 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1394 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1395 | __f_ = __hold.release(); |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1400 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1401 | template <class _Fp, class _Alloc> |
| 1402 | function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1403 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1404 | : __f_(0) |
| 1405 | { |
| 1406 | typedef allocator_traits<_Alloc> __alloc_traits; |
Eric Fiselier | 8e03071 | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1407 | if (__function::__not_null(__f)) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1408 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1409 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1410 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1411 | { |
| 1412 | __f_ = (__base*)&__buf_; |
Eric Fiselier | b05f059 | 2015-06-14 23:30:09 +0000 | [diff] [blame] | 1413 | ::new (__f_) _FF(__f, __a0); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1414 | } |
| 1415 | else |
| 1416 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1417 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1418 | _Ap __a(__a0); |
| 1419 | typedef __allocator_destructor<_Ap> _Dp; |
| 1420 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1421 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 1422 | __f_ = __hold.release(); |
| 1423 | } |
| 1424 | } |
| 1425 | } |
| 1426 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1427 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1428 | function<_Rp(_A0, _A1, _A2)>& |
| 1429 | function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | { |
| 1431 | function(__f).swap(*this); |
| 1432 | return *this; |
| 1433 | } |
| 1434 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1435 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1436 | function<_Rp(_A0, _A1, _A2)>& |
| 1437 | function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | { |
| 1439 | if (__f_ == (__base*)&__buf_) |
| 1440 | __f_->destroy(); |
| 1441 | else if (__f_) |
| 1442 | __f_->destroy_deallocate(); |
| 1443 | __f_ = 0; |
Eric Fiselier | fa97c2e | 2015-06-02 01:31:33 +0000 | [diff] [blame] | 1444 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1447 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1448 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1449 | typename enable_if |
| 1450 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1451 | !is_integral<_Fp>::value, |
| 1452 | function<_Rp(_A0, _A1, _A2)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1453 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1454 | function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1456 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1457 | return *this; |
| 1458 | } |
| 1459 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1460 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1461 | function<_Rp(_A0, _A1, _A2)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | { |
| 1463 | if (__f_ == (__base*)&__buf_) |
| 1464 | __f_->destroy(); |
| 1465 | else if (__f_) |
| 1466 | __f_->destroy_deallocate(); |
| 1467 | } |
| 1468 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1469 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1470 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1471 | function<_Rp(_A0, _A1, _A2)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1472 | { |
Eric Fiselier | 152e5e6 | 2016-12-29 20:03:55 +0000 | [diff] [blame] | 1473 | if (_VSTD::addressof(__f) == this) |
| 1474 | return; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1476 | { |
| 1477 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1478 | __base* __t = (__base*)&__tempbuf; |
| 1479 | __f_->__clone(__t); |
| 1480 | __f_->destroy(); |
| 1481 | __f_ = 0; |
| 1482 | __f.__f_->__clone((__base*)&__buf_); |
| 1483 | __f.__f_->destroy(); |
| 1484 | __f.__f_ = 0; |
| 1485 | __f_ = (__base*)&__buf_; |
| 1486 | __t->__clone((__base*)&__f.__buf_); |
| 1487 | __t->destroy(); |
| 1488 | __f.__f_ = (__base*)&__f.__buf_; |
| 1489 | } |
| 1490 | else if (__f_ == (__base*)&__buf_) |
| 1491 | { |
| 1492 | __f_->__clone((__base*)&__f.__buf_); |
| 1493 | __f_->destroy(); |
| 1494 | __f_ = __f.__f_; |
| 1495 | __f.__f_ = (__base*)&__f.__buf_; |
| 1496 | } |
| 1497 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1498 | { |
| 1499 | __f.__f_->__clone((__base*)&__buf_); |
| 1500 | __f.__f_->destroy(); |
| 1501 | __f.__f_ = __f_; |
| 1502 | __f_ = (__base*)&__buf_; |
| 1503 | } |
| 1504 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1505 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1508 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1509 | _Rp |
| 1510 | 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] | 1511 | { |
| 1512 | if (__f_ == 0) |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1513 | __throw_bad_function_call(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1514 | return (*__f_)(__a0, __a1, __a2); |
| 1515 | } |
| 1516 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1517 | #ifndef _LIBCPP_NO_RTTI |
| 1518 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1519 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1520 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1521 | function<_Rp(_A0, _A1, _A2)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1522 | { |
| 1523 | if (__f_ == 0) |
| 1524 | return typeid(void); |
| 1525 | return __f_->target_type(); |
| 1526 | } |
| 1527 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1528 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1529 | template <typename _Tp> |
| 1530 | _Tp* |
| 1531 | function<_Rp(_A0, _A1, _A2)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1532 | { |
| 1533 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1534 | return (_Tp*)0; |
Marshall Clow | ff5f9b2 | 2017-06-14 20:00:36 +0000 | [diff] [blame] | 1535 | return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1538 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1539 | template <typename _Tp> |
| 1540 | const _Tp* |
| 1541 | function<_Rp(_A0, _A1, _A2)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1542 | { |
| 1543 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1544 | return (const _Tp*)0; |
| 1545 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1548 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1549 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1550 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1551 | inline _LIBCPP_INLINE_VISIBILITY |
| 1552 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1553 | operator==(const function<_Fp>& __f, nullptr_t) {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1554 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1555 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1556 | inline _LIBCPP_INLINE_VISIBILITY |
| 1557 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1558 | operator==(nullptr_t, const function<_Fp>& __f) {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1559 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1560 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1561 | inline _LIBCPP_INLINE_VISIBILITY |
| 1562 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1563 | operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1564 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1565 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1566 | inline _LIBCPP_INLINE_VISIBILITY |
| 1567 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1568 | operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1569 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1570 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1571 | inline _LIBCPP_INLINE_VISIBILITY |
| 1572 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1573 | swap(function<_Fp>& __x, function<_Fp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1574 | {return __x.swap(__y);} |
| 1575 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1576 | #endif // _LIBCPP_FUNCTIONAL_03 |