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