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