allocator_access.hpp 19 KB

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