|
11 | 11 | #define _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H |
12 | 12 |
|
13 | 13 | #include <__config> |
| 14 | +#include <__cstddef/ptrdiff_t.h> |
14 | 15 | #include <__cstddef/size_t.h> |
15 | 16 | #include <__fwd/memory.h> |
16 | 17 | #include <__memory/construct_at.h> |
@@ -336,6 +337,80 @@ struct allocator_traits { |
336 | 337 | } |
337 | 338 | }; |
338 | 339 |
|
| 340 | +template <class _Tp> |
| 341 | +struct allocator_traits<allocator<_Tp>> { |
| 342 | + using allocator_type = allocator<_Tp>; |
| 343 | + using value_type = _Tp; |
| 344 | + using pointer = _Tp*; |
| 345 | + using const_pointer = const _Tp*; |
| 346 | + using void_pointer = void*; |
| 347 | + using const_void_pointer = const void*; |
| 348 | + using difference_type = ptrdiff_t; |
| 349 | + using size_type = size_t; |
| 350 | + using propagate_on_container_copy_assignment = false_type; |
| 351 | + using propagate_on_container_move_assignment = true_type; |
| 352 | + using propagate_on_container_swap = false_type; |
| 353 | + using is_always_equal = true_type; |
| 354 | + |
| 355 | +#ifndef _LIBCPP_CXX03_LANG |
| 356 | + template <class _Up> |
| 357 | + using rebind_alloc = allocator<_Up>; |
| 358 | + template <class _Up> |
| 359 | + using rebind_traits = allocator_traits<allocator<_Up>>; |
| 360 | +#else |
| 361 | + template <class _Up> |
| 362 | + struct rebind_alloc { |
| 363 | + using other = allocator<_Up>; |
| 364 | + }; |
| 365 | + template <class _Up> |
| 366 | + struct rebind_traits { |
| 367 | + using other = allocator_traits<allocator<_Up> >; |
| 368 | + }; |
| 369 | +#endif |
| 370 | + |
| 371 | + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI |
| 372 | + _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer allocate(allocator_type& __alloc, size_type __n) { |
| 373 | + return __alloc.allocate(__n); |
| 374 | + } |
| 375 | + |
| 376 | + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer |
| 377 | + allocate(allocator_type& __alloc, size_type __n, const_void_pointer) { |
| 378 | + return __alloc.allocate(__n); |
| 379 | + } |
| 380 | + |
| 381 | +#if _LIBCPP_STD_VER >= 23 |
| 382 | + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr allocation_result<pointer, size_type> |
| 383 | + allocate_at_least(allocator_type& __alloc, size_type __n) { |
| 384 | + return {__alloc.allocate(__n), __n}; |
| 385 | + } |
| 386 | +#endif |
| 387 | + |
| 388 | + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void |
| 389 | + deallocate(allocator_type& __alloc, pointer __ptr, size_type __n) _NOEXCEPT { |
| 390 | + __alloc.deallocate(__ptr, __n); |
| 391 | + } |
| 392 | + |
| 393 | + template <class _Up, class... _Args> |
| 394 | + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void |
| 395 | + construct(allocator_type&, _Up* __ptr, _Args&&... __args) { |
| 396 | + std::__construct_at(__ptr, std::forward<_Args>(__args)...); |
| 397 | + } |
| 398 | + |
| 399 | + template <class _Up> |
| 400 | + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void destroy(allocator_type&, _Up* __ptr) { |
| 401 | + std::__destroy_at(__ptr); |
| 402 | + } |
| 403 | + |
| 404 | + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type max_size(const allocator_type&) _NOEXCEPT { |
| 405 | + return numeric_limits<size_type>::max() / sizeof(value_type); |
| 406 | + } |
| 407 | + |
| 408 | + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static allocator_type |
| 409 | + select_on_container_copy_construction(const allocator_type&) _NOEXCEPT { |
| 410 | + return allocator_type(); |
| 411 | + } |
| 412 | +}; |
| 413 | + |
339 | 414 | #ifndef _LIBCPP_CXX03_LANG |
340 | 415 | template <class _Traits, class _Tp> |
341 | 416 | using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>; |
|
0 commit comments