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 | |
| 199 | // bad_function_call |
| 200 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 201 | class _LIBCPP_EXCEPTION_ABI bad_function_call |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 202 | : public exception |
| 203 | { |
| 204 | }; |
| 205 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 206 | template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 207 | |
| 208 | namespace __function |
| 209 | { |
| 210 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 211 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 212 | struct __maybe_derive_from_unary_function |
| 213 | { |
| 214 | }; |
| 215 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 216 | template<class _Rp, class _A1> |
| 217 | struct __maybe_derive_from_unary_function<_Rp(_A1)> |
| 218 | : public unary_function<_A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 219 | { |
| 220 | }; |
| 221 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 222 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 223 | struct __maybe_derive_from_binary_function |
| 224 | { |
| 225 | }; |
| 226 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 227 | template<class _Rp, class _A1, class _A2> |
| 228 | struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> |
| 229 | : public binary_function<_A1, _A2, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 230 | { |
| 231 | }; |
| 232 | |
| 233 | template<class _Fp> class __base; |
| 234 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 235 | template<class _Rp> |
| 236 | class __base<_Rp()> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 237 | { |
| 238 | __base(const __base&); |
| 239 | __base& operator=(const __base&); |
| 240 | public: |
| 241 | __base() {} |
| 242 | virtual ~__base() {} |
| 243 | virtual __base* __clone() const = 0; |
| 244 | virtual void __clone(__base*) const = 0; |
| 245 | virtual void destroy() = 0; |
| 246 | virtual void destroy_deallocate() = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 247 | virtual _Rp operator()() = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 248 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 249 | virtual const void* target(const type_info&) const = 0; |
| 250 | virtual const std::type_info& target_type() const = 0; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 251 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 252 | }; |
| 253 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 254 | template<class _Rp, class _A0> |
| 255 | class __base<_Rp(_A0)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 256 | { |
| 257 | __base(const __base&); |
| 258 | __base& operator=(const __base&); |
| 259 | public: |
| 260 | __base() {} |
| 261 | virtual ~__base() {} |
| 262 | virtual __base* __clone() const = 0; |
| 263 | virtual void __clone(__base*) const = 0; |
| 264 | virtual void destroy() = 0; |
| 265 | virtual void destroy_deallocate() = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 266 | virtual _Rp operator()(_A0) = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 267 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | virtual const void* target(const type_info&) const = 0; |
| 269 | virtual const std::type_info& target_type() const = 0; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 270 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 271 | }; |
| 272 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 273 | template<class _Rp, class _A0, class _A1> |
| 274 | class __base<_Rp(_A0, _A1)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | { |
| 276 | __base(const __base&); |
| 277 | __base& operator=(const __base&); |
| 278 | public: |
| 279 | __base() {} |
| 280 | virtual ~__base() {} |
| 281 | virtual __base* __clone() const = 0; |
| 282 | virtual void __clone(__base*) const = 0; |
| 283 | virtual void destroy() = 0; |
| 284 | virtual void destroy_deallocate() = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 285 | virtual _Rp operator()(_A0, _A1) = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 286 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | virtual const void* target(const type_info&) const = 0; |
| 288 | virtual const std::type_info& target_type() const = 0; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 289 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 290 | }; |
| 291 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 292 | template<class _Rp, class _A0, class _A1, class _A2> |
| 293 | class __base<_Rp(_A0, _A1, _A2)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | { |
| 295 | __base(const __base&); |
| 296 | __base& operator=(const __base&); |
| 297 | public: |
| 298 | __base() {} |
| 299 | virtual ~__base() {} |
| 300 | virtual __base* __clone() const = 0; |
| 301 | virtual void __clone(__base*) const = 0; |
| 302 | virtual void destroy() = 0; |
| 303 | virtual void destroy_deallocate() = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 304 | virtual _Rp operator()(_A0, _A1, _A2) = 0; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 305 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 306 | virtual const void* target(const type_info&) const = 0; |
| 307 | virtual const std::type_info& target_type() const = 0; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 308 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | template<class _FD, class _Alloc, class _FB> class __func; |
| 312 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 313 | template<class _Fp, class _Alloc, class _Rp> |
| 314 | class __func<_Fp, _Alloc, _Rp()> |
| 315 | : public __base<_Rp()> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 316 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 317 | __compressed_pair<_Fp, _Alloc> __f_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 318 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 319 | explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} |
| 320 | explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} |
| 321 | virtual __base<_Rp()>* __clone() const; |
| 322 | virtual void __clone(__base<_Rp()>*) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 323 | virtual void destroy(); |
| 324 | virtual void destroy_deallocate(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 325 | virtual _Rp operator()(); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 326 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 327 | virtual const void* target(const type_info&) const; |
| 328 | virtual const std::type_info& target_type() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 329 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 332 | template<class _Fp, class _Alloc, class _Rp> |
| 333 | __base<_Rp()>* |
| 334 | __func<_Fp, _Alloc, _Rp()>::__clone() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 335 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 336 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 337 | _Ap __a(__f_.second()); |
| 338 | typedef __allocator_destructor<_Ap> _Dp; |
| 339 | unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 340 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 341 | return __hold.release(); |
| 342 | } |
| 343 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 344 | template<class _Fp, class _Alloc, class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 345 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 346 | __func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | { |
| 348 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 349 | } |
| 350 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 351 | template<class _Fp, class _Alloc, class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 353 | __func<_Fp, _Alloc, _Rp()>::destroy() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 354 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 355 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 358 | template<class _Fp, class _Alloc, class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 359 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 360 | __func<_Fp, _Alloc, _Rp()>::destroy_deallocate() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 361 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 362 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 363 | _Ap __a(__f_.second()); |
| 364 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | __a.deallocate(this, 1); |
| 366 | } |
| 367 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 368 | template<class _Fp, class _Alloc, class _Rp> |
| 369 | _Rp |
| 370 | __func<_Fp, _Alloc, _Rp()>::operator()() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | { |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 372 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 373 | return _Invoker::__call(__f_.first()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 376 | #ifndef _LIBCPP_NO_RTTI |
| 377 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 378 | template<class _Fp, class _Alloc, class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 379 | const void* |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 380 | __func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 381 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 382 | if (__ti == typeid(_Fp)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 383 | return &__f_.first(); |
| 384 | return (const void*)0; |
| 385 | } |
| 386 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 387 | template<class _Fp, class _Alloc, class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 388 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 389 | __func<_Fp, _Alloc, _Rp()>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 391 | return typeid(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 394 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 395 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 396 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 397 | class __func<_Fp, _Alloc, _Rp(_A0)> |
| 398 | : public __base<_Rp(_A0)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 399 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 400 | __compressed_pair<_Fp, _Alloc> __f_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 402 | _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} |
| 403 | _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 404 | : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 405 | virtual __base<_Rp(_A0)>* __clone() const; |
| 406 | virtual void __clone(__base<_Rp(_A0)>*) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | virtual void destroy(); |
| 408 | virtual void destroy_deallocate(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 409 | virtual _Rp operator()(_A0); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 410 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | virtual const void* target(const type_info&) const; |
| 412 | virtual const std::type_info& target_type() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 413 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 414 | }; |
| 415 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 416 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 417 | __base<_Rp(_A0)>* |
| 418 | __func<_Fp, _Alloc, _Rp(_A0)>::__clone() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 420 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 421 | _Ap __a(__f_.second()); |
| 422 | typedef __allocator_destructor<_Ap> _Dp; |
| 423 | unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 425 | return __hold.release(); |
| 426 | } |
| 427 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 428 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 430 | __func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | { |
| 432 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 433 | } |
| 434 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 435 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 436 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 437 | __func<_Fp, _Alloc, _Rp(_A0)>::destroy() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 438 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 439 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 442 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 443 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 444 | __func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 446 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 447 | _Ap __a(__f_.second()); |
| 448 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 449 | __a.deallocate(this, 1); |
| 450 | } |
| 451 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 452 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 453 | _Rp |
| 454 | __func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | { |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 456 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 457 | return _Invoker::__call(__f_.first(), __a0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 460 | #ifndef _LIBCPP_NO_RTTI |
| 461 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 462 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | const void* |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 464 | __func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 465 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 466 | if (__ti == typeid(_Fp)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 467 | return &__f_.first(); |
| 468 | return (const void*)0; |
| 469 | } |
| 470 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 471 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 473 | __func<_Fp, _Alloc, _Rp(_A0)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 474 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 475 | return typeid(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 478 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 479 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 480 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 481 | class __func<_Fp, _Alloc, _Rp(_A0, _A1)> |
| 482 | : public __base<_Rp(_A0, _A1)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 484 | __compressed_pair<_Fp, _Alloc> __f_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 486 | _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} |
| 487 | _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 488 | : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 489 | virtual __base<_Rp(_A0, _A1)>* __clone() const; |
| 490 | virtual void __clone(__base<_Rp(_A0, _A1)>*) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 491 | virtual void destroy(); |
| 492 | virtual void destroy_deallocate(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 493 | virtual _Rp operator()(_A0, _A1); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 494 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 495 | virtual const void* target(const type_info&) const; |
| 496 | virtual const std::type_info& target_type() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 497 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 498 | }; |
| 499 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 500 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 501 | __base<_Rp(_A0, _A1)>* |
| 502 | __func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 504 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 505 | _Ap __a(__f_.second()); |
| 506 | typedef __allocator_destructor<_Ap> _Dp; |
| 507 | unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 508 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 509 | return __hold.release(); |
| 510 | } |
| 511 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 512 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 513 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 514 | __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] | 515 | { |
| 516 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 517 | } |
| 518 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 519 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 521 | __func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 522 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 523 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 526 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 527 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 528 | __func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 529 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 530 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 531 | _Ap __a(__f_.second()); |
| 532 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | __a.deallocate(this, 1); |
| 534 | } |
| 535 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 536 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 537 | _Rp |
| 538 | __func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | { |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 540 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 541 | return _Invoker::__call(__f_.first(), __a0, __a1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 544 | #ifndef _LIBCPP_NO_RTTI |
| 545 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 546 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 547 | const void* |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 548 | __func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 549 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 550 | if (__ti == typeid(_Fp)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 551 | return &__f_.first(); |
| 552 | return (const void*)0; |
| 553 | } |
| 554 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 555 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 556 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 557 | __func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 558 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 559 | return typeid(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 562 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 563 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 564 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 565 | class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> |
| 566 | : public __base<_Rp(_A0, _A1, _A2)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 567 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 568 | __compressed_pair<_Fp, _Alloc> __f_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 569 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 570 | _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f) : __f_(_VSTD::move(__f)) {} |
| 571 | _LIBCPP_INLINE_VISIBILITY explicit __func(_Fp __f, _Alloc __a) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 572 | : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 573 | virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const; |
| 574 | virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | virtual void destroy(); |
| 576 | virtual void destroy_deallocate(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 577 | virtual _Rp operator()(_A0, _A1, _A2); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 578 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 579 | virtual const void* target(const type_info&) const; |
| 580 | virtual const std::type_info& target_type() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 581 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 582 | }; |
| 583 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 584 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 585 | __base<_Rp(_A0, _A1, _A2)>* |
| 586 | __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 587 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 588 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 589 | _Ap __a(__f_.second()); |
| 590 | typedef __allocator_destructor<_Ap> _Dp; |
| 591 | unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 592 | ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); |
| 593 | return __hold.release(); |
| 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> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 597 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 598 | __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] | 599 | { |
| 600 | ::new (__p) __func(__f_.first(), __f_.second()); |
| 601 | } |
| 602 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 603 | 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] | 604 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 605 | __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 606 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 607 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 608 | } |
| 609 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 610 | 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] | 611 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 612 | __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 614 | typedef typename _Alloc::template rebind<__func>::other _Ap; |
| 615 | _Ap __a(__f_.second()); |
| 616 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 617 | __a.deallocate(this, 1); |
| 618 | } |
| 619 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 620 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 621 | _Rp |
| 622 | __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] | 623 | { |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 624 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 625 | return _Invoker::__call(__f_.first(), __a0, __a1, __a2); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 628 | #ifndef _LIBCPP_NO_RTTI |
| 629 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 630 | 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] | 631 | const void* |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 632 | __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] | 633 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 634 | if (__ti == typeid(_Fp)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 635 | return &__f_.first(); |
| 636 | return (const void*)0; |
| 637 | } |
| 638 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 639 | 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] | 640 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 641 | __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 642 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 643 | return typeid(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 646 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 647 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | } // __function |
| 649 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 650 | template<class _Rp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 651 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp()> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 652 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 653 | typedef __function::__base<_Rp()> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 654 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 655 | __base* __f_; |
| 656 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 657 | template <class _Fp> |
Marshall Clow | 2f9e714 | 2014-06-30 21:27:51 +0000 | [diff] [blame] | 658 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 659 | static bool __not_null(const _Fp&) {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 660 | template <class _R2> |
Marshall Clow | 2f9e714 | 2014-06-30 21:27:51 +0000 | [diff] [blame] | 661 | _LIBCPP_INLINE_VISIBILITY |
| 662 | static bool __not_null(_R2 (*__p)()) {return __p;} |
| 663 | template <class _R2> |
| 664 | _LIBCPP_INLINE_VISIBILITY |
| 665 | static bool __not_null(const function<_R2()>& __p) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 666 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 667 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 668 | |
| 669 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 670 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 671 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 672 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 673 | template<class _Fp> |
| 674 | function(_Fp, |
| 675 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 676 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 677 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 678 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 679 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 680 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 681 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 682 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 683 | template<class _Alloc> |
| 684 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 685 | template<class _Fp, class _Alloc> |
| 686 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 687 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 688 | |
| 689 | function& operator=(const function&); |
| 690 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 691 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 692 | typename enable_if |
| 693 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 694 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 695 | function& |
| 696 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 697 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 698 | |
| 699 | ~function(); |
| 700 | |
| 701 | // 20.7.16.2.2, function modifiers: |
| 702 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 703 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 704 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 705 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 706 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 707 | |
| 708 | // 20.7.16.2.3, function capacity: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 709 | _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 710 | |
| 711 | private: |
| 712 | // deleted overloads close possible hole in the type system |
| 713 | template<class _R2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 714 | bool operator==(const function<_R2()>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | template<class _R2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 716 | bool operator!=(const function<_R2()>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 717 | public: |
| 718 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 719 | _Rp operator()() const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 720 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 721 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 722 | // 20.7.16.2.5, function target access: |
| 723 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 724 | template <typename _Tp> _Tp* target(); |
| 725 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 726 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 727 | }; |
| 728 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 729 | template<class _Rp> |
| 730 | function<_Rp()>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 731 | { |
| 732 | if (__f.__f_ == 0) |
| 733 | __f_ = 0; |
| 734 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 735 | { |
| 736 | __f_ = (__base*)&__buf_; |
| 737 | __f.__f_->__clone(__f_); |
| 738 | } |
| 739 | else |
| 740 | __f_ = __f.__f_->__clone(); |
| 741 | } |
| 742 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 743 | template<class _Rp> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 744 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 745 | function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 746 | { |
| 747 | if (__f.__f_ == 0) |
| 748 | __f_ = 0; |
| 749 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 750 | { |
| 751 | __f_ = (__base*)&__buf_; |
| 752 | __f.__f_->__clone(__f_); |
| 753 | } |
| 754 | else |
| 755 | __f_ = __f.__f_->__clone(); |
| 756 | } |
| 757 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 758 | template<class _Rp> |
| 759 | template <class _Fp> |
| 760 | function<_Rp()>::function(_Fp __f, |
| 761 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 762 | : __f_(0) |
| 763 | { |
| 764 | if (__not_null(__f)) |
| 765 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 766 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 767 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 768 | { |
| 769 | __f_ = (__base*)&__buf_; |
| 770 | ::new (__f_) _FF(__f); |
| 771 | } |
| 772 | else |
| 773 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 774 | typedef allocator<_FF> _Ap; |
| 775 | _Ap __a; |
| 776 | typedef __allocator_destructor<_Ap> _Dp; |
| 777 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 778 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 779 | __f_ = __hold.release(); |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 784 | template<class _Rp> |
| 785 | template <class _Fp, class _Alloc> |
| 786 | function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 787 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 788 | : __f_(0) |
| 789 | { |
| 790 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 791 | if (__not_null(__f)) |
| 792 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 793 | typedef __function::__func<_Fp, _Alloc, _Rp()> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 794 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 795 | { |
| 796 | __f_ = (__base*)&__buf_; |
| 797 | ::new (__f_) _FF(__f); |
| 798 | } |
| 799 | else |
| 800 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 801 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 802 | _Ap __a(__a0); |
| 803 | typedef __allocator_destructor<_Ap> _Dp; |
| 804 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 805 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 806 | __f_ = __hold.release(); |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 811 | template<class _Rp> |
| 812 | function<_Rp()>& |
| 813 | function<_Rp()>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 814 | { |
| 815 | function(__f).swap(*this); |
| 816 | return *this; |
| 817 | } |
| 818 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 819 | template<class _Rp> |
| 820 | function<_Rp()>& |
| 821 | function<_Rp()>::operator=(nullptr_t) |
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 | __f_ = 0; |
Eric Fiselier | fa97c2e | 2015-06-02 01:31:33 +0000 | [diff] [blame^] | 828 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 831 | template<class _Rp> |
| 832 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 833 | typename enable_if |
| 834 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 835 | !is_integral<_Fp>::value, |
| 836 | function<_Rp()>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 837 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 838 | function<_Rp()>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 839 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 840 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 841 | return *this; |
| 842 | } |
| 843 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 844 | template<class _Rp> |
| 845 | function<_Rp()>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 846 | { |
| 847 | if (__f_ == (__base*)&__buf_) |
| 848 | __f_->destroy(); |
| 849 | else if (__f_) |
| 850 | __f_->destroy_deallocate(); |
| 851 | } |
| 852 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 853 | template<class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 854 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 855 | function<_Rp()>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 856 | { |
| 857 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 858 | { |
| 859 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 860 | __base* __t = (__base*)&__tempbuf; |
| 861 | __f_->__clone(__t); |
| 862 | __f_->destroy(); |
| 863 | __f_ = 0; |
| 864 | __f.__f_->__clone((__base*)&__buf_); |
| 865 | __f.__f_->destroy(); |
| 866 | __f.__f_ = 0; |
| 867 | __f_ = (__base*)&__buf_; |
| 868 | __t->__clone((__base*)&__f.__buf_); |
| 869 | __t->destroy(); |
| 870 | __f.__f_ = (__base*)&__f.__buf_; |
| 871 | } |
| 872 | else if (__f_ == (__base*)&__buf_) |
| 873 | { |
| 874 | __f_->__clone((__base*)&__f.__buf_); |
| 875 | __f_->destroy(); |
| 876 | __f_ = __f.__f_; |
| 877 | __f.__f_ = (__base*)&__f.__buf_; |
| 878 | } |
| 879 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 880 | { |
| 881 | __f.__f_->__clone((__base*)&__buf_); |
| 882 | __f.__f_->destroy(); |
| 883 | __f.__f_ = __f_; |
| 884 | __f_ = (__base*)&__buf_; |
| 885 | } |
| 886 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 887 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 890 | template<class _Rp> |
| 891 | _Rp |
| 892 | function<_Rp()>::operator()() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 894 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 895 | if (__f_ == 0) |
| 896 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 897 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 898 | return (*__f_)(); |
| 899 | } |
| 900 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 901 | #ifndef _LIBCPP_NO_RTTI |
| 902 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 903 | template<class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 904 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 905 | function<_Rp()>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 906 | { |
| 907 | if (__f_ == 0) |
| 908 | return typeid(void); |
| 909 | return __f_->target_type(); |
| 910 | } |
| 911 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 912 | template<class _Rp> |
| 913 | template <typename _Tp> |
| 914 | _Tp* |
| 915 | function<_Rp()>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 916 | { |
| 917 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 918 | return (_Tp*)0; |
| 919 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 922 | template<class _Rp> |
| 923 | template <typename _Tp> |
| 924 | const _Tp* |
| 925 | function<_Rp()>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 926 | { |
| 927 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 928 | return (const _Tp*)0; |
| 929 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 932 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 933 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 934 | template<class _Rp, class _A0> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 935 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 936 | : public unary_function<_A0, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 937 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 938 | typedef __function::__base<_Rp(_A0)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 939 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 940 | __base* __f_; |
| 941 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 942 | template <class _Fp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 943 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 944 | static bool __not_null(const _Fp&) {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 945 | template <class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 946 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 947 | static bool __not_null(_R2 (*__p)(_B0)) {return __p;} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 948 | template <class _R2, class _Cp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 949 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 950 | static bool __not_null(_R2 (_Cp::*__p)()) {return __p;} |
| 951 | template <class _R2, class _Cp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 952 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 953 | static bool __not_null(_R2 (_Cp::*__p)() const) {return __p;} |
| 954 | template <class _R2, class _Cp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 955 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 956 | static bool __not_null(_R2 (_Cp::*__p)() volatile) {return __p;} |
| 957 | template <class _R2, class _Cp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 958 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 959 | static bool __not_null(_R2 (_Cp::*__p)() const volatile) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 960 | template <class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 961 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 2f9e714 | 2014-06-30 21:27:51 +0000 | [diff] [blame] | 962 | static bool __not_null(const function<_R2(_B0)>& __p) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 963 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 964 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 965 | |
| 966 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 967 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 968 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 969 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 970 | template<class _Fp> |
| 971 | function(_Fp, |
| 972 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 973 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 974 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 975 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 976 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 977 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 978 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 979 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 980 | template<class _Alloc> |
| 981 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 982 | template<class _Fp, class _Alloc> |
| 983 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 984 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 985 | |
| 986 | function& operator=(const function&); |
| 987 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 988 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 989 | typename enable_if |
| 990 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 991 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 992 | function& |
| 993 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 994 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 995 | |
| 996 | ~function(); |
| 997 | |
| 998 | // 20.7.16.2.2, function modifiers: |
| 999 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1000 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1001 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1002 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1003 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1004 | |
| 1005 | // 20.7.16.2.3, function capacity: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1006 | _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1007 | |
| 1008 | private: |
| 1009 | // deleted overloads close possible hole in the type system |
| 1010 | template<class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1011 | bool operator==(const function<_R2(_B0)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1012 | template<class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1013 | bool operator!=(const function<_R2(_B0)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1014 | public: |
| 1015 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1016 | _Rp operator()(_A0) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1017 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1018 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1019 | // 20.7.16.2.5, function target access: |
| 1020 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1021 | template <typename _Tp> _Tp* target(); |
| 1022 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1023 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1024 | }; |
| 1025 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1026 | template<class _Rp, class _A0> |
| 1027 | function<_Rp(_A0)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1028 | { |
| 1029 | if (__f.__f_ == 0) |
| 1030 | __f_ = 0; |
| 1031 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1032 | { |
| 1033 | __f_ = (__base*)&__buf_; |
| 1034 | __f.__f_->__clone(__f_); |
| 1035 | } |
| 1036 | else |
| 1037 | __f_ = __f.__f_->__clone(); |
| 1038 | } |
| 1039 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1040 | template<class _Rp, class _A0> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1041 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1042 | function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1043 | { |
| 1044 | if (__f.__f_ == 0) |
| 1045 | __f_ = 0; |
| 1046 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1047 | { |
| 1048 | __f_ = (__base*)&__buf_; |
| 1049 | __f.__f_->__clone(__f_); |
| 1050 | } |
| 1051 | else |
| 1052 | __f_ = __f.__f_->__clone(); |
| 1053 | } |
| 1054 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1055 | template<class _Rp, class _A0> |
| 1056 | template <class _Fp> |
| 1057 | function<_Rp(_A0)>::function(_Fp __f, |
| 1058 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1059 | : __f_(0) |
| 1060 | { |
| 1061 | if (__not_null(__f)) |
| 1062 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1063 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1064 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1065 | { |
| 1066 | __f_ = (__base*)&__buf_; |
| 1067 | ::new (__f_) _FF(__f); |
| 1068 | } |
| 1069 | else |
| 1070 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1071 | typedef allocator<_FF> _Ap; |
| 1072 | _Ap __a; |
| 1073 | typedef __allocator_destructor<_Ap> _Dp; |
| 1074 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1075 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1076 | __f_ = __hold.release(); |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1081 | template<class _Rp, class _A0> |
| 1082 | template <class _Fp, class _Alloc> |
| 1083 | function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1084 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1085 | : __f_(0) |
| 1086 | { |
| 1087 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1088 | if (__not_null(__f)) |
| 1089 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1090 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1091 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1092 | { |
| 1093 | __f_ = (__base*)&__buf_; |
| 1094 | ::new (__f_) _FF(__f); |
| 1095 | } |
| 1096 | else |
| 1097 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1098 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1099 | _Ap __a(__a0); |
| 1100 | typedef __allocator_destructor<_Ap> _Dp; |
| 1101 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1102 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 1103 | __f_ = __hold.release(); |
| 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1108 | template<class _Rp, class _A0> |
| 1109 | function<_Rp(_A0)>& |
| 1110 | function<_Rp(_A0)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1111 | { |
| 1112 | function(__f).swap(*this); |
| 1113 | return *this; |
| 1114 | } |
| 1115 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1116 | template<class _Rp, class _A0> |
| 1117 | function<_Rp(_A0)>& |
| 1118 | function<_Rp(_A0)>::operator=(nullptr_t) |
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 | __f_ = 0; |
Eric Fiselier | fa97c2e | 2015-06-02 01:31:33 +0000 | [diff] [blame^] | 1125 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1128 | template<class _Rp, class _A0> |
| 1129 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1130 | typename enable_if |
| 1131 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1132 | !is_integral<_Fp>::value, |
| 1133 | function<_Rp(_A0)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1134 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1135 | function<_Rp(_A0)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1136 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1137 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1138 | return *this; |
| 1139 | } |
| 1140 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1141 | template<class _Rp, class _A0> |
| 1142 | function<_Rp(_A0)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1143 | { |
| 1144 | if (__f_ == (__base*)&__buf_) |
| 1145 | __f_->destroy(); |
| 1146 | else if (__f_) |
| 1147 | __f_->destroy_deallocate(); |
| 1148 | } |
| 1149 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1150 | template<class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1151 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1152 | function<_Rp(_A0)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1153 | { |
| 1154 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1155 | { |
| 1156 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1157 | __base* __t = (__base*)&__tempbuf; |
| 1158 | __f_->__clone(__t); |
| 1159 | __f_->destroy(); |
| 1160 | __f_ = 0; |
| 1161 | __f.__f_->__clone((__base*)&__buf_); |
| 1162 | __f.__f_->destroy(); |
| 1163 | __f.__f_ = 0; |
| 1164 | __f_ = (__base*)&__buf_; |
| 1165 | __t->__clone((__base*)&__f.__buf_); |
| 1166 | __t->destroy(); |
| 1167 | __f.__f_ = (__base*)&__f.__buf_; |
| 1168 | } |
| 1169 | else if (__f_ == (__base*)&__buf_) |
| 1170 | { |
| 1171 | __f_->__clone((__base*)&__f.__buf_); |
| 1172 | __f_->destroy(); |
| 1173 | __f_ = __f.__f_; |
| 1174 | __f.__f_ = (__base*)&__f.__buf_; |
| 1175 | } |
| 1176 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1177 | { |
| 1178 | __f.__f_->__clone((__base*)&__buf_); |
| 1179 | __f.__f_->destroy(); |
| 1180 | __f.__f_ = __f_; |
| 1181 | __f_ = (__base*)&__buf_; |
| 1182 | } |
| 1183 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1184 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1187 | template<class _Rp, class _A0> |
| 1188 | _Rp |
| 1189 | function<_Rp(_A0)>::operator()(_A0 __a0) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1190 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1191 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1192 | if (__f_ == 0) |
| 1193 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1194 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | return (*__f_)(__a0); |
| 1196 | } |
| 1197 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1198 | #ifndef _LIBCPP_NO_RTTI |
| 1199 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1200 | template<class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1201 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1202 | function<_Rp(_A0)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1203 | { |
| 1204 | if (__f_ == 0) |
| 1205 | return typeid(void); |
| 1206 | return __f_->target_type(); |
| 1207 | } |
| 1208 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1209 | template<class _Rp, class _A0> |
| 1210 | template <typename _Tp> |
| 1211 | _Tp* |
| 1212 | function<_Rp(_A0)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1213 | { |
| 1214 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1215 | return (_Tp*)0; |
| 1216 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1219 | template<class _Rp, class _A0> |
| 1220 | template <typename _Tp> |
| 1221 | const _Tp* |
| 1222 | function<_Rp(_A0)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1223 | { |
| 1224 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1225 | return (const _Tp*)0; |
| 1226 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1229 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1230 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1231 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1232 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1233 | : public binary_function<_A0, _A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1235 | typedef __function::__base<_Rp(_A0, _A1)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1236 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1237 | __base* __f_; |
| 1238 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1239 | template <class _Fp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1240 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1241 | static bool __not_null(const _Fp&) {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1242 | template <class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1243 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1244 | static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1245 | template <class _R2, class _Cp, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1246 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1247 | static bool __not_null(_R2 (_Cp::*__p)(_B1)) {return __p;} |
| 1248 | template <class _R2, class _Cp, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1249 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1250 | static bool __not_null(_R2 (_Cp::*__p)(_B1) const) {return __p;} |
| 1251 | template <class _R2, class _Cp, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1252 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1253 | static bool __not_null(_R2 (_Cp::*__p)(_B1) volatile) {return __p;} |
| 1254 | template <class _R2, class _Cp, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1255 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1256 | static bool __not_null(_R2 (_Cp::*__p)(_B1) const volatile) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1257 | template <class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1258 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 2f9e714 | 2014-06-30 21:27:51 +0000 | [diff] [blame] | 1259 | static bool __not_null(const function<_R2(_B0, _B1)>& __p) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1260 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1261 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | |
| 1263 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1264 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 1265 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1266 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1267 | template<class _Fp> |
| 1268 | function(_Fp, |
| 1269 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1270 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1271 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1272 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1273 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 1274 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1275 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1276 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 1277 | template<class _Alloc> |
| 1278 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1279 | template<class _Fp, class _Alloc> |
| 1280 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 1281 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1282 | |
| 1283 | function& operator=(const function&); |
| 1284 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1285 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1286 | typename enable_if |
| 1287 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1288 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1289 | function& |
| 1290 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1291 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1292 | |
| 1293 | ~function(); |
| 1294 | |
| 1295 | // 20.7.16.2.2, function modifiers: |
| 1296 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1297 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1298 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1299 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1300 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1301 | |
| 1302 | // 20.7.16.2.3, function capacity: |
| 1303 | operator bool() const {return __f_;} |
| 1304 | |
| 1305 | private: |
| 1306 | // deleted overloads close possible hole in the type system |
| 1307 | template<class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1308 | bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1309 | template<class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1310 | bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1311 | public: |
| 1312 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1313 | _Rp operator()(_A0, _A1) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1314 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1315 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1316 | // 20.7.16.2.5, function target access: |
| 1317 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1318 | template <typename _Tp> _Tp* target(); |
| 1319 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1320 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1321 | }; |
| 1322 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1323 | template<class _Rp, class _A0, class _A1> |
| 1324 | function<_Rp(_A0, _A1)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | { |
| 1326 | if (__f.__f_ == 0) |
| 1327 | __f_ = 0; |
| 1328 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1329 | { |
| 1330 | __f_ = (__base*)&__buf_; |
| 1331 | __f.__f_->__clone(__f_); |
| 1332 | } |
| 1333 | else |
| 1334 | __f_ = __f.__f_->__clone(); |
| 1335 | } |
| 1336 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1337 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1338 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1339 | 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] | 1340 | { |
| 1341 | if (__f.__f_ == 0) |
| 1342 | __f_ = 0; |
| 1343 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1344 | { |
| 1345 | __f_ = (__base*)&__buf_; |
| 1346 | __f.__f_->__clone(__f_); |
| 1347 | } |
| 1348 | else |
| 1349 | __f_ = __f.__f_->__clone(); |
| 1350 | } |
| 1351 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1352 | template<class _Rp, class _A0, class _A1> |
| 1353 | template <class _Fp> |
| 1354 | function<_Rp(_A0, _A1)>::function(_Fp __f, |
| 1355 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1356 | : __f_(0) |
| 1357 | { |
| 1358 | if (__not_null(__f)) |
| 1359 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1360 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1361 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1362 | { |
| 1363 | __f_ = (__base*)&__buf_; |
| 1364 | ::new (__f_) _FF(__f); |
| 1365 | } |
| 1366 | else |
| 1367 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1368 | typedef allocator<_FF> _Ap; |
| 1369 | _Ap __a; |
| 1370 | typedef __allocator_destructor<_Ap> _Dp; |
| 1371 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1372 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1373 | __f_ = __hold.release(); |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1378 | template<class _Rp, class _A0, class _A1> |
| 1379 | template <class _Fp, class _Alloc> |
| 1380 | function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1381 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1382 | : __f_(0) |
| 1383 | { |
| 1384 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1385 | if (__not_null(__f)) |
| 1386 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1387 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1388 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1389 | { |
| 1390 | __f_ = (__base*)&__buf_; |
| 1391 | ::new (__f_) _FF(__f); |
| 1392 | } |
| 1393 | else |
| 1394 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1395 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1396 | _Ap __a(__a0); |
| 1397 | typedef __allocator_destructor<_Ap> _Dp; |
| 1398 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1399 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 1400 | __f_ = __hold.release(); |
| 1401 | } |
| 1402 | } |
| 1403 | } |
| 1404 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1405 | template<class _Rp, class _A0, class _A1> |
| 1406 | function<_Rp(_A0, _A1)>& |
| 1407 | function<_Rp(_A0, _A1)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1408 | { |
| 1409 | function(__f).swap(*this); |
| 1410 | return *this; |
| 1411 | } |
| 1412 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1413 | template<class _Rp, class _A0, class _A1> |
| 1414 | function<_Rp(_A0, _A1)>& |
| 1415 | function<_Rp(_A0, _A1)>::operator=(nullptr_t) |
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 | __f_ = 0; |
Eric Fiselier | fa97c2e | 2015-06-02 01:31:33 +0000 | [diff] [blame^] | 1422 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1425 | template<class _Rp, class _A0, class _A1> |
| 1426 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1427 | typename enable_if |
| 1428 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1429 | !is_integral<_Fp>::value, |
| 1430 | function<_Rp(_A0, _A1)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1431 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1432 | function<_Rp(_A0, _A1)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1433 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1434 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1435 | return *this; |
| 1436 | } |
| 1437 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1438 | template<class _Rp, class _A0, class _A1> |
| 1439 | function<_Rp(_A0, _A1)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1440 | { |
| 1441 | if (__f_ == (__base*)&__buf_) |
| 1442 | __f_->destroy(); |
| 1443 | else if (__f_) |
| 1444 | __f_->destroy_deallocate(); |
| 1445 | } |
| 1446 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1447 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1449 | function<_Rp(_A0, _A1)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1450 | { |
| 1451 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1452 | { |
| 1453 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1454 | __base* __t = (__base*)&__tempbuf; |
| 1455 | __f_->__clone(__t); |
| 1456 | __f_->destroy(); |
| 1457 | __f_ = 0; |
| 1458 | __f.__f_->__clone((__base*)&__buf_); |
| 1459 | __f.__f_->destroy(); |
| 1460 | __f.__f_ = 0; |
| 1461 | __f_ = (__base*)&__buf_; |
| 1462 | __t->__clone((__base*)&__f.__buf_); |
| 1463 | __t->destroy(); |
| 1464 | __f.__f_ = (__base*)&__f.__buf_; |
| 1465 | } |
| 1466 | else if (__f_ == (__base*)&__buf_) |
| 1467 | { |
| 1468 | __f_->__clone((__base*)&__f.__buf_); |
| 1469 | __f_->destroy(); |
| 1470 | __f_ = __f.__f_; |
| 1471 | __f.__f_ = (__base*)&__f.__buf_; |
| 1472 | } |
| 1473 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1474 | { |
| 1475 | __f.__f_->__clone((__base*)&__buf_); |
| 1476 | __f.__f_->destroy(); |
| 1477 | __f.__f_ = __f_; |
| 1478 | __f_ = (__base*)&__buf_; |
| 1479 | } |
| 1480 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1481 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1484 | template<class _Rp, class _A0, class _A1> |
| 1485 | _Rp |
| 1486 | function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1487 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1488 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1489 | if (__f_ == 0) |
| 1490 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1491 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1492 | return (*__f_)(__a0, __a1); |
| 1493 | } |
| 1494 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1495 | #ifndef _LIBCPP_NO_RTTI |
| 1496 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1497 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1498 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1499 | function<_Rp(_A0, _A1)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1500 | { |
| 1501 | if (__f_ == 0) |
| 1502 | return typeid(void); |
| 1503 | return __f_->target_type(); |
| 1504 | } |
| 1505 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1506 | template<class _Rp, class _A0, class _A1> |
| 1507 | template <typename _Tp> |
| 1508 | _Tp* |
| 1509 | function<_Rp(_A0, _A1)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1510 | { |
| 1511 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1512 | return (_Tp*)0; |
| 1513 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1516 | template<class _Rp, class _A0, class _A1> |
| 1517 | template <typename _Tp> |
| 1518 | const _Tp* |
| 1519 | function<_Rp(_A0, _A1)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1520 | { |
| 1521 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1522 | return (const _Tp*)0; |
| 1523 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1526 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1527 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1528 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1529 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1530 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1531 | typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1532 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1533 | __base* __f_; |
| 1534 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1535 | template <class _Fp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1536 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1537 | static bool __not_null(const _Fp&) {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1538 | template <class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1540 | static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1541 | template <class _R2, class _Cp, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1543 | static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2)) {return __p;} |
| 1544 | template <class _R2, class _Cp, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1545 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1546 | static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const) {return __p;} |
| 1547 | template <class _R2, class _Cp, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1548 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1549 | static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) volatile) {return __p;} |
| 1550 | template <class _R2, class _Cp, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1551 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1552 | 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] | 1553 | template <class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1554 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 2f9e714 | 2014-06-30 21:27:51 +0000 | [diff] [blame] | 1555 | 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] | 1556 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1557 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1558 | |
| 1559 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1560 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 1561 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1562 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1563 | template<class _Fp> |
| 1564 | function(_Fp, |
| 1565 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1566 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1567 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1569 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 1570 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1571 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1572 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 1573 | template<class _Alloc> |
| 1574 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1575 | template<class _Fp, class _Alloc> |
| 1576 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 1577 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1578 | |
| 1579 | function& operator=(const function&); |
| 1580 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1581 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1582 | typename enable_if |
| 1583 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1584 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1585 | function& |
| 1586 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1587 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1588 | |
| 1589 | ~function(); |
| 1590 | |
| 1591 | // 20.7.16.2.2, function modifiers: |
| 1592 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1593 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1594 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1595 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1596 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | |
| 1598 | // 20.7.16.2.3, function capacity: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1599 | _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1600 | |
| 1601 | private: |
| 1602 | // deleted overloads close possible hole in the type system |
| 1603 | template<class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1604 | bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1605 | template<class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1606 | bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1607 | public: |
| 1608 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1609 | _Rp operator()(_A0, _A1, _A2) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1610 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1611 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1612 | // 20.7.16.2.5, function target access: |
| 1613 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1614 | template <typename _Tp> _Tp* target(); |
| 1615 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1616 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1617 | }; |
| 1618 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1619 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1620 | function<_Rp(_A0, _A1, _A2)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1621 | { |
| 1622 | if (__f.__f_ == 0) |
| 1623 | __f_ = 0; |
| 1624 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1625 | { |
| 1626 | __f_ = (__base*)&__buf_; |
| 1627 | __f.__f_->__clone(__f_); |
| 1628 | } |
| 1629 | else |
| 1630 | __f_ = __f.__f_->__clone(); |
| 1631 | } |
| 1632 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1633 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1634 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1635 | function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1636 | const function& __f) |
| 1637 | { |
| 1638 | if (__f.__f_ == 0) |
| 1639 | __f_ = 0; |
| 1640 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1641 | { |
| 1642 | __f_ = (__base*)&__buf_; |
| 1643 | __f.__f_->__clone(__f_); |
| 1644 | } |
| 1645 | else |
| 1646 | __f_ = __f.__f_->__clone(); |
| 1647 | } |
| 1648 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1649 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1650 | template <class _Fp> |
| 1651 | function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, |
| 1652 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1653 | : __f_(0) |
| 1654 | { |
| 1655 | if (__not_null(__f)) |
| 1656 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1657 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1658 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1659 | { |
| 1660 | __f_ = (__base*)&__buf_; |
| 1661 | ::new (__f_) _FF(__f); |
| 1662 | } |
| 1663 | else |
| 1664 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1665 | typedef allocator<_FF> _Ap; |
| 1666 | _Ap __a; |
| 1667 | typedef __allocator_destructor<_Ap> _Dp; |
| 1668 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1669 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1670 | __f_ = __hold.release(); |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1675 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1676 | template <class _Fp, class _Alloc> |
| 1677 | function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1678 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1679 | : __f_(0) |
| 1680 | { |
| 1681 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1682 | if (__not_null(__f)) |
| 1683 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1684 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1685 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1686 | { |
| 1687 | __f_ = (__base*)&__buf_; |
| 1688 | ::new (__f_) _FF(__f); |
| 1689 | } |
| 1690 | else |
| 1691 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1692 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1693 | _Ap __a(__a0); |
| 1694 | typedef __allocator_destructor<_Ap> _Dp; |
| 1695 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1696 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 1697 | __f_ = __hold.release(); |
| 1698 | } |
| 1699 | } |
| 1700 | } |
| 1701 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1702 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1703 | function<_Rp(_A0, _A1, _A2)>& |
| 1704 | function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1705 | { |
| 1706 | function(__f).swap(*this); |
| 1707 | return *this; |
| 1708 | } |
| 1709 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1710 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1711 | function<_Rp(_A0, _A1, _A2)>& |
| 1712 | function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t) |
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 | __f_ = 0; |
Eric Fiselier | fa97c2e | 2015-06-02 01:31:33 +0000 | [diff] [blame^] | 1719 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1722 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1723 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1724 | typename enable_if |
| 1725 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1726 | !is_integral<_Fp>::value, |
| 1727 | function<_Rp(_A0, _A1, _A2)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1728 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1729 | function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1730 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1731 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1732 | return *this; |
| 1733 | } |
| 1734 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1735 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1736 | function<_Rp(_A0, _A1, _A2)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1737 | { |
| 1738 | if (__f_ == (__base*)&__buf_) |
| 1739 | __f_->destroy(); |
| 1740 | else if (__f_) |
| 1741 | __f_->destroy_deallocate(); |
| 1742 | } |
| 1743 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1744 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1746 | function<_Rp(_A0, _A1, _A2)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1747 | { |
| 1748 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1749 | { |
| 1750 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1751 | __base* __t = (__base*)&__tempbuf; |
| 1752 | __f_->__clone(__t); |
| 1753 | __f_->destroy(); |
| 1754 | __f_ = 0; |
| 1755 | __f.__f_->__clone((__base*)&__buf_); |
| 1756 | __f.__f_->destroy(); |
| 1757 | __f.__f_ = 0; |
| 1758 | __f_ = (__base*)&__buf_; |
| 1759 | __t->__clone((__base*)&__f.__buf_); |
| 1760 | __t->destroy(); |
| 1761 | __f.__f_ = (__base*)&__f.__buf_; |
| 1762 | } |
| 1763 | else if (__f_ == (__base*)&__buf_) |
| 1764 | { |
| 1765 | __f_->__clone((__base*)&__f.__buf_); |
| 1766 | __f_->destroy(); |
| 1767 | __f_ = __f.__f_; |
| 1768 | __f.__f_ = (__base*)&__f.__buf_; |
| 1769 | } |
| 1770 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1771 | { |
| 1772 | __f.__f_->__clone((__base*)&__buf_); |
| 1773 | __f.__f_->destroy(); |
| 1774 | __f.__f_ = __f_; |
| 1775 | __f_ = (__base*)&__buf_; |
| 1776 | } |
| 1777 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1778 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1781 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1782 | _Rp |
| 1783 | 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] | 1784 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1785 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1786 | if (__f_ == 0) |
| 1787 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1788 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1789 | return (*__f_)(__a0, __a1, __a2); |
| 1790 | } |
| 1791 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1792 | #ifndef _LIBCPP_NO_RTTI |
| 1793 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1794 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1795 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1796 | function<_Rp(_A0, _A1, _A2)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1797 | { |
| 1798 | if (__f_ == 0) |
| 1799 | return typeid(void); |
| 1800 | return __f_->target_type(); |
| 1801 | } |
| 1802 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1803 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1804 | template <typename _Tp> |
| 1805 | _Tp* |
| 1806 | function<_Rp(_A0, _A1, _A2)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1807 | { |
| 1808 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1809 | return (_Tp*)0; |
| 1810 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1813 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1814 | template <typename _Tp> |
| 1815 | const _Tp* |
| 1816 | function<_Rp(_A0, _A1, _A2)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1817 | { |
| 1818 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1819 | return (const _Tp*)0; |
| 1820 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1823 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1824 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1825 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1826 | inline _LIBCPP_INLINE_VISIBILITY |
| 1827 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1828 | operator==(const function<_Fp>& __f, nullptr_t) {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1829 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1830 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1831 | inline _LIBCPP_INLINE_VISIBILITY |
| 1832 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1833 | operator==(nullptr_t, const function<_Fp>& __f) {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1834 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1835 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1836 | inline _LIBCPP_INLINE_VISIBILITY |
| 1837 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1838 | operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1839 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1840 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1841 | inline _LIBCPP_INLINE_VISIBILITY |
| 1842 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1843 | operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1844 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1845 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1846 | inline _LIBCPP_INLINE_VISIBILITY |
| 1847 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1848 | swap(function<_Fp>& __x, function<_Fp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1849 | {return __x.swap(__y);} |
| 1850 | |
| 1851 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1852 | template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1853 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 1854 | |
| 1855 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1856 | template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1857 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 1858 | |
| 1859 | namespace placeholders |
| 1860 | { |
| 1861 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1862 | template <int _Np> struct __ph {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1863 | |
| 1864 | extern __ph<1> _1; |
| 1865 | extern __ph<2> _2; |
| 1866 | extern __ph<3> _3; |
| 1867 | extern __ph<4> _4; |
| 1868 | extern __ph<5> _5; |
| 1869 | extern __ph<6> _6; |
| 1870 | extern __ph<7> _7; |
| 1871 | extern __ph<8> _8; |
| 1872 | extern __ph<9> _9; |
| 1873 | extern __ph<10> _10; |
| 1874 | |
| 1875 | } // placeholders |
| 1876 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1877 | template<int _Np> |
| 1878 | struct __is_placeholder<placeholders::__ph<_Np> > |
| 1879 | : public integral_constant<int, _Np> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1880 | |
| 1881 | template <class _Tp, class _Uj> |
| 1882 | inline _LIBCPP_INLINE_VISIBILITY |
| 1883 | _Tp& |
| 1884 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 1885 | { |
| 1886 | return __t.get(); |
| 1887 | } |
| 1888 | /* |
| 1889 | template <bool _IsBindExpr, class _Ti, class ..._Uj> |
| 1890 | struct __mu_return1 {}; |
| 1891 | |
| 1892 | template <class _Ti, class ..._Uj> |
| 1893 | struct __mu_return1<true, _Ti, _Uj...> |
| 1894 | { |
| 1895 | typedef typename result_of<_Ti(_Uj...)>::type type; |
| 1896 | }; |
| 1897 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1898 | template <class _Ti, class ..._Uj, size_t ..._Indx> |
| 1899 | inline _LIBCPP_INLINE_VISIBILITY |
| 1900 | typename __mu_return1<true, _Ti, _Uj...>::type |
| 1901 | __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>) |
| 1902 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1903 | __ti(_VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj))...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | template <class _Ti, class ..._Uj> |
| 1907 | inline _LIBCPP_INLINE_VISIBILITY |
| 1908 | typename enable_if |
| 1909 | < |
| 1910 | is_bind_expression<_Ti>::value, |
| 1911 | typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type |
| 1912 | >::type |
| 1913 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) |
| 1914 | { |
| 1915 | typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; |
| 1916 | return __mu_expand(__ti, __uj, __indices()); |
| 1917 | } |
| 1918 | |
| 1919 | template <bool IsPh, class _Ti, class _Uj> |
| 1920 | struct __mu_return2 {}; |
| 1921 | |
| 1922 | template <class _Ti, class _Uj> |
| 1923 | struct __mu_return2<true, _Ti, _Uj> |
| 1924 | { |
| 1925 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; |
| 1926 | }; |
| 1927 | |
| 1928 | template <class _Ti, class _Uj> |
| 1929 | inline _LIBCPP_INLINE_VISIBILITY |
| 1930 | typename enable_if |
| 1931 | < |
| 1932 | 0 < is_placeholder<_Ti>::value, |
| 1933 | typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type |
| 1934 | >::type |
| 1935 | __mu(_Ti&, _Uj& __uj) |
| 1936 | { |
| 1937 | const size_t _Indx = is_placeholder<_Ti>::value - 1; |
| 1938 | // compiler bug workaround |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1939 | typename tuple_element<_Indx, _Uj>::type __t = _VSTD::get<_Indx>(__uj); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1940 | return __t; |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1941 | // return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | template <class _Ti, class _Uj> |
| 1945 | inline _LIBCPP_INLINE_VISIBILITY |
| 1946 | typename enable_if |
| 1947 | < |
| 1948 | !is_bind_expression<_Ti>::value && |
| 1949 | is_placeholder<_Ti>::value == 0 && |
| 1950 | !__is_reference_wrapper<_Ti>::value, |
| 1951 | _Ti& |
| 1952 | >::type |
| 1953 | __mu(_Ti& __ti, _Uj& __uj) |
| 1954 | { |
| 1955 | return __ti; |
| 1956 | } |
| 1957 | |
| 1958 | template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj> |
| 1959 | struct ____mu_return; |
| 1960 | |
| 1961 | template <class _Ti, class ..._Uj> |
| 1962 | struct ____mu_return<_Ti, true, false, tuple<_Uj...> > |
| 1963 | { |
| 1964 | typedef typename result_of<_Ti(_Uj...)>::type type; |
| 1965 | }; |
| 1966 | |
| 1967 | template <class _Ti, class _TupleUj> |
| 1968 | struct ____mu_return<_Ti, false, true, _TupleUj> |
| 1969 | { |
| 1970 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 1971 | _TupleUj>::type&& type; |
| 1972 | }; |
| 1973 | |
| 1974 | template <class _Ti, class _TupleUj> |
| 1975 | struct ____mu_return<_Ti, false, false, _TupleUj> |
| 1976 | { |
| 1977 | typedef _Ti& type; |
| 1978 | }; |
| 1979 | |
| 1980 | template <class _Ti, class _TupleUj> |
| 1981 | struct __mu_return |
| 1982 | : public ____mu_return<_Ti, |
| 1983 | is_bind_expression<_Ti>::value, |
| 1984 | 0 < is_placeholder<_Ti>::value, |
| 1985 | _TupleUj> |
| 1986 | { |
| 1987 | }; |
| 1988 | |
| 1989 | template <class _Ti, class _TupleUj> |
| 1990 | struct __mu_return<reference_wrapper<_Ti>, _TupleUj> |
| 1991 | { |
| 1992 | typedef _Ti& type; |
| 1993 | }; |
| 1994 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1995 | template <class _Fp, class _BoundArgs, class _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1996 | struct __bind_return; |
| 1997 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1998 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
| 1999 | struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2000 | { |
| 2001 | typedef typename __ref_return |
| 2002 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2003 | _Fp&, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2004 | typename __mu_return |
| 2005 | < |
| 2006 | _BoundArgs, |
| 2007 | _TupleUj |
| 2008 | >::type... |
| 2009 | >::type type; |
| 2010 | }; |
| 2011 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2012 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
| 2013 | struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2014 | { |
| 2015 | typedef typename __ref_return |
| 2016 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2017 | _Fp&, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2018 | typename __mu_return |
| 2019 | < |
| 2020 | const _BoundArgs, |
| 2021 | _TupleUj |
| 2022 | >::type... |
| 2023 | >::type type; |
| 2024 | }; |
| 2025 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2026 | template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2027 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2028 | typename __bind_return<_Fp, _BoundArgs, _Args>::type |
| 2029 | __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2030 | _Args&& __args) |
| 2031 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2032 | return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2035 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2036 | class __bind |
| 2037 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2038 | _Fp __f_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2039 | tuple<_BoundArgs...> __bound_args_; |
| 2040 | |
| 2041 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 2042 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2043 | template <class _Gp, class ..._BA> |
| 2044 | explicit __bind(_Gp&& __f, _BA&& ...__bound_args) |
| 2045 | : __f_(_VSTD::forward<_Gp>(__f)), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2046 | __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2047 | |
| 2048 | template <class ..._Args> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2049 | typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2050 | operator()(_Args&& ...__args) |
| 2051 | { |
| 2052 | // compiler bug workaround |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2053 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2054 | tuple<_Args&&...>(__args...)); |
| 2055 | } |
| 2056 | |
| 2057 | template <class ..._Args> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2058 | typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2059 | operator()(_Args&& ...__args) const |
| 2060 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2061 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2062 | tuple<_Args&&...>(__args...)); |
| 2063 | } |
| 2064 | }; |
| 2065 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2066 | template<class _Fp, class ..._BoundArgs> |
| 2067 | struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2068 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2069 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2070 | class __bind_r |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2071 | : public __bind<_Fp, _BoundArgs...> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2072 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2073 | typedef __bind<_Fp, _BoundArgs...> base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2074 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2075 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2077 | template <class _Gp, class ..._BA> |
| 2078 | explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) |
| 2079 | : base(_VSTD::forward<_Gp>(__f), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2080 | _VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2081 | |
| 2082 | template <class ..._Args> |
| 2083 | result_type |
| 2084 | operator()(_Args&& ...__args) |
| 2085 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2086 | return base::operator()(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | template <class ..._Args> |
| 2090 | result_type |
| 2091 | operator()(_Args&& ...__args) const |
| 2092 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2093 | return base::operator()(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2094 | } |
| 2095 | }; |
| 2096 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2097 | template<class _Rp, class _Fp, class ..._BoundArgs> |
| 2098 | struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2099 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2100 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2101 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2102 | __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> |
| 2103 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2104 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2105 | typedef __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type; |
| 2106 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2109 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2110 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2111 | __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> |
| 2112 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2113 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2114 | typedef __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type; |
| 2115 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2116 | } |
| 2117 | */ |
| 2118 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2119 | #endif // _LIBCPP_FUNCTIONAL_03 |