allocator_access.hpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /*
  2. Copyright 2020-2022 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BHO_CORE_ALLOCATOR_ACCESS_HPP
  8. #define BHO_CORE_ALLOCATOR_ACCESS_HPP
  9. #include <asio2/bho/config.hpp>
  10. #include <asio2/bho/core/pointer_traits.hpp>
  11. #include <limits>
  12. #include <new>
  13. #if !defined(BHO_NO_CXX11_ALLOCATOR)
  14. #include <type_traits>
  15. #endif
  16. #if !defined(BHO_NO_CXX11_RVALUE_REFERENCES)
  17. #include <utility>
  18. #endif
  19. #if defined(BHO_GCC_VERSION) && (BHO_GCC_VERSION >= 40300)
  20. #define BHO_DETAIL_ALLOC_EMPTY(T) __is_empty(T)
  21. #elif defined(BHO_INTEL) && defined(_MSC_VER) && (_MSC_VER >= 1500)
  22. #define BHO_DETAIL_ALLOC_EMPTY(T) __is_empty(T)
  23. #elif defined(BHO_MSVC) && (BHO_MSVC >= 1400)
  24. #define BHO_DETAIL_ALLOC_EMPTY(T) __is_empty(T)
  25. #elif defined(BHO_CLANG) && !defined(__CUDACC__)
  26. #if __has_feature(is_empty)
  27. #define BHO_DETAIL_ALLOC_EMPTY(T) __is_empty(T)
  28. #endif
  29. #elif defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x5130)
  30. #define BHO_DETAIL_ALLOC_EMPTY(T) __oracle_is_empty(T)
  31. #elif defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600)
  32. #define BHO_DETAIL_ALLOC_EMPTY(T) __is_empty(T)
  33. #elif defined(BHO_CODEGEARC)
  34. #define BHO_DETAIL_ALLOC_EMPTY(T) __is_empty(T)
  35. #endif
  36. #if defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH)
  37. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  38. #endif
  39. #if defined(_STL_DISABLE_DEPRECATED_WARNING)
  40. _STL_DISABLE_DEPRECATED_WARNING
  41. #endif
  42. #if defined(_MSC_VER)
  43. #pragma warning(push)
  44. #pragma warning(disable:4996)
  45. #endif
  46. namespace bho {
  47. template<class A>
  48. struct allocator_value_type {
  49. typedef typename A::value_type type;
  50. };
  51. namespace detail {
  52. template<class A, class = void>
  53. struct alloc_ptr {
  54. typedef typename bho::allocator_value_type<A>::type* type;
  55. };
  56. template<class>
  57. struct alloc_void {
  58. typedef void type;
  59. };
  60. template<class A>
  61. struct alloc_ptr<A,
  62. typename alloc_void<typename A::pointer>::type> {
  63. typedef typename A::pointer type;
  64. };
  65. } /* detail */
  66. template<class A>
  67. struct allocator_pointer {
  68. typedef typename detail::alloc_ptr<A>::type type;
  69. };
  70. namespace detail {
  71. template<class A, class = void>
  72. struct alloc_const_ptr {
  73. typedef typename bho::pointer_traits<typename
  74. bho::allocator_pointer<A>::type>::template rebind_to<const typename
  75. bho::allocator_value_type<A>::type>::type type;
  76. };
  77. template<class A>
  78. struct alloc_const_ptr<A,
  79. typename alloc_void<typename A::const_pointer>::type> {
  80. typedef typename A::const_pointer type;
  81. };
  82. } /* detail */
  83. template<class A>
  84. struct allocator_const_pointer {
  85. typedef typename detail::alloc_const_ptr<A>::type type;
  86. };
  87. namespace detail {
  88. template<class, class>
  89. struct alloc_to { };
  90. #if defined(BHO_NO_CXX11_VARIADIC_TEMPLATES)
  91. template<template<class> class A, class T, class U>
  92. struct alloc_to<A<U>, T> {
  93. typedef A<T> type;
  94. };
  95. template<template<class, class> class A, class T, class U, class V>
  96. struct alloc_to<A<U, V>, T> {
  97. typedef A<T, V> type;
  98. };
  99. template<template<class, class, class> class A, class T, class U, class V1,
  100. class V2>
  101. struct alloc_to<A<U, V1, V2>, T> {
  102. typedef A<T, V1, V2> type;
  103. };
  104. #else
  105. template<template<class, class...> class A, class T, class U, class... V>
  106. struct alloc_to<A<U, V...>, T> {
  107. typedef A<T, V...> type;
  108. };
  109. #endif
  110. template<class A, class T, class = void>
  111. struct alloc_rebind {
  112. typedef typename alloc_to<A, T>::type type;
  113. };
  114. template<class A, class T>
  115. struct alloc_rebind<A, T,
  116. typename alloc_void<typename A::template rebind<T>::other>::type> {
  117. typedef typename A::template rebind<T>::other type;
  118. };
  119. } /* detail */
  120. template<class A, class T>
  121. struct allocator_rebind {
  122. typedef typename detail::alloc_rebind<A, T>::type type;
  123. };
  124. namespace detail {
  125. template<class A, class = void>
  126. struct alloc_void_ptr {
  127. typedef typename bho::pointer_traits<typename
  128. bho::allocator_pointer<A>::type>::template
  129. rebind_to<void>::type type;
  130. };
  131. template<class A>
  132. struct alloc_void_ptr<A,
  133. typename alloc_void<typename A::void_pointer>::type> {
  134. typedef typename A::void_pointer type;
  135. };
  136. } /* detail */
  137. template<class A>
  138. struct allocator_void_pointer {
  139. typedef typename detail::alloc_void_ptr<A>::type type;
  140. };
  141. namespace detail {
  142. template<class A, class = void>
  143. struct alloc_const_void_ptr {
  144. typedef typename bho::pointer_traits<typename
  145. bho::allocator_pointer<A>::type>::template
  146. rebind_to<const void>::type type;
  147. };
  148. template<class A>
  149. struct alloc_const_void_ptr<A,
  150. typename alloc_void<typename A::const_void_pointer>::type> {
  151. typedef typename A::const_void_pointer type;
  152. };
  153. } /* detail */
  154. template<class A>
  155. struct allocator_const_void_pointer {
  156. typedef typename detail::alloc_const_void_ptr<A>::type type;
  157. };
  158. namespace detail {
  159. template<class A, class = void>
  160. struct alloc_diff_type {
  161. typedef typename bho::pointer_traits<typename
  162. bho::allocator_pointer<A>::type>::difference_type type;
  163. };
  164. template<class A>
  165. struct alloc_diff_type<A,
  166. typename alloc_void<typename A::difference_type>::type> {
  167. typedef typename A::difference_type type;
  168. };
  169. } /* detail */
  170. template<class A>
  171. struct allocator_difference_type {
  172. typedef typename detail::alloc_diff_type<A>::type type;
  173. };
  174. namespace detail {
  175. #if defined(BHO_NO_CXX11_ALLOCATOR)
  176. template<class A, class = void>
  177. struct alloc_size_type {
  178. typedef std::size_t type;
  179. };
  180. #else
  181. template<class A, class = void>
  182. struct alloc_size_type {
  183. typedef typename std::make_unsigned<typename
  184. bho::allocator_difference_type<A>::type>::type type;
  185. };
  186. #endif
  187. template<class A>
  188. struct alloc_size_type<A,
  189. typename alloc_void<typename A::size_type>::type> {
  190. typedef typename A::size_type type;
  191. };
  192. } /* detail */
  193. template<class A>
  194. struct allocator_size_type {
  195. typedef typename detail::alloc_size_type<A>::type type;
  196. };
  197. namespace detail {
  198. #if defined(BHO_NO_CXX11_ALLOCATOR)
  199. template<bool V>
  200. struct alloc_bool {
  201. typedef bool value_type;
  202. typedef alloc_bool type;
  203. static const bool value = V;
  204. operator bool() const BHO_NOEXCEPT {
  205. return V;
  206. }
  207. bool operator()() const BHO_NOEXCEPT {
  208. return V;
  209. }
  210. };
  211. template<bool V>
  212. const bool alloc_bool<V>::value;
  213. typedef alloc_bool<false> alloc_false;
  214. #else
  215. typedef std::false_type alloc_false;
  216. #endif
  217. template<class A, class = void>
  218. struct alloc_pocca {
  219. typedef alloc_false type;
  220. };
  221. template<class A>
  222. struct alloc_pocca<A,
  223. typename alloc_void<typename
  224. A::propagate_on_container_copy_assignment>::type> {
  225. typedef typename A::propagate_on_container_copy_assignment type;
  226. };
  227. } /* detail */
  228. template<class A, class = void>
  229. struct allocator_propagate_on_container_copy_assignment {
  230. typedef typename detail::alloc_pocca<A>::type type;
  231. };
  232. namespace detail {
  233. template<class A, class = void>
  234. struct alloc_pocma {
  235. typedef alloc_false type;
  236. };
  237. template<class A>
  238. struct alloc_pocma<A,
  239. typename alloc_void<typename
  240. A::propagate_on_container_move_assignment>::type> {
  241. typedef typename A::propagate_on_container_move_assignment type;
  242. };
  243. } /* detail */
  244. template<class A>
  245. struct allocator_propagate_on_container_move_assignment {
  246. typedef typename detail::alloc_pocma<A>::type type;
  247. };
  248. namespace detail {
  249. template<class A, class = void>
  250. struct alloc_pocs {
  251. typedef alloc_false type;
  252. };
  253. template<class A>
  254. struct alloc_pocs<A,
  255. typename alloc_void<typename A::propagate_on_container_swap>::type> {
  256. typedef typename A::propagate_on_container_swap type;
  257. };
  258. } /* detail */
  259. template<class A>
  260. struct allocator_propagate_on_container_swap {
  261. typedef typename detail::alloc_pocs<A>::type type;
  262. };
  263. namespace detail {
  264. #if !defined(BHO_NO_CXX11_ALLOCATOR)
  265. template<class A, class = void>
  266. struct alloc_equal {
  267. typedef typename std::is_empty<A>::type type;
  268. };
  269. #elif defined(BHO_DETAIL_ALLOC_EMPTY)
  270. template<class A, class = void>
  271. struct alloc_equal {
  272. typedef alloc_bool<BHO_DETAIL_ALLOC_EMPTY(A)> type;
  273. };
  274. #else
  275. template<class A, class = void>
  276. struct alloc_equal {
  277. typedef alloc_false type;
  278. };
  279. #endif
  280. template<class A>
  281. struct alloc_equal<A,
  282. typename alloc_void<typename A::is_always_equal>::type> {
  283. typedef typename A::is_always_equal type;
  284. };
  285. } /* detail */
  286. template<class A>
  287. struct allocator_is_always_equal {
  288. typedef typename detail::alloc_equal<A>::type type;
  289. };
  290. template<class A>
  291. inline typename allocator_pointer<A>::type
  292. allocator_allocate(A& a, typename allocator_size_type<A>::type n)
  293. {
  294. return a.allocate(n);
  295. }
  296. template<class A>
  297. inline void
  298. allocator_deallocate(A& a, typename allocator_pointer<A>::type p,
  299. typename allocator_size_type<A>::type n)
  300. {
  301. a.deallocate(p, n);
  302. }
  303. #if defined(BHO_NO_CXX11_ALLOCATOR)
  304. template<class A>
  305. inline typename allocator_pointer<A>::type
  306. allocator_allocate(A& a, typename allocator_size_type<A>::type n,
  307. typename allocator_const_void_pointer<A>::type h)
  308. {
  309. return a.allocate(n, h);
  310. }
  311. #else
  312. namespace detail {
  313. template<class>
  314. struct alloc_no {
  315. char x, y;
  316. };
  317. template<class A>
  318. class alloc_has_allocate {
  319. template<class O>
  320. static auto check(int)
  321. -> alloc_no<decltype(std::declval<O&>().allocate(std::declval<typename
  322. bho::allocator_size_type<A>::type>(), std::declval<typename
  323. bho::allocator_const_void_pointer<A>::type>()))>;
  324. template<class>
  325. static char check(long);
  326. public:
  327. BHO_STATIC_CONSTEXPR bool value = sizeof(check<A>(0)) > 1;
  328. };
  329. } /* detail */
  330. template<class A>
  331. inline typename std::enable_if<detail::alloc_has_allocate<A>::value,
  332. typename allocator_pointer<A>::type>::type
  333. allocator_allocate(A& a, typename allocator_size_type<A>::type n,
  334. typename allocator_const_void_pointer<A>::type h)
  335. {
  336. return a.allocate(n, h);
  337. }
  338. template<class A>
  339. inline typename std::enable_if<!detail::alloc_has_allocate<A>::value,
  340. typename allocator_pointer<A>::type>::type
  341. allocator_allocate(A& a, typename allocator_size_type<A>::type n,
  342. typename allocator_const_void_pointer<A>::type)
  343. {
  344. return a.allocate(n);
  345. }
  346. #endif
  347. namespace detail {
  348. #if defined(BHO_NO_CXX11_ALLOCATOR)
  349. template<class A, class = void>
  350. struct alloc_has_construct {
  351. BHO_STATIC_CONSTEXPR bool value = false;
  352. };
  353. template<class A>
  354. struct alloc_has_construct<A,
  355. typename alloc_void<typename A::_default_construct_destroy>::type> {
  356. BHO_STATIC_CONSTEXPR bool value = true;
  357. };
  358. #else
  359. template<class A, class T, class... Args>
  360. class alloc_has_construct {
  361. template<class O>
  362. static auto check(int)
  363. -> alloc_no<decltype(std::declval<O&>().construct(std::declval<T*>(),
  364. std::declval<Args&&>()...))>;
  365. template<class>
  366. static char check(long);
  367. public:
  368. BHO_STATIC_CONSTEXPR bool value = sizeof(check<A>(0)) > 1;
  369. };
  370. #endif
  371. template<bool, class = void>
  372. struct alloc_if { };
  373. template<class T>
  374. struct alloc_if<true, T> {
  375. typedef T type;
  376. };
  377. } /* detail */
  378. #if defined(BHO_NO_CXX11_ALLOCATOR)
  379. template<class A, class T>
  380. inline typename detail::alloc_if<detail::alloc_has_construct<A>::value>::type
  381. allocator_construct(A& a, T* p)
  382. {
  383. a.construct(p);
  384. }
  385. template<class A, class T>
  386. inline typename detail::alloc_if<!detail::alloc_has_construct<A>::value>::type
  387. allocator_construct(A&, T* p)
  388. {
  389. ::new((void*)p) T();
  390. }
  391. #if !defined(BHO_NO_CXX11_RVALUE_REFERENCES)
  392. #if !defined(BHO_NO_CXX11_VARIADIC_TEMPLATES)
  393. template<class A, class T, class V, class... Args>
  394. inline void
  395. allocator_construct(A&, T* p, V&& v, Args&&... args)
  396. {
  397. ::new((void*)p) T(std::forward<V>(v), std::forward<Args>(args)...);
  398. }
  399. #else
  400. template<class A, class T, class V>
  401. inline void
  402. allocator_construct(A&, T* p, V&& v)
  403. {
  404. ::new((void*)p) T(std::forward<V>(v));
  405. }
  406. #endif
  407. #else
  408. template<class A, class T, class V>
  409. inline void
  410. allocator_construct(A&, T* p, const V& v)
  411. {
  412. ::new((void*)p) T(v);
  413. }
  414. template<class A, class T, class V>
  415. inline void
  416. allocator_construct(A&, T* p, V& v)
  417. {
  418. ::new((void*)p) T(v);
  419. }
  420. #endif
  421. #else
  422. template<class A, class T, class... Args>
  423. inline typename std::enable_if<detail::alloc_has_construct<A, T,
  424. Args...>::value>::type
  425. allocator_construct(A& a, T* p, Args&&... args)
  426. {
  427. a.construct(p, std::forward<Args>(args)...);
  428. }
  429. template<class A, class T, class... Args>
  430. inline typename std::enable_if<!detail::alloc_has_construct<A, T,
  431. Args...>::value>::type
  432. allocator_construct(A&, T* p, Args&&... args)
  433. {
  434. ::new((void*)p) T(std::forward<Args>(args)...);
  435. }
  436. #endif
  437. namespace detail {
  438. #if defined(BHO_NO_CXX11_ALLOCATOR)
  439. template<class A, class, class = void>
  440. struct alloc_has_destroy {
  441. BHO_STATIC_CONSTEXPR bool value = false;
  442. };
  443. template<class A, class T>
  444. struct alloc_has_destroy<A, T,
  445. typename alloc_void<typename A::_default_construct_destroy>::type> {
  446. BHO_STATIC_CONSTEXPR bool value = true;
  447. };
  448. #else
  449. template<class A, class T>
  450. class alloc_has_destroy {
  451. template<class O>
  452. static auto check(int)
  453. -> alloc_no<decltype(std::declval<O&>().destroy(std::declval<T*>()))>;
  454. template<class>
  455. static char check(long);
  456. public:
  457. BHO_STATIC_CONSTEXPR bool value = sizeof(check<A>(0)) > 1;
  458. };
  459. #endif
  460. } /* detail */
  461. template<class A, class T>
  462. inline typename detail::alloc_if<detail::alloc_has_destroy<A, T>::value>::type
  463. allocator_destroy(A& a, T* p)
  464. {
  465. a.destroy(p);
  466. }
  467. template<class A, class T>
  468. inline typename detail::alloc_if<!detail::alloc_has_destroy<A, T>::value>::type
  469. allocator_destroy(A&, T* p)
  470. {
  471. p->~T();
  472. (void)p;
  473. }
  474. namespace detail {
  475. #if defined(BHO_NO_CXX11_ALLOCATOR)
  476. template<class T, T>
  477. struct alloc_no {
  478. char x, y;
  479. };
  480. template<class A>
  481. class alloc_has_max_size {
  482. template<class O>
  483. static alloc_no<typename bho::allocator_size_type<O>::type(O::*)(),
  484. &O::max_size> check(int);
  485. template<class O>
  486. static alloc_no<typename bho::allocator_size_type<O>::type(O::*)() const,
  487. &O::max_size> check(int);
  488. template<class O>
  489. static alloc_no<typename bho::allocator_size_type<O>::type(*)(),
  490. &O::max_size> check(int);
  491. template<class>
  492. static char check(long);
  493. public:
  494. BHO_STATIC_CONSTEXPR bool value = sizeof(check<A>(0)) > 1;
  495. };
  496. #else
  497. template<class A>
  498. class alloc_has_max_size {
  499. template<class O>
  500. static auto check(int)
  501. -> alloc_no<decltype(std::declval<const O&>().max_size())>;
  502. template<class>
  503. static char check(long);
  504. public:
  505. BHO_STATIC_CONSTEXPR bool value = sizeof(check<A>(0)) > 1;
  506. };
  507. #endif
  508. } /* detail */
  509. template<class A>
  510. inline typename detail::alloc_if<detail::alloc_has_max_size<A>::value,
  511. typename allocator_size_type<A>::type>::type
  512. allocator_max_size(const A& a) BHO_NOEXCEPT
  513. {
  514. return a.max_size();
  515. }
  516. template<class A>
  517. inline typename detail::alloc_if<!detail::alloc_has_max_size<A>::value,
  518. typename allocator_size_type<A>::type>::type
  519. allocator_max_size(const A&) BHO_NOEXCEPT
  520. {
  521. return (std::numeric_limits<typename
  522. allocator_size_type<A>::type>::max)() /
  523. sizeof(typename allocator_value_type<A>::type);
  524. }
  525. namespace detail {
  526. #if defined(BHO_NO_CXX11_ALLOCATOR)
  527. template<class A>
  528. class alloc_has_soccc {
  529. template<class O>
  530. static alloc_no<O(O::*)(), &O::select_on_container_copy_construction>
  531. check(int);
  532. template<class O>
  533. static alloc_no<O(O::*)() const, &O::select_on_container_copy_construction>
  534. check(int);
  535. template<class O>
  536. static alloc_no<O(*)(), &O::select_on_container_copy_construction>
  537. check(int);
  538. template<class>
  539. static char check(long);
  540. public:
  541. BHO_STATIC_CONSTEXPR bool value = sizeof(check<A>(0)) > 1;
  542. };
  543. #else
  544. template<class A>
  545. class alloc_has_soccc {
  546. template<class O>
  547. static auto check(int) -> alloc_no<decltype(std::declval<const
  548. O&>().select_on_container_copy_construction())>;
  549. template<class>
  550. static char check(long);
  551. public:
  552. BHO_STATIC_CONSTEXPR bool value = sizeof(check<A>(0)) > 1;
  553. };
  554. #endif
  555. } /* detail */
  556. template<class A>
  557. inline typename detail::alloc_if<detail::alloc_has_soccc<A>::value, A>::type
  558. allocator_select_on_container_copy_construction(const A& a)
  559. {
  560. return a.select_on_container_copy_construction();
  561. }
  562. template<class A>
  563. inline typename detail::alloc_if<!detail::alloc_has_soccc<A>::value, A>::type
  564. allocator_select_on_container_copy_construction(const A& a)
  565. {
  566. return a;
  567. }
  568. template<class A, class T>
  569. inline void
  570. allocator_destroy_n(A& a, T* p, std::size_t n)
  571. {
  572. while (n > 0) {
  573. bho::allocator_destroy(a, p + --n);
  574. }
  575. }
  576. namespace detail {
  577. template<class A, class T>
  578. class alloc_destroyer {
  579. public:
  580. alloc_destroyer(A& a, T* p) BHO_NOEXCEPT
  581. : a_(a), p_(p), n_(0) { }
  582. ~alloc_destroyer() {
  583. bho::allocator_destroy_n(a_, p_, n_);
  584. }
  585. std::size_t& size() BHO_NOEXCEPT {
  586. return n_;
  587. }
  588. private:
  589. alloc_destroyer(const alloc_destroyer&);
  590. alloc_destroyer& operator=(const alloc_destroyer&);
  591. A& a_;
  592. T* p_;
  593. std::size_t n_;
  594. };
  595. } /* detail */
  596. template<class A, class T>
  597. inline void
  598. allocator_construct_n(A& a, T* p, std::size_t n)
  599. {
  600. detail::alloc_destroyer<A, T> d(a, p);
  601. for (std::size_t& i = d.size(); i < n; ++i) {
  602. bho::allocator_construct(a, p + i);
  603. }
  604. d.size() = 0;
  605. }
  606. template<class A, class T>
  607. inline void
  608. allocator_construct_n(A& a, T* p, std::size_t n, const T* l, std::size_t m)
  609. {
  610. detail::alloc_destroyer<A, T> d(a, p);
  611. for (std::size_t& i = d.size(); i < n; ++i) {
  612. bho::allocator_construct(a, p + i, l[i % m]);
  613. }
  614. d.size() = 0;
  615. }
  616. template<class A, class T, class I>
  617. inline void
  618. allocator_construct_n(A& a, T* p, std::size_t n, I b)
  619. {
  620. detail::alloc_destroyer<A, T> d(a, p);
  621. for (std::size_t& i = d.size(); i < n; void(++i), void(++b)) {
  622. bho::allocator_construct(a, p + i, *b);
  623. }
  624. d.size() = 0;
  625. }
  626. #if !defined(BHO_NO_CXX11_TEMPLATE_ALIASES)
  627. template<class A>
  628. using allocator_value_type_t = typename allocator_value_type<A>::type;
  629. template<class A>
  630. using allocator_pointer_t = typename allocator_pointer<A>::type;
  631. template<class A>
  632. using allocator_const_pointer_t = typename allocator_const_pointer<A>::type;
  633. template<class A>
  634. using allocator_void_pointer_t = typename allocator_void_pointer<A>::type;
  635. template<class A>
  636. using allocator_const_void_pointer_t =
  637. typename allocator_const_void_pointer<A>::type;
  638. template<class A>
  639. using allocator_difference_type_t =
  640. typename allocator_difference_type<A>::type;
  641. template<class A>
  642. using allocator_size_type_t = typename allocator_size_type<A>::type;
  643. template<class A>
  644. using allocator_propagate_on_container_copy_assignment_t =
  645. typename allocator_propagate_on_container_copy_assignment<A>::type;
  646. template<class A>
  647. using allocator_propagate_on_container_move_assignment_t =
  648. typename allocator_propagate_on_container_move_assignment<A>::type;
  649. template<class A>
  650. using allocator_propagate_on_container_swap_t =
  651. typename allocator_propagate_on_container_swap<A>::type;
  652. template<class A>
  653. using allocator_is_always_equal_t =
  654. typename allocator_is_always_equal<A>::type;
  655. template<class A, class T>
  656. using allocator_rebind_t = typename allocator_rebind<A, T>::type;
  657. #endif
  658. } /* boost */
  659. #if defined(_MSC_VER)
  660. #pragma warning(pop)
  661. #endif
  662. #if defined(_STL_RESTORE_DEPRECATED_WARNING)
  663. _STL_RESTORE_DEPRECATED_WARNING
  664. #endif
  665. #if defined(_LIBCPP_SUPPRESS_DEPRECATED_POP)
  666. _LIBCPP_SUPPRESS_DEPRECATED_POP
  667. #endif
  668. #endif