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_BASE |
| 12 | #define _LIBCPP_FUNCTIONAL_BASE |
| 13 | |
| 14 | #include <__config> |
| 15 | #include <type_traits> |
| 16 | #include <typeinfo> |
| 17 | #include <exception> |
Marshall Clow | 599e60d | 2013-09-12 02:11:16 +0000 | [diff] [blame] | 18 | #include <new> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 20 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 22 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | |
| 24 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 25 | |
| 26 | template <class _Arg, class _Result> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 27 | struct _LIBCPP_TYPE_VIS_ONLY unary_function |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | { |
| 29 | typedef _Arg argument_type; |
| 30 | typedef _Result result_type; |
| 31 | }; |
| 32 | |
| 33 | template <class _Arg1, class _Arg2, class _Result> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 34 | struct _LIBCPP_TYPE_VIS_ONLY binary_function |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | { |
| 36 | typedef _Arg1 first_argument_type; |
| 37 | typedef _Arg2 second_argument_type; |
| 38 | typedef _Result result_type; |
| 39 | }; |
| 40 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 41 | template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | |
| 43 | template <class _Tp> |
| 44 | struct __has_result_type |
| 45 | { |
| 46 | private: |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 47 | struct __two {char __lx; char __lxx;}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | template <class _Up> static __two __test(...); |
| 49 | template <class _Up> static char __test(typename _Up::result_type* = 0); |
| 50 | public: |
| 51 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 52 | }; |
| 53 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 54 | #if _LIBCPP_STD_VER > 11 |
| 55 | template <class _Tp = void> |
| 56 | #else |
Howard Hinnant | 3fadda3 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 57 | template <class _Tp> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 58 | #endif |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 59 | struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool> |
Howard Hinnant | 3fadda3 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 60 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 61 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 62 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | 3fadda3 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 63 | {return __x < __y;} |
| 64 | }; |
| 65 | |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 66 | #if _LIBCPP_STD_VER > 11 |
| 67 | template <> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 68 | struct _LIBCPP_TYPE_VIS_ONLY less<void> |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 69 | { |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 70 | template <class _T1, class _T2> |
| 71 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 72 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 59ac38c | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 73 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))) |
| 74 | -> decltype (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)) |
| 75 | { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); } |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 76 | typedef void is_transparent; |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 77 | }; |
| 78 | #endif |
| 79 | |
Howard Hinnant | a4e87ab | 2013-08-08 18:38:55 +0000 | [diff] [blame] | 80 | // addressof |
| 81 | |
| 82 | template <class _Tp> |
| 83 | inline _LIBCPP_INLINE_VISIBILITY |
| 84 | _Tp* |
| 85 | addressof(_Tp& __x) _NOEXCEPT |
| 86 | { |
| 87 | return (_Tp*)&reinterpret_cast<const volatile char&>(__x); |
| 88 | } |
| 89 | |
| 90 | #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) |
| 91 | // Objective-C++ Automatic Reference Counting uses qualified pointers |
| 92 | // that require special addressof() signatures. When |
| 93 | // _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler |
| 94 | // itself is providing these definitions. Otherwise, we provide them. |
| 95 | template <class _Tp> |
| 96 | inline _LIBCPP_INLINE_VISIBILITY |
| 97 | __strong _Tp* |
| 98 | addressof(__strong _Tp& __x) _NOEXCEPT |
| 99 | { |
| 100 | return &__x; |
| 101 | } |
| 102 | |
| 103 | #ifdef _LIBCPP_HAS_OBJC_ARC_WEAK |
| 104 | template <class _Tp> |
| 105 | inline _LIBCPP_INLINE_VISIBILITY |
| 106 | __weak _Tp* |
| 107 | addressof(__weak _Tp& __x) _NOEXCEPT |
| 108 | { |
| 109 | return &__x; |
| 110 | } |
| 111 | #endif |
| 112 | |
| 113 | template <class _Tp> |
| 114 | inline _LIBCPP_INLINE_VISIBILITY |
| 115 | __autoreleasing _Tp* |
| 116 | addressof(__autoreleasing _Tp& __x) _NOEXCEPT |
| 117 | { |
| 118 | return &__x; |
| 119 | } |
| 120 | |
| 121 | template <class _Tp> |
| 122 | inline _LIBCPP_INLINE_VISIBILITY |
| 123 | __unsafe_unretained _Tp* |
| 124 | addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT |
| 125 | { |
| 126 | return &__x; |
| 127 | } |
| 128 | #endif |
| 129 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 130 | |
| 131 | // __weak_result_type |
| 132 | |
| 133 | template <class _Tp> |
| 134 | struct __derives_from_unary_function |
| 135 | { |
| 136 | private: |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 137 | struct __two {char __lx; char __lxx;}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 138 | static __two __test(...); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 139 | template <class _Ap, class _Rp> |
| 140 | static unary_function<_Ap, _Rp> |
| 141 | __test(const volatile unary_function<_Ap, _Rp>*); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 142 | public: |
| 143 | static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; |
| 144 | typedef decltype(__test((_Tp*)0)) type; |
| 145 | }; |
| 146 | |
| 147 | template <class _Tp> |
| 148 | struct __derives_from_binary_function |
| 149 | { |
| 150 | private: |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 151 | struct __two {char __lx; char __lxx;}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 152 | static __two __test(...); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 153 | template <class _A1, class _A2, class _Rp> |
| 154 | static binary_function<_A1, _A2, _Rp> |
| 155 | __test(const volatile binary_function<_A1, _A2, _Rp>*); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | public: |
| 157 | static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; |
| 158 | typedef decltype(__test((_Tp*)0)) type; |
| 159 | }; |
| 160 | |
| 161 | template <class _Tp, bool = __derives_from_unary_function<_Tp>::value> |
| 162 | struct __maybe_derive_from_unary_function // bool is true |
| 163 | : public __derives_from_unary_function<_Tp>::type |
| 164 | { |
| 165 | }; |
| 166 | |
| 167 | template <class _Tp> |
| 168 | struct __maybe_derive_from_unary_function<_Tp, false> |
| 169 | { |
| 170 | }; |
| 171 | |
| 172 | template <class _Tp, bool = __derives_from_binary_function<_Tp>::value> |
| 173 | struct __maybe_derive_from_binary_function // bool is true |
| 174 | : public __derives_from_binary_function<_Tp>::type |
| 175 | { |
| 176 | }; |
| 177 | |
| 178 | template <class _Tp> |
| 179 | struct __maybe_derive_from_binary_function<_Tp, false> |
| 180 | { |
| 181 | }; |
| 182 | |
| 183 | template <class _Tp, bool = __has_result_type<_Tp>::value> |
| 184 | struct __weak_result_type_imp // bool is true |
| 185 | : public __maybe_derive_from_unary_function<_Tp>, |
| 186 | public __maybe_derive_from_binary_function<_Tp> |
| 187 | { |
| 188 | typedef typename _Tp::result_type result_type; |
| 189 | }; |
| 190 | |
| 191 | template <class _Tp> |
| 192 | struct __weak_result_type_imp<_Tp, false> |
| 193 | : public __maybe_derive_from_unary_function<_Tp>, |
| 194 | public __maybe_derive_from_binary_function<_Tp> |
| 195 | { |
| 196 | }; |
| 197 | |
| 198 | template <class _Tp> |
| 199 | struct __weak_result_type |
| 200 | : public __weak_result_type_imp<_Tp> |
| 201 | { |
| 202 | }; |
| 203 | |
| 204 | // 0 argument case |
| 205 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 206 | template <class _Rp> |
| 207 | struct __weak_result_type<_Rp ()> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 208 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 209 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 210 | }; |
| 211 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 212 | template <class _Rp> |
| 213 | struct __weak_result_type<_Rp (&)()> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 214 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 215 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | }; |
| 217 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 218 | template <class _Rp> |
| 219 | struct __weak_result_type<_Rp (*)()> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 221 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | // 1 argument case |
| 225 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 226 | template <class _Rp, class _A1> |
| 227 | struct __weak_result_type<_Rp (_A1)> |
| 228 | : public unary_function<_A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 229 | { |
| 230 | }; |
| 231 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 232 | template <class _Rp, class _A1> |
| 233 | struct __weak_result_type<_Rp (&)(_A1)> |
| 234 | : public unary_function<_A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | { |
| 236 | }; |
| 237 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 238 | template <class _Rp, class _A1> |
| 239 | struct __weak_result_type<_Rp (*)(_A1)> |
| 240 | : public unary_function<_A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 | { |
| 242 | }; |
| 243 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 244 | template <class _Rp, class _Cp> |
| 245 | struct __weak_result_type<_Rp (_Cp::*)()> |
| 246 | : public unary_function<_Cp*, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 247 | { |
| 248 | }; |
| 249 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 250 | template <class _Rp, class _Cp> |
| 251 | struct __weak_result_type<_Rp (_Cp::*)() const> |
| 252 | : public unary_function<const _Cp*, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 253 | { |
| 254 | }; |
| 255 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 256 | template <class _Rp, class _Cp> |
| 257 | struct __weak_result_type<_Rp (_Cp::*)() volatile> |
| 258 | : public unary_function<volatile _Cp*, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 259 | { |
| 260 | }; |
| 261 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 262 | template <class _Rp, class _Cp> |
| 263 | struct __weak_result_type<_Rp (_Cp::*)() const volatile> |
| 264 | : public unary_function<const volatile _Cp*, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 265 | { |
| 266 | }; |
| 267 | |
| 268 | // 2 argument case |
| 269 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 270 | template <class _Rp, class _A1, class _A2> |
| 271 | struct __weak_result_type<_Rp (_A1, _A2)> |
| 272 | : public binary_function<_A1, _A2, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 273 | { |
| 274 | }; |
| 275 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 276 | template <class _Rp, class _A1, class _A2> |
| 277 | struct __weak_result_type<_Rp (*)(_A1, _A2)> |
| 278 | : public binary_function<_A1, _A2, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 279 | { |
| 280 | }; |
| 281 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 282 | template <class _Rp, class _A1, class _A2> |
| 283 | struct __weak_result_type<_Rp (&)(_A1, _A2)> |
| 284 | : public binary_function<_A1, _A2, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 | { |
| 286 | }; |
| 287 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 288 | template <class _Rp, class _Cp, class _A1> |
| 289 | struct __weak_result_type<_Rp (_Cp::*)(_A1)> |
| 290 | : public binary_function<_Cp*, _A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 291 | { |
| 292 | }; |
| 293 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 294 | template <class _Rp, class _Cp, class _A1> |
| 295 | struct __weak_result_type<_Rp (_Cp::*)(_A1) const> |
| 296 | : public binary_function<const _Cp*, _A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 297 | { |
| 298 | }; |
| 299 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 300 | template <class _Rp, class _Cp, class _A1> |
| 301 | struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile> |
| 302 | : public binary_function<volatile _Cp*, _A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | { |
| 304 | }; |
| 305 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 306 | template <class _Rp, class _Cp, class _A1> |
| 307 | struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile> |
| 308 | : public binary_function<const volatile _Cp*, _A1, _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | { |
| 310 | }; |
| 311 | |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 312 | |
| 313 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 314 | // 3 or more arguments |
| 315 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 316 | template <class _Rp, class _A1, class _A2, class _A3, class ..._A4> |
| 317 | struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 318 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 319 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 320 | }; |
| 321 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 322 | template <class _Rp, class _A1, class _A2, class _A3, class ..._A4> |
| 323 | struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 324 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 325 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 326 | }; |
| 327 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 328 | template <class _Rp, class _A1, class _A2, class _A3, class ..._A4> |
| 329 | struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 330 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 331 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 334 | template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> |
| 335 | struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 336 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 337 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 338 | }; |
| 339 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 340 | template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> |
| 341 | struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 342 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 343 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 344 | }; |
| 345 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 346 | template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> |
| 347 | struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 348 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 349 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | }; |
| 351 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 352 | template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> |
| 353 | struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> |
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 | typedef _Rp result_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 356 | }; |
| 357 | |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 358 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 359 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 360 | // __invoke |
| 361 | |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 362 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 363 | |
Howard Hinnant | bd89e4b | 2011-05-20 22:02:53 +0000 | [diff] [blame] | 364 | // bullets 1 and 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | |
Howard Hinnant | ecc9742 | 2013-05-07 23:40:12 +0000 | [diff] [blame] | 366 | template <class _Fp, class _A0, class ..._Args, |
| 367 | class> |
Eric Fiselier | c254b36 | 2015-04-19 15:32:52 +0000 | [diff] [blame] | 368 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bd89e4b | 2011-05-20 22:02:53 +0000 | [diff] [blame] | 369 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 370 | __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 371 | -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 372 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 373 | return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Howard Hinnant | ecc9742 | 2013-05-07 23:40:12 +0000 | [diff] [blame] | 376 | template <class _Fp, class _A0, class ..._Args, |
| 377 | class> |
Eric Fiselier | c254b36 | 2015-04-19 15:32:52 +0000 | [diff] [blame] | 378 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bd89e4b | 2011-05-20 22:02:53 +0000 | [diff] [blame] | 379 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 380 | __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 381 | -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 382 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 383 | return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Howard Hinnant | bd89e4b | 2011-05-20 22:02:53 +0000 | [diff] [blame] | 386 | // bullets 3 and 4 |
| 387 | |
Howard Hinnant | ecc9742 | 2013-05-07 23:40:12 +0000 | [diff] [blame] | 388 | template <class _Fp, class _A0, |
| 389 | class> |
Eric Fiselier | c254b36 | 2015-04-19 15:32:52 +0000 | [diff] [blame] | 390 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bd89e4b | 2011-05-20 22:02:53 +0000 | [diff] [blame] | 391 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 392 | __invoke(_Fp&& __f, _A0&& __a0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 393 | -> decltype(_VSTD::forward<_A0>(__a0).*__f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 395 | return _VSTD::forward<_A0>(__a0).*__f; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Howard Hinnant | ecc9742 | 2013-05-07 23:40:12 +0000 | [diff] [blame] | 398 | template <class _Fp, class _A0, |
| 399 | class> |
Eric Fiselier | c254b36 | 2015-04-19 15:32:52 +0000 | [diff] [blame] | 400 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bd89e4b | 2011-05-20 22:02:53 +0000 | [diff] [blame] | 401 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 402 | __invoke(_Fp&& __f, _A0&& __a0) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 403 | -> decltype((*_VSTD::forward<_A0>(__a0)).*__f) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 405 | return (*_VSTD::forward<_A0>(__a0)).*__f; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Howard Hinnant | bd89e4b | 2011-05-20 22:02:53 +0000 | [diff] [blame] | 408 | // bullet 5 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 410 | template <class _Fp, class ..._Args> |
Eric Fiselier | c254b36 | 2015-04-19 15:32:52 +0000 | [diff] [blame] | 411 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bd89e4b | 2011-05-20 22:02:53 +0000 | [diff] [blame] | 412 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 413 | __invoke(_Fp&& __f, _Args&& ...__args) |
| 414 | -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 416 | return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 417 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | template <class _Tp, class ..._Args> |
| 419 | struct __invoke_return |
| 420 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 421 | typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 422 | }; |
| 423 | |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 424 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 425 | |
| 426 | #include <__functional_base_03> |
| 427 | |
| 428 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 429 | |
| 430 | |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 431 | template <class _Ret> |
| 432 | struct __invoke_void_return_wrapper |
| 433 | { |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 434 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 435 | template <class ..._Args> |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 436 | static _Ret __call(_Args&&... __args) { |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 437 | return __invoke(_VSTD::forward<_Args>(__args)...); |
| 438 | } |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 439 | #else |
| 440 | template <class _Fn> |
| 441 | static _Ret __call(_Fn __f) { |
| 442 | return __invoke(__f); |
| 443 | } |
| 444 | |
| 445 | template <class _Fn, class _A0> |
| 446 | static _Ret __call(_Fn __f, _A0& __a0) { |
| 447 | return __invoke(__f, __a0); |
| 448 | } |
| 449 | |
| 450 | template <class _Fn, class _A0, class _A1> |
| 451 | static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) { |
| 452 | return __invoke(__f, __a0, __a1); |
| 453 | } |
| 454 | |
| 455 | template <class _Fn, class _A0, class _A1, class _A2> |
| 456 | static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){ |
| 457 | return __invoke(__f, __a0, __a1, __a2); |
| 458 | } |
| 459 | #endif |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 460 | }; |
| 461 | |
| 462 | template <> |
| 463 | struct __invoke_void_return_wrapper<void> |
| 464 | { |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 465 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 466 | template <class ..._Args> |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 467 | static void __call(_Args&&... __args) { |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 468 | __invoke(_VSTD::forward<_Args>(__args)...); |
| 469 | } |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 470 | #else |
| 471 | template <class _Fn> |
| 472 | static void __call(_Fn __f) { |
| 473 | __invoke(__f); |
| 474 | } |
| 475 | |
| 476 | template <class _Fn, class _A0> |
| 477 | static void __call(_Fn __f, _A0& __a0) { |
| 478 | __invoke(__f, __a0); |
| 479 | } |
| 480 | |
| 481 | template <class _Fn, class _A0, class _A1> |
| 482 | static void __call(_Fn __f, _A0& __a0, _A1& __a1) { |
| 483 | __invoke(__f, __a0, __a1); |
| 484 | } |
| 485 | |
| 486 | template <class _Fn, class _A0, class _A1, class _A2> |
| 487 | static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) { |
| 488 | __invoke(__f, __a0, __a1, __a2); |
| 489 | } |
| 490 | #endif |
Eric Fiselier | c3231d2 | 2015-02-10 16:48:45 +0000 | [diff] [blame] | 491 | }; |
| 492 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 493 | template <class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 494 | class _LIBCPP_TYPE_VIS_ONLY reference_wrapper |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 495 | : public __weak_result_type<_Tp> |
| 496 | { |
| 497 | public: |
| 498 | // types |
| 499 | typedef _Tp type; |
| 500 | private: |
| 501 | type* __f_; |
| 502 | |
| 503 | public: |
| 504 | // construct/copy/destroy |
Howard Hinnant | a4e87ab | 2013-08-08 18:38:55 +0000 | [diff] [blame] | 505 | _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT |
| 506 | : __f_(_VSTD::addressof(__f)) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 507 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 508 | private: reference_wrapper(type&&); public: // = delete; // do not bind to temps |
| 509 | #endif |
| 510 | |
| 511 | // access |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 512 | _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;} |
| 513 | _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 514 | |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 515 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | // invoke |
| 517 | template <class... _ArgTypes> |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 518 | _LIBCPP_INLINE_VISIBILITY |
| 519 | typename __invoke_of<type&, _ArgTypes...>::type |
| 520 | operator() (_ArgTypes&&... __args) const { |
| 521 | return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...); |
| 522 | } |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 523 | #else |
| 524 | |
| 525 | _LIBCPP_INLINE_VISIBILITY |
| 526 | typename __invoke_return<type>::type |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 527 | operator() () const { |
| 528 | return __invoke(get()); |
| 529 | } |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 530 | |
| 531 | template <class _A0> |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 532 | _LIBCPP_INLINE_VISIBILITY |
| 533 | typename __invoke_return0<type, _A0>::type |
| 534 | operator() (_A0& __a0) const { |
| 535 | return __invoke(get(), __a0); |
| 536 | } |
| 537 | |
| 538 | template <class _A0> |
| 539 | _LIBCPP_INLINE_VISIBILITY |
| 540 | typename __invoke_return0<type, _A0 const>::type |
| 541 | operator() (_A0 const& __a0) const { |
| 542 | return __invoke(get(), __a0); |
| 543 | } |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 544 | |
| 545 | template <class _A0, class _A1> |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 546 | _LIBCPP_INLINE_VISIBILITY |
| 547 | typename __invoke_return1<type, _A0, _A1>::type |
| 548 | operator() (_A0& __a0, _A1& __a1) const { |
| 549 | return __invoke(get(), __a0, __a1); |
| 550 | } |
| 551 | |
| 552 | template <class _A0, class _A1> |
| 553 | _LIBCPP_INLINE_VISIBILITY |
| 554 | typename __invoke_return1<type, _A0 const, _A1>::type |
| 555 | operator() (_A0 const& __a0, _A1& __a1) const { |
| 556 | return __invoke(get(), __a0, __a1); |
| 557 | } |
| 558 | |
| 559 | template <class _A0, class _A1> |
| 560 | _LIBCPP_INLINE_VISIBILITY |
| 561 | typename __invoke_return1<type, _A0, _A1 const>::type |
| 562 | operator() (_A0& __a0, _A1 const& __a1) const { |
| 563 | return __invoke(get(), __a0, __a1); |
| 564 | } |
| 565 | |
| 566 | template <class _A0, class _A1> |
| 567 | _LIBCPP_INLINE_VISIBILITY |
| 568 | typename __invoke_return1<type, _A0 const, _A1 const>::type |
| 569 | operator() (_A0 const& __a0, _A1 const& __a1) const { |
| 570 | return __invoke(get(), __a0, __a1); |
| 571 | } |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 572 | |
| 573 | template <class _A0, class _A1, class _A2> |
Eric Fiselier | f1626ad | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 574 | _LIBCPP_INLINE_VISIBILITY |
| 575 | typename __invoke_return2<type, _A0, _A1, _A2>::type |
| 576 | operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { |
| 577 | return __invoke(get(), __a0, __a1, __a2); |
| 578 | } |
| 579 | |
| 580 | template <class _A0, class _A1, class _A2> |
| 581 | _LIBCPP_INLINE_VISIBILITY |
| 582 | typename __invoke_return2<type, _A0 const, _A1, _A2>::type |
| 583 | operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { |
| 584 | return __invoke(get(), __a0, __a1, __a2); |
| 585 | } |
| 586 | |
| 587 | template <class _A0, class _A1, class _A2> |
| 588 | _LIBCPP_INLINE_VISIBILITY |
| 589 | typename __invoke_return2<type, _A0, _A1 const, _A2>::type |
| 590 | operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { |
| 591 | return __invoke(get(), __a0, __a1, __a2); |
| 592 | } |
| 593 | |
| 594 | template <class _A0, class _A1, class _A2> |
| 595 | _LIBCPP_INLINE_VISIBILITY |
| 596 | typename __invoke_return2<type, _A0, _A1, _A2 const>::type |
| 597 | operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { |
| 598 | return __invoke(get(), __a0, __a1, __a2); |
| 599 | } |
| 600 | |
| 601 | template <class _A0, class _A1, class _A2> |
| 602 | _LIBCPP_INLINE_VISIBILITY |
| 603 | typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type |
| 604 | operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { |
| 605 | return __invoke(get(), __a0, __a1, __a2); |
| 606 | } |
| 607 | |
| 608 | template <class _A0, class _A1, class _A2> |
| 609 | _LIBCPP_INLINE_VISIBILITY |
| 610 | typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type |
| 611 | operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { |
| 612 | return __invoke(get(), __a0, __a1, __a2); |
| 613 | } |
| 614 | |
| 615 | template <class _A0, class _A1, class _A2> |
| 616 | _LIBCPP_INLINE_VISIBILITY |
| 617 | typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type |
| 618 | operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { |
| 619 | return __invoke(get(), __a0, __a1, __a2); |
| 620 | } |
| 621 | |
| 622 | template <class _A0, class _A1, class _A2> |
| 623 | _LIBCPP_INLINE_VISIBILITY |
| 624 | typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type |
| 625 | operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { |
| 626 | return __invoke(get(), __a0, __a1, __a2); |
| 627 | } |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 628 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | }; |
| 630 | |
Marshall Clow | 0ea7f8c | 2014-01-06 14:00:09 +0000 | [diff] [blame] | 631 | template <class _Tp> struct __is_reference_wrapper_impl : public false_type {}; |
| 632 | template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 633 | template <class _Tp> struct __is_reference_wrapper |
Marshall Clow | 0ea7f8c | 2014-01-06 14:00:09 +0000 | [diff] [blame] | 634 | : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 635 | |
| 636 | template <class _Tp> |
| 637 | inline _LIBCPP_INLINE_VISIBILITY |
| 638 | reference_wrapper<_Tp> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 639 | ref(_Tp& __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 640 | { |
| 641 | return reference_wrapper<_Tp>(__t); |
| 642 | } |
| 643 | |
| 644 | template <class _Tp> |
| 645 | inline _LIBCPP_INLINE_VISIBILITY |
| 646 | reference_wrapper<_Tp> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 647 | ref(reference_wrapper<_Tp> __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | { |
| 649 | return ref(__t.get()); |
| 650 | } |
| 651 | |
| 652 | template <class _Tp> |
| 653 | inline _LIBCPP_INLINE_VISIBILITY |
| 654 | reference_wrapper<const _Tp> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 655 | cref(const _Tp& __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 656 | { |
| 657 | return reference_wrapper<const _Tp>(__t); |
| 658 | } |
| 659 | |
| 660 | template <class _Tp> |
| 661 | inline _LIBCPP_INLINE_VISIBILITY |
| 662 | reference_wrapper<const _Tp> |
Howard Hinnant | 603d2c0 | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 663 | cref(reference_wrapper<_Tp> __t) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 664 | { |
| 665 | return cref(__t.get()); |
| 666 | } |
| 667 | |
Eric Fiselier | 5b3a459 | 2015-07-22 22:23:49 +0000 | [diff] [blame] | 668 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 669 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 670 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 671 | |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 672 | template <class _Tp> void ref(const _Tp&&) = delete; |
| 673 | template <class _Tp> void cref(const _Tp&&) = delete; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 674 | |
| 675 | #else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 676 | |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 677 | template <class _Tp> void ref(const _Tp&&);// = delete; |
| 678 | template <class _Tp> void cref(const _Tp&&);// = delete; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 679 | |
| 680 | #endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 681 | |
| 682 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 683 | |
| 684 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 685 | |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 686 | #if _LIBCPP_STD_VER > 11 |
| 687 | template <class _Tp1, class _Tp2 = void> |
| 688 | struct __is_transparent |
| 689 | { |
| 690 | private: |
| 691 | struct __two {char __lx; char __lxx;}; |
| 692 | template <class _Up> static __two __test(...); |
| 693 | template <class _Up> static char __test(typename _Up::is_transparent* = 0); |
| 694 | public: |
| 695 | static const bool value = sizeof(__test<_Tp1>(0)) == 1; |
| 696 | }; |
| 697 | #endif |
| 698 | |
Marshall Clow | 599e60d | 2013-09-12 02:11:16 +0000 | [diff] [blame] | 699 | // allocator_arg_t |
| 700 | |
| 701 | struct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { }; |
| 702 | |
| 703 | #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY) |
| 704 | extern const allocator_arg_t allocator_arg; |
| 705 | #else |
| 706 | constexpr allocator_arg_t allocator_arg = allocator_arg_t(); |
| 707 | #endif |
| 708 | |
| 709 | // uses_allocator |
| 710 | |
| 711 | template <class _Tp> |
| 712 | struct __has_allocator_type |
| 713 | { |
| 714 | private: |
| 715 | struct __two {char __lx; char __lxx;}; |
| 716 | template <class _Up> static __two __test(...); |
| 717 | template <class _Up> static char __test(typename _Up::allocator_type* = 0); |
| 718 | public: |
| 719 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 720 | }; |
| 721 | |
| 722 | template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value> |
| 723 | struct __uses_allocator |
| 724 | : public integral_constant<bool, |
| 725 | is_convertible<_Alloc, typename _Tp::allocator_type>::value> |
| 726 | { |
| 727 | }; |
| 728 | |
| 729 | template <class _Tp, class _Alloc> |
| 730 | struct __uses_allocator<_Tp, _Alloc, false> |
| 731 | : public false_type |
| 732 | { |
| 733 | }; |
| 734 | |
| 735 | template <class _Tp, class _Alloc> |
| 736 | struct _LIBCPP_TYPE_VIS_ONLY uses_allocator |
| 737 | : public __uses_allocator<_Tp, _Alloc> |
| 738 | { |
| 739 | }; |
| 740 | |
| 741 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 742 | |
| 743 | // allocator construction |
| 744 | |
| 745 | template <class _Tp, class _Alloc, class ..._Args> |
| 746 | struct __uses_alloc_ctor_imp |
| 747 | { |
| 748 | static const bool __ua = uses_allocator<_Tp, _Alloc>::value; |
| 749 | static const bool __ic = |
| 750 | is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; |
| 751 | static const int value = __ua ? 2 - __ic : 0; |
| 752 | }; |
| 753 | |
| 754 | template <class _Tp, class _Alloc, class ..._Args> |
| 755 | struct __uses_alloc_ctor |
| 756 | : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> |
| 757 | {}; |
| 758 | |
| 759 | template <class _Tp, class _Allocator, class... _Args> |
| 760 | inline _LIBCPP_INLINE_VISIBILITY |
| 761 | void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args ) |
| 762 | { |
| 763 | new (__storage) _Tp (_VSTD::forward<_Args>(__args)...); |
| 764 | } |
| 765 | |
| 766 | template <class _Tp, class _Allocator, class... _Args> |
| 767 | inline _LIBCPP_INLINE_VISIBILITY |
| 768 | void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) |
| 769 | { |
| 770 | new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...); |
| 771 | } |
| 772 | |
| 773 | template <class _Tp, class _Allocator, class... _Args> |
| 774 | inline _LIBCPP_INLINE_VISIBILITY |
| 775 | void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) |
| 776 | { |
| 777 | new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a); |
| 778 | } |
| 779 | |
| 780 | template <class _Tp, class _Allocator, class... _Args> |
| 781 | inline _LIBCPP_INLINE_VISIBILITY |
| 782 | void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args) |
| 783 | { |
| 784 | __user_alloc_construct_impl( |
| 785 | __uses_alloc_ctor<_Tp, _Allocator>(), |
| 786 | __storage, __a, _VSTD::forward<_Args>(__args)... |
| 787 | ); |
| 788 | } |
| 789 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Marshall Clow | 4a0a981 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 790 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | _LIBCPP_END_NAMESPACE_STD |
| 792 | |
| 793 | #endif // _LIBCPP_FUNCTIONAL_BASE |