1227825Stheraven// -*- C++ -*- 2227825Stheraven//===----------------------------------------------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_FUNCTIONAL_BASE 12227825Stheraven#define _LIBCPP_FUNCTIONAL_BASE 13227825Stheraven 14227825Stheraven#include <__config> 15227825Stheraven#include <type_traits> 16227825Stheraven#include <typeinfo> 17227825Stheraven#include <exception> 18262801Sdim#include <new> 19227825Stheraven 20227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 21227825Stheraven#pragma GCC system_header 22227825Stheraven#endif 23227825Stheraven 24227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 25227825Stheraven 26227825Stheraventemplate <class _Arg, class _Result> 27262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY unary_function 28227825Stheraven{ 29227825Stheraven typedef _Arg argument_type; 30227825Stheraven typedef _Result result_type; 31227825Stheraven}; 32227825Stheraven 33227825Stheraventemplate <class _Arg1, class _Arg2, class _Result> 34262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY binary_function 35227825Stheraven{ 36227825Stheraven typedef _Arg1 first_argument_type; 37227825Stheraven typedef _Arg2 second_argument_type; 38227825Stheraven typedef _Result result_type; 39227825Stheraven}; 40227825Stheraven 41262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash; 42227825Stheraven 43227825Stheraventemplate <class _Tp> 44227825Stheravenstruct __has_result_type 45227825Stheraven{ 46227825Stheravenprivate: 47243683Sdim struct __two {char __lx; char __lxx;}; 48227825Stheraven template <class _Up> static __two __test(...); 49227825Stheraven template <class _Up> static char __test(typename _Up::result_type* = 0); 50227825Stheravenpublic: 51227825Stheraven static const bool value = sizeof(__test<_Tp>(0)) == 1; 52227825Stheraven}; 53227825Stheraven 54262801Sdim#if _LIBCPP_STD_VER > 11 55262801Sdimtemplate <class _Tp = void> 56262801Sdim#else 57232950Stheraventemplate <class _Tp> 58262801Sdim#endif 59262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool> 60232950Stheraven{ 61262801Sdim _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 62262801Sdim bool operator()(const _Tp& __x, const _Tp& __y) const 63232950Stheraven {return __x < __y;} 64232950Stheraven}; 65232950Stheraven 66262801Sdim#if _LIBCPP_STD_VER > 11 67262801Sdimtemplate <> 68262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY less<void> 69262801Sdim{ 70262801Sdim template <class _T1, class _T2> 71262801Sdim _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 72262801Sdim auto operator()(_T1&& __t, _T2&& __u) const 73262801Sdim { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); } 74262801Sdim typedef void is_transparent; 75262801Sdim}; 76262801Sdim#endif 77262801Sdim 78262801Sdim// addressof 79262801Sdim 80262801Sdimtemplate <class _Tp> 81262801Sdiminline _LIBCPP_INLINE_VISIBILITY 82262801Sdim_Tp* 83262801Sdimaddressof(_Tp& __x) _NOEXCEPT 84262801Sdim{ 85262801Sdim return (_Tp*)&reinterpret_cast<const volatile char&>(__x); 86262801Sdim} 87262801Sdim 88262801Sdim#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) 89262801Sdim// Objective-C++ Automatic Reference Counting uses qualified pointers 90262801Sdim// that require special addressof() signatures. When 91262801Sdim// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler 92262801Sdim// itself is providing these definitions. Otherwise, we provide them. 93262801Sdimtemplate <class _Tp> 94262801Sdiminline _LIBCPP_INLINE_VISIBILITY 95262801Sdim__strong _Tp* 96262801Sdimaddressof(__strong _Tp& __x) _NOEXCEPT 97262801Sdim{ 98262801Sdim return &__x; 99262801Sdim} 100262801Sdim 101262801Sdim#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK 102262801Sdimtemplate <class _Tp> 103262801Sdiminline _LIBCPP_INLINE_VISIBILITY 104262801Sdim__weak _Tp* 105262801Sdimaddressof(__weak _Tp& __x) _NOEXCEPT 106262801Sdim{ 107262801Sdim return &__x; 108262801Sdim} 109262801Sdim#endif 110262801Sdim 111262801Sdimtemplate <class _Tp> 112262801Sdiminline _LIBCPP_INLINE_VISIBILITY 113262801Sdim__autoreleasing _Tp* 114262801Sdimaddressof(__autoreleasing _Tp& __x) _NOEXCEPT 115262801Sdim{ 116262801Sdim return &__x; 117262801Sdim} 118262801Sdim 119262801Sdimtemplate <class _Tp> 120262801Sdiminline _LIBCPP_INLINE_VISIBILITY 121262801Sdim__unsafe_unretained _Tp* 122262801Sdimaddressof(__unsafe_unretained _Tp& __x) _NOEXCEPT 123262801Sdim{ 124262801Sdim return &__x; 125262801Sdim} 126262801Sdim#endif 127262801Sdim 128227825Stheraven#ifdef _LIBCPP_HAS_NO_VARIADICS 129227825Stheraven 130227825Stheraven#include <__functional_base_03> 131227825Stheraven 132227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 133227825Stheraven 134227825Stheraven// __weak_result_type 135227825Stheraven 136227825Stheraventemplate <class _Tp> 137227825Stheravenstruct __derives_from_unary_function 138227825Stheraven{ 139227825Stheravenprivate: 140243683Sdim struct __two {char __lx; char __lxx;}; 141227825Stheraven static __two __test(...); 142232950Stheraven template <class _Ap, class _Rp> 143232950Stheraven static unary_function<_Ap, _Rp> 144232950Stheraven __test(const volatile unary_function<_Ap, _Rp>*); 145227825Stheravenpublic: 146227825Stheraven static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; 147227825Stheraven typedef decltype(__test((_Tp*)0)) type; 148227825Stheraven}; 149227825Stheraven 150227825Stheraventemplate <class _Tp> 151227825Stheravenstruct __derives_from_binary_function 152227825Stheraven{ 153227825Stheravenprivate: 154243683Sdim struct __two {char __lx; char __lxx;}; 155227825Stheraven static __two __test(...); 156232950Stheraven template <class _A1, class _A2, class _Rp> 157232950Stheraven static binary_function<_A1, _A2, _Rp> 158232950Stheraven __test(const volatile binary_function<_A1, _A2, _Rp>*); 159227825Stheravenpublic: 160227825Stheraven static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; 161227825Stheraven typedef decltype(__test((_Tp*)0)) type; 162227825Stheraven}; 163227825Stheraven 164227825Stheraventemplate <class _Tp, bool = __derives_from_unary_function<_Tp>::value> 165227825Stheravenstruct __maybe_derive_from_unary_function // bool is true 166227825Stheraven : public __derives_from_unary_function<_Tp>::type 167227825Stheraven{ 168227825Stheraven}; 169227825Stheraven 170227825Stheraventemplate <class _Tp> 171227825Stheravenstruct __maybe_derive_from_unary_function<_Tp, false> 172227825Stheraven{ 173227825Stheraven}; 174227825Stheraven 175227825Stheraventemplate <class _Tp, bool = __derives_from_binary_function<_Tp>::value> 176227825Stheravenstruct __maybe_derive_from_binary_function // bool is true 177227825Stheraven : public __derives_from_binary_function<_Tp>::type 178227825Stheraven{ 179227825Stheraven}; 180227825Stheraven 181227825Stheraventemplate <class _Tp> 182227825Stheravenstruct __maybe_derive_from_binary_function<_Tp, false> 183227825Stheraven{ 184227825Stheraven}; 185227825Stheraven 186227825Stheraventemplate <class _Tp, bool = __has_result_type<_Tp>::value> 187227825Stheravenstruct __weak_result_type_imp // bool is true 188227825Stheraven : public __maybe_derive_from_unary_function<_Tp>, 189227825Stheraven public __maybe_derive_from_binary_function<_Tp> 190227825Stheraven{ 191227825Stheraven typedef typename _Tp::result_type result_type; 192227825Stheraven}; 193227825Stheraven 194227825Stheraventemplate <class _Tp> 195227825Stheravenstruct __weak_result_type_imp<_Tp, false> 196227825Stheraven : public __maybe_derive_from_unary_function<_Tp>, 197227825Stheraven public __maybe_derive_from_binary_function<_Tp> 198227825Stheraven{ 199227825Stheraven}; 200227825Stheraven 201227825Stheraventemplate <class _Tp> 202227825Stheravenstruct __weak_result_type 203227825Stheraven : public __weak_result_type_imp<_Tp> 204227825Stheraven{ 205227825Stheraven}; 206227825Stheraven 207227825Stheraven// 0 argument case 208227825Stheraven 209232950Stheraventemplate <class _Rp> 210232950Stheravenstruct __weak_result_type<_Rp ()> 211227825Stheraven{ 212232950Stheraven typedef _Rp result_type; 213227825Stheraven}; 214227825Stheraven 215232950Stheraventemplate <class _Rp> 216232950Stheravenstruct __weak_result_type<_Rp (&)()> 217227825Stheraven{ 218232950Stheraven typedef _Rp result_type; 219227825Stheraven}; 220227825Stheraven 221232950Stheraventemplate <class _Rp> 222232950Stheravenstruct __weak_result_type<_Rp (*)()> 223227825Stheraven{ 224232950Stheraven typedef _Rp result_type; 225227825Stheraven}; 226227825Stheraven 227227825Stheraven// 1 argument case 228227825Stheraven 229232950Stheraventemplate <class _Rp, class _A1> 230232950Stheravenstruct __weak_result_type<_Rp (_A1)> 231232950Stheraven : public unary_function<_A1, _Rp> 232227825Stheraven{ 233227825Stheraven}; 234227825Stheraven 235232950Stheraventemplate <class _Rp, class _A1> 236232950Stheravenstruct __weak_result_type<_Rp (&)(_A1)> 237232950Stheraven : public unary_function<_A1, _Rp> 238227825Stheraven{ 239227825Stheraven}; 240227825Stheraven 241232950Stheraventemplate <class _Rp, class _A1> 242232950Stheravenstruct __weak_result_type<_Rp (*)(_A1)> 243232950Stheraven : public unary_function<_A1, _Rp> 244227825Stheraven{ 245227825Stheraven}; 246227825Stheraven 247232950Stheraventemplate <class _Rp, class _Cp> 248232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)()> 249232950Stheraven : public unary_function<_Cp*, _Rp> 250227825Stheraven{ 251227825Stheraven}; 252227825Stheraven 253232950Stheraventemplate <class _Rp, class _Cp> 254232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)() const> 255232950Stheraven : public unary_function<const _Cp*, _Rp> 256227825Stheraven{ 257227825Stheraven}; 258227825Stheraven 259232950Stheraventemplate <class _Rp, class _Cp> 260232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)() volatile> 261232950Stheraven : public unary_function<volatile _Cp*, _Rp> 262227825Stheraven{ 263227825Stheraven}; 264227825Stheraven 265232950Stheraventemplate <class _Rp, class _Cp> 266232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)() const volatile> 267232950Stheraven : public unary_function<const volatile _Cp*, _Rp> 268227825Stheraven{ 269227825Stheraven}; 270227825Stheraven 271227825Stheraven// 2 argument case 272227825Stheraven 273232950Stheraventemplate <class _Rp, class _A1, class _A2> 274232950Stheravenstruct __weak_result_type<_Rp (_A1, _A2)> 275232950Stheraven : public binary_function<_A1, _A2, _Rp> 276227825Stheraven{ 277227825Stheraven}; 278227825Stheraven 279232950Stheraventemplate <class _Rp, class _A1, class _A2> 280232950Stheravenstruct __weak_result_type<_Rp (*)(_A1, _A2)> 281232950Stheraven : public binary_function<_A1, _A2, _Rp> 282227825Stheraven{ 283227825Stheraven}; 284227825Stheraven 285232950Stheraventemplate <class _Rp, class _A1, class _A2> 286232950Stheravenstruct __weak_result_type<_Rp (&)(_A1, _A2)> 287232950Stheraven : public binary_function<_A1, _A2, _Rp> 288227825Stheraven{ 289227825Stheraven}; 290227825Stheraven 291232950Stheraventemplate <class _Rp, class _Cp, class _A1> 292232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1)> 293232950Stheraven : public binary_function<_Cp*, _A1, _Rp> 294227825Stheraven{ 295227825Stheraven}; 296227825Stheraven 297232950Stheraventemplate <class _Rp, class _Cp, class _A1> 298232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1) const> 299232950Stheraven : public binary_function<const _Cp*, _A1, _Rp> 300227825Stheraven{ 301227825Stheraven}; 302227825Stheraven 303232950Stheraventemplate <class _Rp, class _Cp, class _A1> 304232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1) volatile> 305232950Stheraven : public binary_function<volatile _Cp*, _A1, _Rp> 306227825Stheraven{ 307227825Stheraven}; 308227825Stheraven 309232950Stheraventemplate <class _Rp, class _Cp, class _A1> 310232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile> 311232950Stheraven : public binary_function<const volatile _Cp*, _A1, _Rp> 312227825Stheraven{ 313227825Stheraven}; 314227825Stheraven 315227825Stheraven// 3 or more arguments 316227825Stheraven 317232950Stheraventemplate <class _Rp, class _A1, class _A2, class _A3, class ..._A4> 318232950Stheravenstruct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)> 319227825Stheraven{ 320232950Stheraven typedef _Rp result_type; 321227825Stheraven}; 322227825Stheraven 323232950Stheraventemplate <class _Rp, class _A1, class _A2, class _A3, class ..._A4> 324232950Stheravenstruct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)> 325227825Stheraven{ 326232950Stheraven typedef _Rp result_type; 327227825Stheraven}; 328227825Stheraven 329232950Stheraventemplate <class _Rp, class _A1, class _A2, class _A3, class ..._A4> 330232950Stheravenstruct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)> 331227825Stheraven{ 332232950Stheraven typedef _Rp result_type; 333227825Stheraven}; 334227825Stheraven 335232950Stheraventemplate <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> 336232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)> 337227825Stheraven{ 338232950Stheraven typedef _Rp result_type; 339227825Stheraven}; 340227825Stheraven 341232950Stheraventemplate <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> 342232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const> 343227825Stheraven{ 344232950Stheraven typedef _Rp result_type; 345227825Stheraven}; 346227825Stheraven 347232950Stheraventemplate <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> 348232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile> 349227825Stheraven{ 350232950Stheraven typedef _Rp result_type; 351227825Stheraven}; 352227825Stheraven 353232950Stheraventemplate <class _Rp, class _Cp, class _A1, class _A2, class ..._A3> 354232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> 355227825Stheraven{ 356232950Stheraven typedef _Rp result_type; 357227825Stheraven}; 358227825Stheraven 359227825Stheraven// __invoke 360227825Stheraven 361227825Stheraven// bullets 1 and 2 362227825Stheraven 363253222Sdimtemplate <class _Fp, class _A0, class ..._Args, 364253222Sdim class> 365227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 366227825Stheravenauto 367232950Stheraven__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) 368227825Stheraven -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) 369227825Stheraven{ 370227825Stheraven return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...); 371227825Stheraven} 372227825Stheraven 373253222Sdimtemplate <class _Fp, class _A0, class ..._Args, 374253222Sdim class> 375227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 376227825Stheravenauto 377232950Stheraven__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) 378227825Stheraven -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) 379227825Stheraven{ 380227825Stheraven return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...); 381227825Stheraven} 382227825Stheraven 383227825Stheraven// bullets 3 and 4 384227825Stheraven 385253222Sdimtemplate <class _Fp, class _A0, 386253222Sdim class> 387227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 388227825Stheravenauto 389232950Stheraven__invoke(_Fp&& __f, _A0&& __a0) 390227825Stheraven -> decltype(_VSTD::forward<_A0>(__a0).*__f) 391227825Stheraven{ 392227825Stheraven return _VSTD::forward<_A0>(__a0).*__f; 393227825Stheraven} 394227825Stheraven 395253222Sdimtemplate <class _Fp, class _A0, 396253222Sdim class> 397227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 398227825Stheravenauto 399232950Stheraven__invoke(_Fp&& __f, _A0&& __a0) 400227825Stheraven -> decltype((*_VSTD::forward<_A0>(__a0)).*__f) 401227825Stheraven{ 402227825Stheraven return (*_VSTD::forward<_A0>(__a0)).*__f; 403227825Stheraven} 404227825Stheraven 405227825Stheraven// bullet 5 406227825Stheraven 407232950Stheraventemplate <class _Fp, class ..._Args> 408227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 409227825Stheravenauto 410232950Stheraven__invoke(_Fp&& __f, _Args&& ...__args) 411232950Stheraven -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) 412227825Stheraven{ 413232950Stheraven return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...); 414227825Stheraven} 415227825Stheraven 416227825Stheraventemplate <class _Tp, class ..._Args> 417227825Stheravenstruct __invoke_return 418227825Stheraven{ 419227825Stheraven typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type; 420227825Stheraven}; 421227825Stheraven 422227825Stheraventemplate <class _Tp> 423262801Sdimclass _LIBCPP_TYPE_VIS_ONLY reference_wrapper 424227825Stheraven : public __weak_result_type<_Tp> 425227825Stheraven{ 426227825Stheravenpublic: 427227825Stheraven // types 428227825Stheraven typedef _Tp type; 429227825Stheravenprivate: 430227825Stheraven type* __f_; 431227825Stheraven 432227825Stheravenpublic: 433227825Stheraven // construct/copy/destroy 434262801Sdim _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT 435262801Sdim : __f_(_VSTD::addressof(__f)) {} 436227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 437227825Stheraven private: reference_wrapper(type&&); public: // = delete; // do not bind to temps 438227825Stheraven#endif 439227825Stheraven 440227825Stheraven // access 441227825Stheraven _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;} 442227825Stheraven _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;} 443227825Stheraven 444227825Stheraven // invoke 445227825Stheraven template <class... _ArgTypes> 446227825Stheraven _LIBCPP_INLINE_VISIBILITY 447227825Stheraven typename __invoke_of<type&, _ArgTypes...>::type 448227825Stheraven operator() (_ArgTypes&&... __args) const 449227825Stheraven { 450227825Stheraven return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...); 451227825Stheraven } 452227825Stheraven}; 453227825Stheraven 454227825Stheraventemplate <class _Tp> struct ____is_reference_wrapper : public false_type {}; 455227825Stheraventemplate <class _Tp> struct ____is_reference_wrapper<reference_wrapper<_Tp> > : public true_type {}; 456227825Stheraventemplate <class _Tp> struct __is_reference_wrapper 457227825Stheraven : public ____is_reference_wrapper<typename remove_cv<_Tp>::type> {}; 458227825Stheraven 459227825Stheraventemplate <class _Tp> 460227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 461227825Stheravenreference_wrapper<_Tp> 462227825Stheravenref(_Tp& __t) _NOEXCEPT 463227825Stheraven{ 464227825Stheraven return reference_wrapper<_Tp>(__t); 465227825Stheraven} 466227825Stheraven 467227825Stheraventemplate <class _Tp> 468227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 469227825Stheravenreference_wrapper<_Tp> 470227825Stheravenref(reference_wrapper<_Tp> __t) _NOEXCEPT 471227825Stheraven{ 472227825Stheraven return ref(__t.get()); 473227825Stheraven} 474227825Stheraven 475227825Stheraventemplate <class _Tp> 476227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 477227825Stheravenreference_wrapper<const _Tp> 478227825Stheravencref(const _Tp& __t) _NOEXCEPT 479227825Stheraven{ 480227825Stheraven return reference_wrapper<const _Tp>(__t); 481227825Stheraven} 482227825Stheraven 483227825Stheraventemplate <class _Tp> 484227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 485227825Stheravenreference_wrapper<const _Tp> 486227825Stheravencref(reference_wrapper<_Tp> __t) _NOEXCEPT 487227825Stheraven{ 488227825Stheraven return cref(__t.get()); 489227825Stheraven} 490227825Stheraven 491227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 492227825Stheraven#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS 493227825Stheraven 494232950Stheraventemplate <class _Tp> void ref(const _Tp&&) = delete; 495232950Stheraventemplate <class _Tp> void cref(const _Tp&&) = delete; 496227825Stheraven 497227825Stheraven#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS 498227825Stheraven 499232950Stheraventemplate <class _Tp> void ref(const _Tp&&);// = delete; 500232950Stheraventemplate <class _Tp> void cref(const _Tp&&);// = delete; 501227825Stheraven 502227825Stheraven#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS 503227825Stheraven 504227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 505227825Stheraven 506227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 507227825Stheraven 508262801Sdim#if _LIBCPP_STD_VER > 11 509262801Sdimtemplate <class _Tp1, class _Tp2 = void> 510262801Sdimstruct __is_transparent 511262801Sdim{ 512262801Sdimprivate: 513262801Sdim struct __two {char __lx; char __lxx;}; 514262801Sdim template <class _Up> static __two __test(...); 515262801Sdim template <class _Up> static char __test(typename _Up::is_transparent* = 0); 516262801Sdimpublic: 517262801Sdim static const bool value = sizeof(__test<_Tp1>(0)) == 1; 518262801Sdim}; 519262801Sdim#endif 520262801Sdim 521262801Sdim// allocator_arg_t 522262801Sdim 523262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { }; 524262801Sdim 525262801Sdim#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY) 526262801Sdimextern const allocator_arg_t allocator_arg; 527262801Sdim#else 528262801Sdimconstexpr allocator_arg_t allocator_arg = allocator_arg_t(); 529262801Sdim#endif 530262801Sdim 531262801Sdim// uses_allocator 532262801Sdim 533262801Sdimtemplate <class _Tp> 534262801Sdimstruct __has_allocator_type 535262801Sdim{ 536262801Sdimprivate: 537262801Sdim struct __two {char __lx; char __lxx;}; 538262801Sdim template <class _Up> static __two __test(...); 539262801Sdim template <class _Up> static char __test(typename _Up::allocator_type* = 0); 540262801Sdimpublic: 541262801Sdim static const bool value = sizeof(__test<_Tp>(0)) == 1; 542262801Sdim}; 543262801Sdim 544262801Sdimtemplate <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value> 545262801Sdimstruct __uses_allocator 546262801Sdim : public integral_constant<bool, 547262801Sdim is_convertible<_Alloc, typename _Tp::allocator_type>::value> 548262801Sdim{ 549262801Sdim}; 550262801Sdim 551262801Sdimtemplate <class _Tp, class _Alloc> 552262801Sdimstruct __uses_allocator<_Tp, _Alloc, false> 553262801Sdim : public false_type 554262801Sdim{ 555262801Sdim}; 556262801Sdim 557262801Sdimtemplate <class _Tp, class _Alloc> 558262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY uses_allocator 559262801Sdim : public __uses_allocator<_Tp, _Alloc> 560262801Sdim{ 561262801Sdim}; 562262801Sdim 563262801Sdim#ifndef _LIBCPP_HAS_NO_VARIADICS 564262801Sdim 565262801Sdim// allocator construction 566262801Sdim 567262801Sdimtemplate <class _Tp, class _Alloc, class ..._Args> 568262801Sdimstruct __uses_alloc_ctor_imp 569262801Sdim{ 570262801Sdim static const bool __ua = uses_allocator<_Tp, _Alloc>::value; 571262801Sdim static const bool __ic = 572262801Sdim is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; 573262801Sdim static const int value = __ua ? 2 - __ic : 0; 574262801Sdim}; 575262801Sdim 576262801Sdimtemplate <class _Tp, class _Alloc, class ..._Args> 577262801Sdimstruct __uses_alloc_ctor 578262801Sdim : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> 579262801Sdim {}; 580262801Sdim 581262801Sdimtemplate <class _Tp, class _Allocator, class... _Args> 582262801Sdiminline _LIBCPP_INLINE_VISIBILITY 583262801Sdimvoid __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args ) 584262801Sdim{ 585262801Sdim new (__storage) _Tp (_VSTD::forward<_Args>(__args)...); 586262801Sdim} 587262801Sdim 588262801Sdimtemplate <class _Tp, class _Allocator, class... _Args> 589262801Sdiminline _LIBCPP_INLINE_VISIBILITY 590262801Sdimvoid __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) 591262801Sdim{ 592262801Sdim new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...); 593262801Sdim} 594262801Sdim 595262801Sdimtemplate <class _Tp, class _Allocator, class... _Args> 596262801Sdiminline _LIBCPP_INLINE_VISIBILITY 597262801Sdimvoid __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) 598262801Sdim{ 599262801Sdim new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a); 600262801Sdim} 601262801Sdim 602262801Sdimtemplate <class _Tp, class _Allocator, class... _Args> 603262801Sdiminline _LIBCPP_INLINE_VISIBILITY 604262801Sdimvoid __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args) 605262801Sdim{ 606262801Sdim __user_alloc_construct_impl( 607262801Sdim __uses_alloc_ctor<_Tp, _Allocator>(), 608262801Sdim __storage, __a, _VSTD::forward<_Args>(__args)... 609262801Sdim ); 610262801Sdim} 611262801Sdim#endif // _LIBCPP_HAS_NO_VARIADICS 612262801Sdim 613227825Stheraven_LIBCPP_END_NAMESPACE_STD 614227825Stheraven 615227825Stheraven#endif // _LIBCPP_FUNCTIONAL_BASE 616