__functional_base 18 KB

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