__functional_base 17 KB

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