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