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; |
| 828 | } |
| 829 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 830 | template<class _Rp> |
| 831 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 832 | typename enable_if |
| 833 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 834 | !is_integral<_Fp>::value, |
| 835 | function<_Rp()>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 836 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 837 | function<_Rp()>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 838 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 839 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 840 | return *this; |
| 841 | } |
| 842 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 843 | template<class _Rp> |
| 844 | function<_Rp()>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 845 | { |
| 846 | if (__f_ == (__base*)&__buf_) |
| 847 | __f_->destroy(); |
| 848 | else if (__f_) |
| 849 | __f_->destroy_deallocate(); |
| 850 | } |
| 851 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 852 | template<class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 853 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 854 | function<_Rp()>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 855 | { |
| 856 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 857 | { |
| 858 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 859 | __base* __t = (__base*)&__tempbuf; |
| 860 | __f_->__clone(__t); |
| 861 | __f_->destroy(); |
| 862 | __f_ = 0; |
| 863 | __f.__f_->__clone((__base*)&__buf_); |
| 864 | __f.__f_->destroy(); |
| 865 | __f.__f_ = 0; |
| 866 | __f_ = (__base*)&__buf_; |
| 867 | __t->__clone((__base*)&__f.__buf_); |
| 868 | __t->destroy(); |
| 869 | __f.__f_ = (__base*)&__f.__buf_; |
| 870 | } |
| 871 | else if (__f_ == (__base*)&__buf_) |
| 872 | { |
| 873 | __f_->__clone((__base*)&__f.__buf_); |
| 874 | __f_->destroy(); |
| 875 | __f_ = __f.__f_; |
| 876 | __f.__f_ = (__base*)&__f.__buf_; |
| 877 | } |
| 878 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 879 | { |
| 880 | __f.__f_->__clone((__base*)&__buf_); |
| 881 | __f.__f_->destroy(); |
| 882 | __f.__f_ = __f_; |
| 883 | __f_ = (__base*)&__buf_; |
| 884 | } |
| 885 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 886 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 889 | template<class _Rp> |
| 890 | _Rp |
| 891 | function<_Rp()>::operator()() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 892 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 893 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 894 | if (__f_ == 0) |
| 895 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 896 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 897 | return (*__f_)(); |
| 898 | } |
| 899 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 900 | #ifndef _LIBCPP_NO_RTTI |
| 901 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 902 | template<class _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 903 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 904 | function<_Rp()>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 905 | { |
| 906 | if (__f_ == 0) |
| 907 | return typeid(void); |
| 908 | return __f_->target_type(); |
| 909 | } |
| 910 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 911 | template<class _Rp> |
| 912 | template <typename _Tp> |
| 913 | _Tp* |
| 914 | function<_Rp()>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | { |
| 916 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 917 | return (_Tp*)0; |
| 918 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 921 | template<class _Rp> |
| 922 | template <typename _Tp> |
| 923 | const _Tp* |
| 924 | function<_Rp()>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 925 | { |
| 926 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 927 | return (const _Tp*)0; |
| 928 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 929 | } |
| 930 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 931 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 932 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 933 | template<class _Rp, class _A0> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 934 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 935 | : public unary_function<_A0, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 936 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 937 | typedef __function::__base<_Rp(_A0)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 938 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 939 | __base* __f_; |
| 940 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 941 | template <class _Fp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 942 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 943 | static bool __not_null(const _Fp&) {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 944 | template <class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 945 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 946 | static bool __not_null(_R2 (*__p)(_B0)) {return __p;} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 947 | template <class _R2, class _Cp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 948 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 949 | static bool __not_null(_R2 (_Cp::*__p)()) {return __p;} |
| 950 | template <class _R2, class _Cp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 951 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 952 | static bool __not_null(_R2 (_Cp::*__p)() const) {return __p;} |
| 953 | template <class _R2, class _Cp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 954 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 955 | static bool __not_null(_R2 (_Cp::*__p)() volatile) {return __p;} |
| 956 | template <class _R2, class _Cp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 957 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 958 | static bool __not_null(_R2 (_Cp::*__p)() const volatile) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | template <class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 960 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 2f9e714 | 2014-06-30 21:27:51 +0000 | [diff] [blame] | 961 | static bool __not_null(const function<_R2(_B0)>& __p) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 962 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 963 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 964 | |
| 965 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 966 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 967 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 968 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 969 | template<class _Fp> |
| 970 | function(_Fp, |
| 971 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 972 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 973 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 974 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 975 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 976 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 977 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 978 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 979 | template<class _Alloc> |
| 980 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 981 | template<class _Fp, class _Alloc> |
| 982 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 983 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 984 | |
| 985 | function& operator=(const function&); |
| 986 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 987 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 988 | typename enable_if |
| 989 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 990 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 991 | function& |
| 992 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 993 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | |
| 995 | ~function(); |
| 996 | |
| 997 | // 20.7.16.2.2, function modifiers: |
| 998 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 999 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1001 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1002 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1003 | |
| 1004 | // 20.7.16.2.3, function capacity: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1005 | _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1006 | |
| 1007 | private: |
| 1008 | // deleted overloads close possible hole in the type system |
| 1009 | template<class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1010 | bool operator==(const function<_R2(_B0)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1011 | template<class _R2, class _B0> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1012 | bool operator!=(const function<_R2(_B0)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1013 | public: |
| 1014 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1015 | _Rp operator()(_A0) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1016 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1017 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1018 | // 20.7.16.2.5, function target access: |
| 1019 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1020 | template <typename _Tp> _Tp* target(); |
| 1021 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1022 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1023 | }; |
| 1024 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1025 | template<class _Rp, class _A0> |
| 1026 | function<_Rp(_A0)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1027 | { |
| 1028 | if (__f.__f_ == 0) |
| 1029 | __f_ = 0; |
| 1030 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1031 | { |
| 1032 | __f_ = (__base*)&__buf_; |
| 1033 | __f.__f_->__clone(__f_); |
| 1034 | } |
| 1035 | else |
| 1036 | __f_ = __f.__f_->__clone(); |
| 1037 | } |
| 1038 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1039 | template<class _Rp, class _A0> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1040 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1041 | function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1042 | { |
| 1043 | if (__f.__f_ == 0) |
| 1044 | __f_ = 0; |
| 1045 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1046 | { |
| 1047 | __f_ = (__base*)&__buf_; |
| 1048 | __f.__f_->__clone(__f_); |
| 1049 | } |
| 1050 | else |
| 1051 | __f_ = __f.__f_->__clone(); |
| 1052 | } |
| 1053 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1054 | template<class _Rp, class _A0> |
| 1055 | template <class _Fp> |
| 1056 | function<_Rp(_A0)>::function(_Fp __f, |
| 1057 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1058 | : __f_(0) |
| 1059 | { |
| 1060 | if (__not_null(__f)) |
| 1061 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1062 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1063 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1064 | { |
| 1065 | __f_ = (__base*)&__buf_; |
| 1066 | ::new (__f_) _FF(__f); |
| 1067 | } |
| 1068 | else |
| 1069 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1070 | typedef allocator<_FF> _Ap; |
| 1071 | _Ap __a; |
| 1072 | typedef __allocator_destructor<_Ap> _Dp; |
| 1073 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1074 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1075 | __f_ = __hold.release(); |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1080 | template<class _Rp, class _A0> |
| 1081 | template <class _Fp, class _Alloc> |
| 1082 | function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1083 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1084 | : __f_(0) |
| 1085 | { |
| 1086 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1087 | if (__not_null(__f)) |
| 1088 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1089 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1090 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1091 | { |
| 1092 | __f_ = (__base*)&__buf_; |
| 1093 | ::new (__f_) _FF(__f); |
| 1094 | } |
| 1095 | else |
| 1096 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame^] | 1097 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1098 | _Ap __a(__a0); |
| 1099 | typedef __allocator_destructor<_Ap> _Dp; |
| 1100 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1101 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 1102 | __f_ = __hold.release(); |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1107 | template<class _Rp, class _A0> |
| 1108 | function<_Rp(_A0)>& |
| 1109 | function<_Rp(_A0)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1110 | { |
| 1111 | function(__f).swap(*this); |
| 1112 | return *this; |
| 1113 | } |
| 1114 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1115 | template<class _Rp, class _A0> |
| 1116 | function<_Rp(_A0)>& |
| 1117 | function<_Rp(_A0)>::operator=(nullptr_t) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | { |
| 1119 | if (__f_ == (__base*)&__buf_) |
| 1120 | __f_->destroy(); |
| 1121 | else if (__f_) |
| 1122 | __f_->destroy_deallocate(); |
| 1123 | __f_ = 0; |
| 1124 | } |
| 1125 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1126 | template<class _Rp, class _A0> |
| 1127 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1128 | typename enable_if |
| 1129 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1130 | !is_integral<_Fp>::value, |
| 1131 | function<_Rp(_A0)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1132 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1133 | function<_Rp(_A0)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1134 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1135 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1136 | return *this; |
| 1137 | } |
| 1138 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1139 | template<class _Rp, class _A0> |
| 1140 | function<_Rp(_A0)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1141 | { |
| 1142 | if (__f_ == (__base*)&__buf_) |
| 1143 | __f_->destroy(); |
| 1144 | else if (__f_) |
| 1145 | __f_->destroy_deallocate(); |
| 1146 | } |
| 1147 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1148 | template<class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1149 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1150 | function<_Rp(_A0)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1151 | { |
| 1152 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1153 | { |
| 1154 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1155 | __base* __t = (__base*)&__tempbuf; |
| 1156 | __f_->__clone(__t); |
| 1157 | __f_->destroy(); |
| 1158 | __f_ = 0; |
| 1159 | __f.__f_->__clone((__base*)&__buf_); |
| 1160 | __f.__f_->destroy(); |
| 1161 | __f.__f_ = 0; |
| 1162 | __f_ = (__base*)&__buf_; |
| 1163 | __t->__clone((__base*)&__f.__buf_); |
| 1164 | __t->destroy(); |
| 1165 | __f.__f_ = (__base*)&__f.__buf_; |
| 1166 | } |
| 1167 | else if (__f_ == (__base*)&__buf_) |
| 1168 | { |
| 1169 | __f_->__clone((__base*)&__f.__buf_); |
| 1170 | __f_->destroy(); |
| 1171 | __f_ = __f.__f_; |
| 1172 | __f.__f_ = (__base*)&__f.__buf_; |
| 1173 | } |
| 1174 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1175 | { |
| 1176 | __f.__f_->__clone((__base*)&__buf_); |
| 1177 | __f.__f_->destroy(); |
| 1178 | __f.__f_ = __f_; |
| 1179 | __f_ = (__base*)&__buf_; |
| 1180 | } |
| 1181 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1182 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1185 | template<class _Rp, class _A0> |
| 1186 | _Rp |
| 1187 | function<_Rp(_A0)>::operator()(_A0 __a0) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1188 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1189 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1190 | if (__f_ == 0) |
| 1191 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1192 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1193 | return (*__f_)(__a0); |
| 1194 | } |
| 1195 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1196 | #ifndef _LIBCPP_NO_RTTI |
| 1197 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1198 | template<class _Rp, class _A0> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1199 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1200 | function<_Rp(_A0)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1201 | { |
| 1202 | if (__f_ == 0) |
| 1203 | return typeid(void); |
| 1204 | return __f_->target_type(); |
| 1205 | } |
| 1206 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1207 | template<class _Rp, class _A0> |
| 1208 | template <typename _Tp> |
| 1209 | _Tp* |
| 1210 | function<_Rp(_A0)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1211 | { |
| 1212 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1213 | return (_Tp*)0; |
| 1214 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1217 | template<class _Rp, class _A0> |
| 1218 | template <typename _Tp> |
| 1219 | const _Tp* |
| 1220 | function<_Rp(_A0)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1221 | { |
| 1222 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1223 | return (const _Tp*)0; |
| 1224 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1227 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1228 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1229 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1230 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1231 | : public binary_function<_A0, _A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1232 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1233 | typedef __function::__base<_Rp(_A0, _A1)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1235 | __base* __f_; |
| 1236 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1237 | template <class _Fp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1239 | static bool __not_null(const _Fp&) {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1240 | template <class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1241 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1242 | static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1243 | template <class _R2, class _Cp, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1244 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1245 | static bool __not_null(_R2 (_Cp::*__p)(_B1)) {return __p;} |
| 1246 | template <class _R2, class _Cp, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1247 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1248 | static bool __not_null(_R2 (_Cp::*__p)(_B1) const) {return __p;} |
| 1249 | template <class _R2, class _Cp, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1251 | static bool __not_null(_R2 (_Cp::*__p)(_B1) volatile) {return __p;} |
| 1252 | template <class _R2, class _Cp, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1253 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1254 | static bool __not_null(_R2 (_Cp::*__p)(_B1) const volatile) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1255 | template <class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1256 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 2f9e714 | 2014-06-30 21:27:51 +0000 | [diff] [blame] | 1257 | static bool __not_null(const function<_R2(_B0, _B1)>& __p) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1258 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1259 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1260 | |
| 1261 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1262 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 1263 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1264 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1265 | template<class _Fp> |
| 1266 | function(_Fp, |
| 1267 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1268 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1269 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1270 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1271 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 1272 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1273 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1274 | function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} |
| 1275 | template<class _Alloc> |
| 1276 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1277 | template<class _Fp, class _Alloc> |
| 1278 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 1279 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1280 | |
| 1281 | function& operator=(const function&); |
| 1282 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1283 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1284 | typename enable_if |
| 1285 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1286 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1287 | function& |
| 1288 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1289 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1290 | |
| 1291 | ~function(); |
| 1292 | |
| 1293 | // 20.7.16.2.2, function modifiers: |
| 1294 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1295 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1297 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1298 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1299 | |
| 1300 | // 20.7.16.2.3, function capacity: |
| 1301 | operator bool() const {return __f_;} |
| 1302 | |
| 1303 | private: |
| 1304 | // deleted overloads close possible hole in the type system |
| 1305 | template<class _R2, class _B0, class _B1> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1306 | bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | public: |
| 1310 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1311 | _Rp operator()(_A0, _A1) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1312 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1313 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1314 | // 20.7.16.2.5, function target access: |
| 1315 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1316 | template <typename _Tp> _Tp* target(); |
| 1317 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1318 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1319 | }; |
| 1320 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1321 | template<class _Rp, class _A0, class _A1> |
| 1322 | function<_Rp(_A0, _A1)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1323 | { |
| 1324 | if (__f.__f_ == 0) |
| 1325 | __f_ = 0; |
| 1326 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1327 | { |
| 1328 | __f_ = (__base*)&__buf_; |
| 1329 | __f.__f_->__clone(__f_); |
| 1330 | } |
| 1331 | else |
| 1332 | __f_ = __f.__f_->__clone(); |
| 1333 | } |
| 1334 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1335 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1336 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1337 | 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] | 1338 | { |
| 1339 | if (__f.__f_ == 0) |
| 1340 | __f_ = 0; |
| 1341 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1342 | { |
| 1343 | __f_ = (__base*)&__buf_; |
| 1344 | __f.__f_->__clone(__f_); |
| 1345 | } |
| 1346 | else |
| 1347 | __f_ = __f.__f_->__clone(); |
| 1348 | } |
| 1349 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1350 | template<class _Rp, class _A0, class _A1> |
| 1351 | template <class _Fp> |
| 1352 | function<_Rp(_A0, _A1)>::function(_Fp __f, |
| 1353 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1354 | : __f_(0) |
| 1355 | { |
| 1356 | if (__not_null(__f)) |
| 1357 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1358 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1359 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1360 | { |
| 1361 | __f_ = (__base*)&__buf_; |
| 1362 | ::new (__f_) _FF(__f); |
| 1363 | } |
| 1364 | else |
| 1365 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1366 | typedef allocator<_FF> _Ap; |
| 1367 | _Ap __a; |
| 1368 | typedef __allocator_destructor<_Ap> _Dp; |
| 1369 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1370 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1371 | __f_ = __hold.release(); |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1376 | template<class _Rp, class _A0, class _A1> |
| 1377 | template <class _Fp, class _Alloc> |
| 1378 | function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1379 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1380 | : __f_(0) |
| 1381 | { |
| 1382 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1383 | if (__not_null(__f)) |
| 1384 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1385 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1386 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1387 | { |
| 1388 | __f_ = (__base*)&__buf_; |
| 1389 | ::new (__f_) _FF(__f); |
| 1390 | } |
| 1391 | else |
| 1392 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame^] | 1393 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1394 | _Ap __a(__a0); |
| 1395 | typedef __allocator_destructor<_Ap> _Dp; |
| 1396 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1397 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 1398 | __f_ = __hold.release(); |
| 1399 | } |
| 1400 | } |
| 1401 | } |
| 1402 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1403 | template<class _Rp, class _A0, class _A1> |
| 1404 | function<_Rp(_A0, _A1)>& |
| 1405 | function<_Rp(_A0, _A1)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1406 | { |
| 1407 | function(__f).swap(*this); |
| 1408 | return *this; |
| 1409 | } |
| 1410 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1411 | template<class _Rp, class _A0, class _A1> |
| 1412 | function<_Rp(_A0, _A1)>& |
| 1413 | function<_Rp(_A0, _A1)>::operator=(nullptr_t) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1414 | { |
| 1415 | if (__f_ == (__base*)&__buf_) |
| 1416 | __f_->destroy(); |
| 1417 | else if (__f_) |
| 1418 | __f_->destroy_deallocate(); |
| 1419 | __f_ = 0; |
| 1420 | } |
| 1421 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1422 | template<class _Rp, class _A0, class _A1> |
| 1423 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1424 | typename enable_if |
| 1425 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1426 | !is_integral<_Fp>::value, |
| 1427 | function<_Rp(_A0, _A1)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1428 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1429 | function<_Rp(_A0, _A1)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1431 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1432 | return *this; |
| 1433 | } |
| 1434 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1435 | template<class _Rp, class _A0, class _A1> |
| 1436 | function<_Rp(_A0, _A1)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1437 | { |
| 1438 | if (__f_ == (__base*)&__buf_) |
| 1439 | __f_->destroy(); |
| 1440 | else if (__f_) |
| 1441 | __f_->destroy_deallocate(); |
| 1442 | } |
| 1443 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1444 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1445 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1446 | function<_Rp(_A0, _A1)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1447 | { |
| 1448 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1449 | { |
| 1450 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1451 | __base* __t = (__base*)&__tempbuf; |
| 1452 | __f_->__clone(__t); |
| 1453 | __f_->destroy(); |
| 1454 | __f_ = 0; |
| 1455 | __f.__f_->__clone((__base*)&__buf_); |
| 1456 | __f.__f_->destroy(); |
| 1457 | __f.__f_ = 0; |
| 1458 | __f_ = (__base*)&__buf_; |
| 1459 | __t->__clone((__base*)&__f.__buf_); |
| 1460 | __t->destroy(); |
| 1461 | __f.__f_ = (__base*)&__f.__buf_; |
| 1462 | } |
| 1463 | else if (__f_ == (__base*)&__buf_) |
| 1464 | { |
| 1465 | __f_->__clone((__base*)&__f.__buf_); |
| 1466 | __f_->destroy(); |
| 1467 | __f_ = __f.__f_; |
| 1468 | __f.__f_ = (__base*)&__f.__buf_; |
| 1469 | } |
| 1470 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1471 | { |
| 1472 | __f.__f_->__clone((__base*)&__buf_); |
| 1473 | __f.__f_->destroy(); |
| 1474 | __f.__f_ = __f_; |
| 1475 | __f_ = (__base*)&__buf_; |
| 1476 | } |
| 1477 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1478 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1481 | template<class _Rp, class _A0, class _A1> |
| 1482 | _Rp |
| 1483 | function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1484 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1485 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | if (__f_ == 0) |
| 1487 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1488 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1489 | return (*__f_)(__a0, __a1); |
| 1490 | } |
| 1491 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1492 | #ifndef _LIBCPP_NO_RTTI |
| 1493 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1494 | template<class _Rp, class _A0, class _A1> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1495 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1496 | function<_Rp(_A0, _A1)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1497 | { |
| 1498 | if (__f_ == 0) |
| 1499 | return typeid(void); |
| 1500 | return __f_->target_type(); |
| 1501 | } |
| 1502 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1503 | template<class _Rp, class _A0, class _A1> |
| 1504 | template <typename _Tp> |
| 1505 | _Tp* |
| 1506 | function<_Rp(_A0, _A1)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1507 | { |
| 1508 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1509 | return (_Tp*)0; |
| 1510 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1513 | template<class _Rp, class _A0, class _A1> |
| 1514 | template <typename _Tp> |
| 1515 | const _Tp* |
| 1516 | function<_Rp(_A0, _A1)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1517 | { |
| 1518 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1519 | return (const _Tp*)0; |
| 1520 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1523 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1524 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1525 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1526 | class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1527 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1528 | typedef __function::__base<_Rp(_A0, _A1, _A2)> __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1529 | aligned_storage<3*sizeof(void*)>::type __buf_; |
| 1530 | __base* __f_; |
| 1531 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1532 | template <class _Fp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1533 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1534 | static bool __not_null(const _Fp&) {return true;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | template <class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1536 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1537 | static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;} |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1538 | template <class _R2, class _Cp, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1540 | static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2)) {return __p;} |
| 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) const) {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) volatile) {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) const volatile) {return __p;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1550 | template <class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1551 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 2f9e714 | 2014-06-30 21:27:51 +0000 | [diff] [blame] | 1552 | 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] | 1553 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1554 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1555 | |
| 1556 | // 20.7.16.2.1, construct/copy/destroy: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1557 | _LIBCPP_INLINE_VISIBILITY explicit function() : __f_(0) {} |
| 1558 | _LIBCPP_INLINE_VISIBILITY function(nullptr_t) : __f_(0) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1559 | function(const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1560 | template<class _Fp> |
| 1561 | function(_Fp, |
| 1562 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1563 | |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1564 | template<class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1566 | function(allocator_arg_t, const _Alloc&) : __f_(0) {} |
| 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&, nullptr_t) : __f_(0) {} |
| 1570 | template<class _Alloc> |
| 1571 | function(allocator_arg_t, const _Alloc&, const function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1572 | template<class _Fp, class _Alloc> |
| 1573 | function(allocator_arg_t, const _Alloc& __a, _Fp __f, |
| 1574 | typename enable_if<!is_integral<_Fp>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1575 | |
| 1576 | function& operator=(const function&); |
| 1577 | function& operator=(nullptr_t); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1578 | template<class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1579 | typename enable_if |
| 1580 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1581 | !is_integral<_Fp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1582 | function& |
| 1583 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1584 | operator=(_Fp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1585 | |
| 1586 | ~function(); |
| 1587 | |
| 1588 | // 20.7.16.2.2, function modifiers: |
| 1589 | void swap(function&); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1590 | template<class _Fp, class _Alloc> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1592 | void assign(_Fp __f, const _Alloc& __a) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1593 | {function(allocator_arg, __a, __f).swap(*this);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1594 | |
| 1595 | // 20.7.16.2.3, function capacity: |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1596 | _LIBCPP_INLINE_VISIBILITY operator bool() const {return __f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | |
| 1598 | private: |
| 1599 | // deleted overloads close possible hole in the type system |
| 1600 | template<class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1601 | bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1602 | template<class _R2, class _B0, class _B1, class _B2> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 1603 | bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1604 | public: |
| 1605 | // 20.7.16.2.4, function invocation: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1606 | _Rp operator()(_A0, _A1, _A2) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1607 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1608 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1609 | // 20.7.16.2.5, function target access: |
| 1610 | const std::type_info& target_type() const; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1611 | template <typename _Tp> _Tp* target(); |
| 1612 | template <typename _Tp> const _Tp* target() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1613 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1614 | }; |
| 1615 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1616 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1617 | function<_Rp(_A0, _A1, _A2)>::function(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1618 | { |
| 1619 | if (__f.__f_ == 0) |
| 1620 | __f_ = 0; |
| 1621 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1622 | { |
| 1623 | __f_ = (__base*)&__buf_; |
| 1624 | __f.__f_->__clone(__f_); |
| 1625 | } |
| 1626 | else |
| 1627 | __f_ = __f.__f_->__clone(); |
| 1628 | } |
| 1629 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1630 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1631 | template<class _Alloc> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1632 | function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&, |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1633 | const function& __f) |
| 1634 | { |
| 1635 | if (__f.__f_ == 0) |
| 1636 | __f_ = 0; |
| 1637 | else if (__f.__f_ == (const __base*)&__f.__buf_) |
| 1638 | { |
| 1639 | __f_ = (__base*)&__buf_; |
| 1640 | __f.__f_->__clone(__f_); |
| 1641 | } |
| 1642 | else |
| 1643 | __f_ = __f.__f_->__clone(); |
| 1644 | } |
| 1645 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1646 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1647 | template <class _Fp> |
| 1648 | function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, |
| 1649 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | : __f_(0) |
| 1651 | { |
| 1652 | if (__not_null(__f)) |
| 1653 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1654 | typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1655 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1656 | { |
| 1657 | __f_ = (__base*)&__buf_; |
| 1658 | ::new (__f_) _FF(__f); |
| 1659 | } |
| 1660 | else |
| 1661 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1662 | typedef allocator<_FF> _Ap; |
| 1663 | _Ap __a; |
| 1664 | typedef __allocator_destructor<_Ap> _Dp; |
| 1665 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1666 | ::new (__hold.get()) _FF(__f, allocator<_Fp>(__a)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1667 | __f_ = __hold.release(); |
| 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1672 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1673 | template <class _Fp, class _Alloc> |
| 1674 | function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, |
| 1675 | typename enable_if<!is_integral<_Fp>::value>::type*) |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1676 | : __f_(0) |
| 1677 | { |
| 1678 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1679 | if (__not_null(__f)) |
| 1680 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1681 | typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1682 | if (sizeof(_FF) <= sizeof(__buf_)) |
| 1683 | { |
| 1684 | __f_ = (__base*)&__buf_; |
| 1685 | ::new (__f_) _FF(__f); |
| 1686 | } |
| 1687 | else |
| 1688 | { |
Marshall Clow | 66302c6 | 2015-04-07 05:21:38 +0000 | [diff] [blame^] | 1689 | typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1690 | _Ap __a(__a0); |
| 1691 | typedef __allocator_destructor<_Ap> _Dp; |
| 1692 | unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Howard Hinnant | 7255280 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 1693 | ::new (__hold.get()) _FF(__f, _Alloc(__a)); |
| 1694 | __f_ = __hold.release(); |
| 1695 | } |
| 1696 | } |
| 1697 | } |
| 1698 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1699 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1700 | function<_Rp(_A0, _A1, _A2)>& |
| 1701 | function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1702 | { |
| 1703 | function(__f).swap(*this); |
| 1704 | return *this; |
| 1705 | } |
| 1706 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1707 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1708 | function<_Rp(_A0, _A1, _A2)>& |
| 1709 | function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1710 | { |
| 1711 | if (__f_ == (__base*)&__buf_) |
| 1712 | __f_->destroy(); |
| 1713 | else if (__f_) |
| 1714 | __f_->destroy_deallocate(); |
| 1715 | __f_ = 0; |
| 1716 | } |
| 1717 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1718 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1719 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1720 | typename enable_if |
| 1721 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1722 | !is_integral<_Fp>::value, |
| 1723 | function<_Rp(_A0, _A1, _A2)>& |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1724 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1725 | function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1726 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1727 | function(_VSTD::move(__f)).swap(*this); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1728 | return *this; |
| 1729 | } |
| 1730 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1731 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1732 | function<_Rp(_A0, _A1, _A2)>::~function() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | { |
| 1734 | if (__f_ == (__base*)&__buf_) |
| 1735 | __f_->destroy(); |
| 1736 | else if (__f_) |
| 1737 | __f_->destroy_deallocate(); |
| 1738 | } |
| 1739 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1740 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1741 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1742 | function<_Rp(_A0, _A1, _A2)>::swap(function& __f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1743 | { |
| 1744 | if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) |
| 1745 | { |
| 1746 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 1747 | __base* __t = (__base*)&__tempbuf; |
| 1748 | __f_->__clone(__t); |
| 1749 | __f_->destroy(); |
| 1750 | __f_ = 0; |
| 1751 | __f.__f_->__clone((__base*)&__buf_); |
| 1752 | __f.__f_->destroy(); |
| 1753 | __f.__f_ = 0; |
| 1754 | __f_ = (__base*)&__buf_; |
| 1755 | __t->__clone((__base*)&__f.__buf_); |
| 1756 | __t->destroy(); |
| 1757 | __f.__f_ = (__base*)&__f.__buf_; |
| 1758 | } |
| 1759 | else if (__f_ == (__base*)&__buf_) |
| 1760 | { |
| 1761 | __f_->__clone((__base*)&__f.__buf_); |
| 1762 | __f_->destroy(); |
| 1763 | __f_ = __f.__f_; |
| 1764 | __f.__f_ = (__base*)&__f.__buf_; |
| 1765 | } |
| 1766 | else if (__f.__f_ == (__base*)&__f.__buf_) |
| 1767 | { |
| 1768 | __f.__f_->__clone((__base*)&__buf_); |
| 1769 | __f.__f_->destroy(); |
| 1770 | __f.__f_ = __f_; |
| 1771 | __f_ = (__base*)&__buf_; |
| 1772 | } |
| 1773 | else |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1774 | _VSTD::swap(__f_, __f.__f_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1777 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1778 | _Rp |
| 1779 | 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] | 1780 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1781 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | if (__f_ == 0) |
| 1783 | throw bad_function_call(); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1784 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1785 | return (*__f_)(__a0, __a1, __a2); |
| 1786 | } |
| 1787 | |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1788 | #ifndef _LIBCPP_NO_RTTI |
| 1789 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1790 | template<class _Rp, class _A0, class _A1, class _A2> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1791 | const std::type_info& |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1792 | function<_Rp(_A0, _A1, _A2)>::target_type() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1793 | { |
| 1794 | if (__f_ == 0) |
| 1795 | return typeid(void); |
| 1796 | return __f_->target_type(); |
| 1797 | } |
| 1798 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1799 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1800 | template <typename _Tp> |
| 1801 | _Tp* |
| 1802 | function<_Rp(_A0, _A1, _A2)>::target() |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1803 | { |
| 1804 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1805 | return (_Tp*)0; |
| 1806 | return (_Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1809 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1810 | template <typename _Tp> |
| 1811 | const _Tp* |
| 1812 | function<_Rp(_A0, _A1, _A2)>::target() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1813 | { |
| 1814 | if (__f_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1815 | return (const _Tp*)0; |
| 1816 | return (const _Tp*)__f_->target(typeid(_Tp)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1819 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1820 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1821 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1822 | inline _LIBCPP_INLINE_VISIBILITY |
| 1823 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1824 | operator==(const function<_Fp>& __f, nullptr_t) {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1825 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1826 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1827 | inline _LIBCPP_INLINE_VISIBILITY |
| 1828 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1829 | operator==(nullptr_t, const function<_Fp>& __f) {return !__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1830 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1831 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1832 | inline _LIBCPP_INLINE_VISIBILITY |
| 1833 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1834 | operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1835 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1836 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | inline _LIBCPP_INLINE_VISIBILITY |
| 1838 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1839 | operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1840 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1841 | template <class _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1842 | inline _LIBCPP_INLINE_VISIBILITY |
| 1843 | void |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1844 | swap(function<_Fp>& __x, function<_Fp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1845 | {return __x.swap(__y);} |
| 1846 | |
| 1847 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1848 | template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1849 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 1850 | |
| 1851 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1852 | template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1853 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 1854 | |
| 1855 | namespace placeholders |
| 1856 | { |
| 1857 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1858 | template <int _Np> struct __ph {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | |
| 1860 | extern __ph<1> _1; |
| 1861 | extern __ph<2> _2; |
| 1862 | extern __ph<3> _3; |
| 1863 | extern __ph<4> _4; |
| 1864 | extern __ph<5> _5; |
| 1865 | extern __ph<6> _6; |
| 1866 | extern __ph<7> _7; |
| 1867 | extern __ph<8> _8; |
| 1868 | extern __ph<9> _9; |
| 1869 | extern __ph<10> _10; |
| 1870 | |
| 1871 | } // placeholders |
| 1872 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1873 | template<int _Np> |
| 1874 | struct __is_placeholder<placeholders::__ph<_Np> > |
| 1875 | : public integral_constant<int, _Np> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1876 | |
| 1877 | template <class _Tp, class _Uj> |
| 1878 | inline _LIBCPP_INLINE_VISIBILITY |
| 1879 | _Tp& |
| 1880 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 1881 | { |
| 1882 | return __t.get(); |
| 1883 | } |
| 1884 | /* |
| 1885 | template <bool _IsBindExpr, class _Ti, class ..._Uj> |
| 1886 | struct __mu_return1 {}; |
| 1887 | |
| 1888 | template <class _Ti, class ..._Uj> |
| 1889 | struct __mu_return1<true, _Ti, _Uj...> |
| 1890 | { |
| 1891 | typedef typename result_of<_Ti(_Uj...)>::type type; |
| 1892 | }; |
| 1893 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1894 | template <class _Ti, class ..._Uj, size_t ..._Indx> |
| 1895 | inline _LIBCPP_INLINE_VISIBILITY |
| 1896 | typename __mu_return1<true, _Ti, _Uj...>::type |
| 1897 | __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>) |
| 1898 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1899 | __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] | 1900 | } |
| 1901 | |
| 1902 | template <class _Ti, class ..._Uj> |
| 1903 | inline _LIBCPP_INLINE_VISIBILITY |
| 1904 | typename enable_if |
| 1905 | < |
| 1906 | is_bind_expression<_Ti>::value, |
| 1907 | typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type |
| 1908 | >::type |
| 1909 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) |
| 1910 | { |
| 1911 | typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; |
| 1912 | return __mu_expand(__ti, __uj, __indices()); |
| 1913 | } |
| 1914 | |
| 1915 | template <bool IsPh, class _Ti, class _Uj> |
| 1916 | struct __mu_return2 {}; |
| 1917 | |
| 1918 | template <class _Ti, class _Uj> |
| 1919 | struct __mu_return2<true, _Ti, _Uj> |
| 1920 | { |
| 1921 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; |
| 1922 | }; |
| 1923 | |
| 1924 | template <class _Ti, class _Uj> |
| 1925 | inline _LIBCPP_INLINE_VISIBILITY |
| 1926 | typename enable_if |
| 1927 | < |
| 1928 | 0 < is_placeholder<_Ti>::value, |
| 1929 | typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type |
| 1930 | >::type |
| 1931 | __mu(_Ti&, _Uj& __uj) |
| 1932 | { |
| 1933 | const size_t _Indx = is_placeholder<_Ti>::value - 1; |
| 1934 | // compiler bug workaround |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1935 | typename tuple_element<_Indx, _Uj>::type __t = _VSTD::get<_Indx>(__uj); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1936 | return __t; |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 1937 | // 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] | 1938 | } |
| 1939 | |
| 1940 | template <class _Ti, class _Uj> |
| 1941 | inline _LIBCPP_INLINE_VISIBILITY |
| 1942 | typename enable_if |
| 1943 | < |
| 1944 | !is_bind_expression<_Ti>::value && |
| 1945 | is_placeholder<_Ti>::value == 0 && |
| 1946 | !__is_reference_wrapper<_Ti>::value, |
| 1947 | _Ti& |
| 1948 | >::type |
| 1949 | __mu(_Ti& __ti, _Uj& __uj) |
| 1950 | { |
| 1951 | return __ti; |
| 1952 | } |
| 1953 | |
| 1954 | template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj> |
| 1955 | struct ____mu_return; |
| 1956 | |
| 1957 | template <class _Ti, class ..._Uj> |
| 1958 | struct ____mu_return<_Ti, true, false, tuple<_Uj...> > |
| 1959 | { |
| 1960 | typedef typename result_of<_Ti(_Uj...)>::type type; |
| 1961 | }; |
| 1962 | |
| 1963 | template <class _Ti, class _TupleUj> |
| 1964 | struct ____mu_return<_Ti, false, true, _TupleUj> |
| 1965 | { |
| 1966 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 1967 | _TupleUj>::type&& type; |
| 1968 | }; |
| 1969 | |
| 1970 | template <class _Ti, class _TupleUj> |
| 1971 | struct ____mu_return<_Ti, false, false, _TupleUj> |
| 1972 | { |
| 1973 | typedef _Ti& type; |
| 1974 | }; |
| 1975 | |
| 1976 | template <class _Ti, class _TupleUj> |
| 1977 | struct __mu_return |
| 1978 | : public ____mu_return<_Ti, |
| 1979 | is_bind_expression<_Ti>::value, |
| 1980 | 0 < is_placeholder<_Ti>::value, |
| 1981 | _TupleUj> |
| 1982 | { |
| 1983 | }; |
| 1984 | |
| 1985 | template <class _Ti, class _TupleUj> |
| 1986 | struct __mu_return<reference_wrapper<_Ti>, _TupleUj> |
| 1987 | { |
| 1988 | typedef _Ti& type; |
| 1989 | }; |
| 1990 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1991 | template <class _Fp, class _BoundArgs, class _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1992 | struct __bind_return; |
| 1993 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1994 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
| 1995 | struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1996 | { |
| 1997 | typedef typename __ref_return |
| 1998 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1999 | _Fp&, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2000 | typename __mu_return |
| 2001 | < |
| 2002 | _BoundArgs, |
| 2003 | _TupleUj |
| 2004 | >::type... |
| 2005 | >::type type; |
| 2006 | }; |
| 2007 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2008 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
| 2009 | struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2010 | { |
| 2011 | typedef typename __ref_return |
| 2012 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2013 | _Fp&, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2014 | typename __mu_return |
| 2015 | < |
| 2016 | const _BoundArgs, |
| 2017 | _TupleUj |
| 2018 | >::type... |
| 2019 | >::type type; |
| 2020 | }; |
| 2021 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2022 | template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2023 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2024 | typename __bind_return<_Fp, _BoundArgs, _Args>::type |
| 2025 | __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2026 | _Args&& __args) |
| 2027 | { |
Marshall Clow | ba6dbf4 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2028 | return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2031 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2032 | class __bind |
| 2033 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2034 | _Fp __f_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2035 | tuple<_BoundArgs...> __bound_args_; |
| 2036 | |
| 2037 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 2038 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2039 | template <class _Gp, class ..._BA> |
| 2040 | explicit __bind(_Gp&& __f, _BA&& ...__bound_args) |
| 2041 | : __f_(_VSTD::forward<_Gp>(__f)), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2042 | __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2043 | |
| 2044 | template <class ..._Args> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2045 | typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2046 | operator()(_Args&& ...__args) |
| 2047 | { |
| 2048 | // compiler bug workaround |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2049 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2050 | tuple<_Args&&...>(__args...)); |
| 2051 | } |
| 2052 | |
| 2053 | template <class ..._Args> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2054 | typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2055 | operator()(_Args&& ...__args) const |
| 2056 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2057 | return __apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2058 | tuple<_Args&&...>(__args...)); |
| 2059 | } |
| 2060 | }; |
| 2061 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2062 | template<class _Fp, class ..._BoundArgs> |
| 2063 | struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2064 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2065 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2066 | class __bind_r |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2067 | : public __bind<_Fp, _BoundArgs...> |
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 | typedef __bind<_Fp, _BoundArgs...> base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2070 | public: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2071 | typedef _Rp result_type; |
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 | template <class _Gp, class ..._BA> |
| 2074 | explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) |
| 2075 | : base(_VSTD::forward<_Gp>(__f), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2076 | _VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2077 | |
| 2078 | template <class ..._Args> |
| 2079 | result_type |
| 2080 | operator()(_Args&& ...__args) |
| 2081 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2082 | return base::operator()(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | template <class ..._Args> |
| 2086 | result_type |
| 2087 | operator()(_Args&& ...__args) const |
| 2088 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2089 | return base::operator()(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2090 | } |
| 2091 | }; |
| 2092 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2093 | template<class _Rp, class _Fp, class ..._BoundArgs> |
| 2094 | struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2095 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2096 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2097 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2098 | __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> |
| 2099 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2100 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2101 | typedef __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type; |
| 2102 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2105 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2106 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2107 | __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> |
| 2108 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2109 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2110 | typedef __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type; |
| 2111 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2112 | } |
| 2113 | */ |
| 2114 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2115 | #endif // _LIBCPP_FUNCTIONAL_03 |