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> |
| 18 | |
| 19 | #pragma GCC system_header |
| 20 | |
| 21 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 22 | |
| 23 | template <class _Arg, class _Result> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 24 | struct _LIBCPP_VISIBLE unary_function |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | { |
| 26 | typedef _Arg argument_type; |
| 27 | typedef _Result result_type; |
| 28 | }; |
| 29 | |
| 30 | template <class _Arg1, class _Arg2, class _Result> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 31 | struct _LIBCPP_VISIBLE binary_function |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | { |
| 33 | typedef _Arg1 first_argument_type; |
| 34 | typedef _Arg2 second_argument_type; |
| 35 | typedef _Result result_type; |
| 36 | }; |
| 37 | |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 38 | template <class _Tp> struct _LIBCPP_VISIBLE hash; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | |
| 40 | template <class _Tp> |
| 41 | struct __has_result_type |
| 42 | { |
| 43 | private: |
| 44 | struct __two {char _; char __;}; |
| 45 | template <class _Up> static __two __test(...); |
| 46 | template <class _Up> static char __test(typename _Up::result_type* = 0); |
| 47 | public: |
| 48 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 49 | }; |
| 50 | |
| 51 | #ifdef _LIBCPP_HAS_NO_VARIADICS |
| 52 | |
| 53 | #include <__functional_base_03> |
| 54 | |
| 55 | #else // _LIBCPP_HAS_NO_VARIADICS |
| 56 | |
| 57 | // __weak_result_type |
| 58 | |
| 59 | template <class _Tp> |
| 60 | struct __derives_from_unary_function |
| 61 | { |
| 62 | private: |
| 63 | struct __two {char _; char __;}; |
| 64 | static __two __test(...); |
| 65 | template <class _A, class _R> |
| 66 | static unary_function<_A, _R> |
| 67 | __test(const volatile unary_function<_A, _R>*); |
| 68 | public: |
| 69 | static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; |
| 70 | typedef decltype(__test((_Tp*)0)) type; |
| 71 | }; |
| 72 | |
| 73 | template <class _Tp> |
| 74 | struct __derives_from_binary_function |
| 75 | { |
| 76 | private: |
| 77 | struct __two {char _; char __;}; |
| 78 | static __two __test(...); |
| 79 | template <class _A1, class _A2, class _R> |
| 80 | static binary_function<_A1, _A2, _R> |
| 81 | __test(const volatile binary_function<_A1, _A2, _R>*); |
| 82 | public: |
| 83 | static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; |
| 84 | typedef decltype(__test((_Tp*)0)) type; |
| 85 | }; |
| 86 | |
| 87 | template <class _Tp, bool = __derives_from_unary_function<_Tp>::value> |
| 88 | struct __maybe_derive_from_unary_function // bool is true |
| 89 | : public __derives_from_unary_function<_Tp>::type |
| 90 | { |
| 91 | }; |
| 92 | |
| 93 | template <class _Tp> |
| 94 | struct __maybe_derive_from_unary_function<_Tp, false> |
| 95 | { |
| 96 | }; |
| 97 | |
| 98 | template <class _Tp, bool = __derives_from_binary_function<_Tp>::value> |
| 99 | struct __maybe_derive_from_binary_function // bool is true |
| 100 | : public __derives_from_binary_function<_Tp>::type |
| 101 | { |
| 102 | }; |
| 103 | |
| 104 | template <class _Tp> |
| 105 | struct __maybe_derive_from_binary_function<_Tp, false> |
| 106 | { |
| 107 | }; |
| 108 | |
| 109 | template <class _Tp, bool = __has_result_type<_Tp>::value> |
| 110 | struct __weak_result_type_imp // bool is true |
| 111 | : public __maybe_derive_from_unary_function<_Tp>, |
| 112 | public __maybe_derive_from_binary_function<_Tp> |
| 113 | { |
| 114 | typedef typename _Tp::result_type result_type; |
| 115 | }; |
| 116 | |
| 117 | template <class _Tp> |
| 118 | struct __weak_result_type_imp<_Tp, false> |
| 119 | : public __maybe_derive_from_unary_function<_Tp>, |
| 120 | public __maybe_derive_from_binary_function<_Tp> |
| 121 | { |
| 122 | }; |
| 123 | |
| 124 | template <class _Tp> |
| 125 | struct __weak_result_type |
| 126 | : public __weak_result_type_imp<_Tp> |
| 127 | { |
| 128 | }; |
| 129 | |
| 130 | // 0 argument case |
| 131 | |
| 132 | template <class _R> |
| 133 | struct __weak_result_type<_R ()> |
| 134 | { |
| 135 | typedef _R result_type; |
| 136 | }; |
| 137 | |
| 138 | template <class _R> |
| 139 | struct __weak_result_type<_R (&)()> |
| 140 | { |
| 141 | typedef _R result_type; |
| 142 | }; |
| 143 | |
| 144 | template <class _R> |
| 145 | struct __weak_result_type<_R (*)()> |
| 146 | { |
| 147 | typedef _R result_type; |
| 148 | }; |
| 149 | |
| 150 | // 1 argument case |
| 151 | |
| 152 | template <class _R, class _A1> |
| 153 | struct __weak_result_type<_R (_A1)> |
| 154 | : public unary_function<_A1, _R> |
| 155 | { |
| 156 | }; |
| 157 | |
| 158 | template <class _R, class _A1> |
| 159 | struct __weak_result_type<_R (&)(_A1)> |
| 160 | : public unary_function<_A1, _R> |
| 161 | { |
| 162 | }; |
| 163 | |
| 164 | template <class _R, class _A1> |
| 165 | struct __weak_result_type<_R (*)(_A1)> |
| 166 | : public unary_function<_A1, _R> |
| 167 | { |
| 168 | }; |
| 169 | |
| 170 | template <class _R, class _C> |
| 171 | struct __weak_result_type<_R (_C::*)()> |
| 172 | : public unary_function<_C*, _R> |
| 173 | { |
| 174 | }; |
| 175 | |
| 176 | template <class _R, class _C> |
| 177 | struct __weak_result_type<_R (_C::*)() const> |
| 178 | : public unary_function<const _C*, _R> |
| 179 | { |
| 180 | }; |
| 181 | |
| 182 | template <class _R, class _C> |
| 183 | struct __weak_result_type<_R (_C::*)() volatile> |
| 184 | : public unary_function<volatile _C*, _R> |
| 185 | { |
| 186 | }; |
| 187 | |
| 188 | template <class _R, class _C> |
| 189 | struct __weak_result_type<_R (_C::*)() const volatile> |
| 190 | : public unary_function<const volatile _C*, _R> |
| 191 | { |
| 192 | }; |
| 193 | |
| 194 | // 2 argument case |
| 195 | |
| 196 | template <class _R, class _A1, class _A2> |
| 197 | struct __weak_result_type<_R (_A1, _A2)> |
| 198 | : public binary_function<_A1, _A2, _R> |
| 199 | { |
| 200 | }; |
| 201 | |
| 202 | template <class _R, class _A1, class _A2> |
| 203 | struct __weak_result_type<_R (*)(_A1, _A2)> |
| 204 | : public binary_function<_A1, _A2, _R> |
| 205 | { |
| 206 | }; |
| 207 | |
| 208 | template <class _R, class _A1, class _A2> |
| 209 | struct __weak_result_type<_R (&)(_A1, _A2)> |
| 210 | : public binary_function<_A1, _A2, _R> |
| 211 | { |
| 212 | }; |
| 213 | |
| 214 | template <class _R, class _C, class _A1> |
| 215 | struct __weak_result_type<_R (_C::*)(_A1)> |
| 216 | : public binary_function<_C*, _A1, _R> |
| 217 | { |
| 218 | }; |
| 219 | |
| 220 | template <class _R, class _C, class _A1> |
| 221 | struct __weak_result_type<_R (_C::*)(_A1) const> |
| 222 | : public binary_function<const _C*, _A1, _R> |
| 223 | { |
| 224 | }; |
| 225 | |
| 226 | template <class _R, class _C, class _A1> |
| 227 | struct __weak_result_type<_R (_C::*)(_A1) volatile> |
| 228 | : public binary_function<volatile _C*, _A1, _R> |
| 229 | { |
| 230 | }; |
| 231 | |
| 232 | template <class _R, class _C, class _A1> |
| 233 | struct __weak_result_type<_R (_C::*)(_A1) const volatile> |
| 234 | : public binary_function<const volatile _C*, _A1, _R> |
| 235 | { |
| 236 | }; |
| 237 | |
| 238 | // 3 or more arguments |
| 239 | |
| 240 | template <class _R, class _A1, class _A2, class _A3, class ..._A4> |
| 241 | struct __weak_result_type<_R (_A1, _A2, _A3, _A4...)> |
| 242 | { |
| 243 | typedef _R result_type; |
| 244 | }; |
| 245 | |
| 246 | template <class _R, class _A1, class _A2, class _A3, class ..._A4> |
| 247 | struct __weak_result_type<_R (&)(_A1, _A2, _A3, _A4...)> |
| 248 | { |
| 249 | typedef _R result_type; |
| 250 | }; |
| 251 | |
| 252 | template <class _R, class _A1, class _A2, class _A3, class ..._A4> |
| 253 | struct __weak_result_type<_R (*)(_A1, _A2, _A3, _A4...)> |
| 254 | { |
| 255 | typedef _R result_type; |
| 256 | }; |
| 257 | |
| 258 | template <class _R, class _C, class _A1, class _A2, class ..._A3> |
| 259 | struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...)> |
| 260 | { |
| 261 | typedef _R result_type; |
| 262 | }; |
| 263 | |
| 264 | template <class _R, class _C, class _A1, class _A2, class ..._A3> |
| 265 | struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) const> |
| 266 | { |
| 267 | typedef _R result_type; |
| 268 | }; |
| 269 | |
| 270 | template <class _R, class _C, class _A1, class _A2, class ..._A3> |
| 271 | struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) volatile> |
| 272 | { |
| 273 | typedef _R result_type; |
| 274 | }; |
| 275 | |
| 276 | template <class _R, class _C, class _A1, class _A2, class ..._A3> |
| 277 | struct __weak_result_type<_R (_C::*)(_A1, _A2, _A3...) const volatile> |
| 278 | { |
| 279 | typedef _R result_type; |
| 280 | }; |
| 281 | |
| 282 | // __invoke |
| 283 | |
| 284 | // first bullet |
| 285 | |
| 286 | template <class _R, class _T, class _T1, class ..._Param, class ..._Arg> |
| 287 | inline _LIBCPP_INLINE_VISIBILITY |
| 288 | typename enable_if |
| 289 | < |
| 290 | sizeof...(_Param) == sizeof...(_Arg) && |
| 291 | is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 292 | _R |
| 293 | >::type |
| 294 | __invoke(_R (_T::*__f)(_Param...), _T1&& __t1, _Arg&& ...__arg) |
| 295 | { |
| 296 | return (_STD::forward<_T>(__t1).*__f)(_STD::forward<_Arg>(__arg)...); |
| 297 | } |
| 298 | |
| 299 | template <class _R, class _T, class _T1, class ..._Param, class ..._Arg> |
| 300 | inline _LIBCPP_INLINE_VISIBILITY |
| 301 | typename enable_if |
| 302 | < |
| 303 | sizeof...(_Param) == sizeof...(_Arg) && |
| 304 | is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 305 | _R |
| 306 | >::type |
| 307 | __invoke(_R (_T::*__f)(_Param...) const, _T1&& __t1, _Arg&& ...__arg) |
| 308 | { |
Howard Hinnant | fdc5a0f | 2010-09-11 15:09:37 +0000 | [diff] [blame] | 309 | return (_STD::forward<const _T>(__t1).*__f)(_STD::forward<_Arg>(__arg)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | template <class _R, class _T, class _T1, class ..._Param, class ..._Arg> |
| 313 | inline _LIBCPP_INLINE_VISIBILITY |
| 314 | typename enable_if |
| 315 | < |
| 316 | sizeof...(_Param) == sizeof...(_Arg) && |
| 317 | is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 318 | _R |
| 319 | >::type |
| 320 | __invoke(_R (_T::*__f)(_Param...) volatile, _T1&& __t1, _Arg&& ...__arg) |
| 321 | { |
Howard Hinnant | fdc5a0f | 2010-09-11 15:09:37 +0000 | [diff] [blame] | 322 | return (_STD::forward<volatile _T>(__t1).*__f)(_STD::forward<_Arg>(__arg)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | template <class _R, class _T, class _T1, class ..._Param, class ..._Arg> |
| 326 | inline _LIBCPP_INLINE_VISIBILITY |
| 327 | typename enable_if |
| 328 | < |
| 329 | sizeof...(_Param) == sizeof...(_Arg) && |
| 330 | is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 331 | _R |
| 332 | >::type |
| 333 | __invoke(_R (_T::*__f)(_Param...) const volatile, _T1&& __t1, _Arg&& ...__arg) |
| 334 | { |
Howard Hinnant | fdc5a0f | 2010-09-11 15:09:37 +0000 | [diff] [blame] | 335 | return (_STD::forward<const volatile _T>(__t1).*__f)(_STD::forward<_Arg>(__arg)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | // second bullet |
| 339 | |
| 340 | template <class _R, class _T, class _T1, class ..._Param, class ..._Arg> |
| 341 | inline _LIBCPP_INLINE_VISIBILITY |
| 342 | typename enable_if |
| 343 | < |
| 344 | sizeof...(_Param) == sizeof...(_Arg) && |
| 345 | !is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 346 | _R |
| 347 | >::type |
| 348 | __invoke(_R (_T::*__f)(_Param...), _T1&& __t1, _Arg&& ...__arg) |
| 349 | { |
| 350 | return ((*_STD::forward<_T1>(__t1)).*__f)(_STD::forward<_Arg>(__arg)...); |
| 351 | } |
| 352 | |
| 353 | template <class _R, class _T, class _T1, class ..._Param, class ..._Arg> |
| 354 | inline _LIBCPP_INLINE_VISIBILITY |
| 355 | typename enable_if |
| 356 | < |
| 357 | sizeof...(_Param) == sizeof...(_Arg) && |
| 358 | !is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 359 | _R |
| 360 | >::type |
| 361 | __invoke(_R (_T::*__f)(_Param...) const, _T1&& __t1, _Arg&& ...__arg) |
| 362 | { |
| 363 | return ((*_STD::forward<_T1>(__t1)).*__f)(_STD::forward<_Arg>(__arg)...); |
| 364 | } |
| 365 | |
| 366 | template <class _R, class _T, class _T1, class ..._Param, class ..._Arg> |
| 367 | inline _LIBCPP_INLINE_VISIBILITY |
| 368 | typename enable_if |
| 369 | < |
| 370 | sizeof...(_Param) == sizeof...(_Arg) && |
| 371 | !is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 372 | _R |
| 373 | >::type |
| 374 | __invoke(_R (_T::*__f)(_Param...) volatile, _T1&& __t1, _Arg&& ...__arg) |
| 375 | { |
| 376 | return ((*_STD::forward<_T1>(__t1)).*__f)(_STD::forward<_Arg>(__arg)...); |
| 377 | } |
| 378 | |
| 379 | template <class _R, class _T, class _T1, class ..._Param, class ..._Arg> |
| 380 | inline _LIBCPP_INLINE_VISIBILITY |
| 381 | typename enable_if |
| 382 | < |
| 383 | sizeof...(_Param) == sizeof...(_Arg) && |
| 384 | !is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 385 | _R |
| 386 | >::type |
| 387 | __invoke(_R (_T::*__f)(_Param...) const volatile, _T1&& __t1, _Arg&& ...__arg) |
| 388 | { |
| 389 | return ((*_STD::forward<_T1>(__t1)).*__f)(_STD::forward<_Arg>(__arg)...); |
| 390 | } |
| 391 | |
| 392 | // third bullet |
| 393 | |
| 394 | template <class _R, class _T, class _T1> |
| 395 | inline _LIBCPP_INLINE_VISIBILITY |
| 396 | typename enable_if |
| 397 | < |
| 398 | is_base_of<_T, typename remove_reference<_T1>::type>::value, |
| 399 | typename __apply_cv<_T1, _R>::type&& |
| 400 | >::type |
| 401 | __invoke(_R _T::* __f, _T1&& __t1) |
| 402 | { |
| 403 | return _STD::forward<_T1>(__t1).*__f; |
| 404 | } |
| 405 | |
| 406 | // forth bullet |
| 407 | |
| 408 | template <class _T1, class _R, bool> |
| 409 | struct __4th_helper |
| 410 | { |
| 411 | }; |
| 412 | |
| 413 | template <class _T1, class _R> |
| 414 | struct __4th_helper<_T1, _R, true> |
| 415 | { |
| 416 | typedef typename __apply_cv<decltype(*_STD::declval<_T1>()), _R>::type type; |
| 417 | }; |
| 418 | |
| 419 | template <class _R, class _T, class _T1> |
| 420 | inline _LIBCPP_INLINE_VISIBILITY |
| 421 | typename __4th_helper<_T1, _R, |
| 422 | !is_base_of<_T, |
| 423 | typename remove_reference<_T1>::type |
| 424 | >::value |
| 425 | >::type&& |
| 426 | __invoke(_R _T::* __f, _T1&& __t1) |
| 427 | { |
| 428 | return (*_STD::forward<_T1>(__t1)).*__f; |
| 429 | } |
| 430 | |
| 431 | // fifth bullet |
| 432 | |
Howard Hinnant | 941138f | 2011-05-16 16:20:21 +0000 | [diff] [blame] | 433 | template <class _R, class ..._Param, class ..._Args> |
| 434 | inline _LIBCPP_INLINE_VISIBILITY |
| 435 | _R |
| 436 | __invoke(_R (*__f)(_Param...), _Args&& ...__args) |
| 437 | { |
| 438 | return __f(_STD::forward<_Args>(__args)...); |
| 439 | } |
| 440 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 441 | template <class _F, class ..._T> |
| 442 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame^] | 443 | typename __invoke_of<_F, _T...>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 444 | __invoke(_F&& __f, _T&& ...__t) |
| 445 | { |
| 446 | return _STD::forward<_F>(__f)(_STD::forward<_T>(__t)...); |
| 447 | } |
| 448 | |
| 449 | template <class _Tp, class ..._Args> |
| 450 | struct __invoke_return |
| 451 | { |
| 452 | typedef decltype(__invoke(_STD::declval<_Tp>(), _STD::declval<_Args>()...)) type; |
| 453 | }; |
| 454 | |
| 455 | template <class _Tp> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 456 | class _LIBCPP_VISIBLE reference_wrapper |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 457 | : public __weak_result_type<_Tp> |
| 458 | { |
| 459 | public: |
| 460 | // types |
| 461 | typedef _Tp type; |
| 462 | private: |
| 463 | type* __f_; |
| 464 | |
| 465 | public: |
| 466 | // construct/copy/destroy |
| 467 | _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) : __f_(&__f) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 468 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | private: reference_wrapper(type&&); public: // = delete; // do not bind to temps |
| 470 | #endif |
| 471 | |
| 472 | // access |
| 473 | _LIBCPP_INLINE_VISIBILITY operator type& () const {return *__f_;} |
| 474 | _LIBCPP_INLINE_VISIBILITY type& get() const {return *__f_;} |
| 475 | |
| 476 | // invoke |
| 477 | template <class... _ArgTypes> |
Howard Hinnant | 99acc50 | 2010-09-21 17:32:39 +0000 | [diff] [blame] | 478 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 57cff29 | 2011-05-19 15:05:04 +0000 | [diff] [blame^] | 479 | typename __invoke_of<type&, _ArgTypes...>::type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 480 | operator() (_ArgTypes&&... __args) const |
| 481 | { |
| 482 | return __invoke(get(), _STD::forward<_ArgTypes>(__args)...); |
| 483 | } |
| 484 | }; |
| 485 | |
| 486 | template <class _Tp> struct ____is_reference_wrapper : public false_type {}; |
| 487 | template <class _Tp> struct ____is_reference_wrapper<reference_wrapper<_Tp> > : public true_type {}; |
| 488 | template <class _Tp> struct __is_reference_wrapper |
| 489 | : public ____is_reference_wrapper<typename remove_cv<_Tp>::type> {}; |
| 490 | |
| 491 | template <class _Tp> |
| 492 | inline _LIBCPP_INLINE_VISIBILITY |
| 493 | reference_wrapper<_Tp> |
| 494 | ref(_Tp& __t) |
| 495 | { |
| 496 | return reference_wrapper<_Tp>(__t); |
| 497 | } |
| 498 | |
| 499 | template <class _Tp> |
| 500 | inline _LIBCPP_INLINE_VISIBILITY |
| 501 | reference_wrapper<_Tp> |
| 502 | ref(reference_wrapper<_Tp> __t) |
| 503 | { |
| 504 | return ref(__t.get()); |
| 505 | } |
| 506 | |
| 507 | template <class _Tp> |
| 508 | inline _LIBCPP_INLINE_VISIBILITY |
| 509 | reference_wrapper<const _Tp> |
| 510 | cref(const _Tp& __t) |
| 511 | { |
| 512 | return reference_wrapper<const _Tp>(__t); |
| 513 | } |
| 514 | |
| 515 | template <class _Tp> |
| 516 | inline _LIBCPP_INLINE_VISIBILITY |
| 517 | reference_wrapper<const _Tp> |
| 518 | cref(reference_wrapper<_Tp> __t) |
| 519 | { |
| 520 | return cref(__t.get()); |
| 521 | } |
| 522 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 523 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 524 | #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 525 | |
| 526 | template <class _Tp> void ref(const _Tp&& __t) = delete; |
| 527 | template <class _Tp> void cref(const _Tp&& __t) = delete; |
| 528 | |
| 529 | #else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 530 | |
| 531 | template <class _Tp> void ref(const _Tp&& __t);// = delete; |
| 532 | template <class _Tp> void cref(const _Tp&& __t);// = delete; |
| 533 | |
| 534 | #endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS |
| 535 | |
| 536 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 537 | |
| 538 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 539 | |
| 540 | _LIBCPP_END_NAMESPACE_STD |
| 541 | |
| 542 | #endif // _LIBCPP_FUNCTIONAL_BASE |