|
12369 | 12369 | \indexlibrarymember{value_type}{polymorphic_allocator}%
|
12370 | 12370 | \begin{codeblock}
|
12371 | 12371 | namespace std::pmr {
|
12372 |
| - template<class Tp> class polymorphic_allocator { |
| 12372 | + template<class Tp = byte> class polymorphic_allocator { |
12373 | 12373 | memory_resource* memory_rsrc; // \expos
|
12374 | 12374 |
|
12375 | 12375 | public:
|
|
12390 | 12390 | [[nodiscard]] Tp* allocate(size_t n);
|
12391 | 12391 | void deallocate(Tp* p, size_t n);
|
12392 | 12392 |
|
| 12393 | + void* allocate_bytes(size_t nbytes, size_t alignment = alignof(max_align_t)); |
| 12394 | + void deallocate_bytes(void* p, size_t nbytes, size_t alignment = alignof(max_align_t)); |
| 12395 | + template <class T> T* allocate_object(size_t n = 1); |
| 12396 | + template <class T> void deallocate_object(T* p, size_t n = 1); |
| 12397 | + template <class T, class... CtorArgs> T* new_object(CtorArgs&&... ctor_args); |
| 12398 | + template <class T> void delete_object(T* p); |
| 12399 | + |
12393 | 12400 | template<class T, class... Args>
|
12394 | 12401 | void construct(T* p, Args&&... args);
|
12395 | 12402 |
|
@@ -12490,6 +12497,119 @@
|
12490 | 12497 | Nothing.
|
12491 | 12498 | \end{itemdescr}
|
12492 | 12499 |
|
| 12500 | +\indexlibrarymember{allocate_bytes}{polymorphic_allocator}% |
| 12501 | +\begin{itemdecl} |
| 12502 | +void* allocate_bytes(size_t nbytes, size_t alignment = alignof(max_align_t)); |
| 12503 | +\end{itemdecl} |
| 12504 | + |
| 12505 | +\begin{itemdescr} |
| 12506 | +\pnum |
| 12507 | +\effects |
| 12508 | +Equivalent to: \tcode{return memory_rsrc->allocate(nbytes, alignment);} |
| 12509 | + |
| 12510 | +\pnum |
| 12511 | +\begin{note} |
| 12512 | +The return type is \tcode{void*} (rather than, e.g., \tcode{byte*}) |
| 12513 | +to support conversion to an arbitrary pointer type \tcode{U*} |
| 12514 | +by \tcode{static_cast<U*>}, thus facilitating construction of a \tcode{U} |
| 12515 | +object in the allocated memory. |
| 12516 | +\end{note} |
| 12517 | +\end{itemdescr} |
| 12518 | + |
| 12519 | +\indexlibrarymember{deallocate_bytes}{polymorphic_allocator}% |
| 12520 | +\begin{itemdecl} |
| 12521 | +void deallocate_bytes(void* p, size_t nbytes, size_t alignment = alignof(max_align_t)); |
| 12522 | +\end{itemdecl} |
| 12523 | + |
| 12524 | +\begin{itemdescr} |
| 12525 | +\pnum |
| 12526 | +\effects |
| 12527 | +Equivalent to \tcode{memory_rsrc->deallocate(p, nbytes, alignment)}. |
| 12528 | +\end{itemdescr} |
| 12529 | + |
| 12530 | +\indexlibrarymember{allocate_object}{polymorphic_allocator}% |
| 12531 | +\begin{itemdecl} |
| 12532 | +template <class T> |
| 12533 | + T* allocate_object(size_t n = 1); |
| 12534 | +\end{itemdecl} |
| 12535 | + |
| 12536 | +\begin{itemdescr} |
| 12537 | +\pnum |
| 12538 | +\effects |
| 12539 | +Allocates memory suitable for holding |
| 12540 | +an array of \tcode{n} objects of type \tcode{T}, as follows: |
| 12541 | +\begin{itemize} |
| 12542 | +\item |
| 12543 | + if \tcode{SIZE_MAX / sizeof(T) < n}, throws \tcode{length_error}, |
| 12544 | +\item |
| 12545 | + otherwise equivalent to: |
| 12546 | +\begin{codeblock} |
| 12547 | +return static_cast<T*>(allocate_bytes(n*sizeof(T), alignof(T))); |
| 12548 | +\end{codeblock} |
| 12549 | +\end{itemize} |
| 12550 | + |
| 12551 | +\pnum |
| 12552 | +\begin{note} |
| 12553 | +\tcode{T} is not deduced and must therefore be provided as a template argument. |
| 12554 | +\end{note} |
| 12555 | +\end{itemdescr} |
| 12556 | + |
| 12557 | +\indexlibrarymember{deallocate_object}{polymorphic_allocator}% |
| 12558 | +\begin{itemdecl} |
| 12559 | +template <class T> |
| 12560 | + void deallocate_object(T* p, size_t n = 1); |
| 12561 | +\end{itemdecl} |
| 12562 | + |
| 12563 | +\begin{itemdescr} |
| 12564 | +\pnum |
| 12565 | +\effects |
| 12566 | +Equivalent to \tcode{deallocate_bytes(p, n*sizeof(T), alignof(T))}. |
| 12567 | +\end{itemdescr} |
| 12568 | + |
| 12569 | +\indexlibrarymember{new_object}{polymorphic_allocator}% |
| 12570 | +\begin{itemdecl} |
| 12571 | +template <class T, class CtorArgs...> |
| 12572 | + T* new_object(CtorArgs&&... ctor_args); |
| 12573 | +\end{itemdecl} |
| 12574 | + |
| 12575 | +\begin{itemdescr} |
| 12576 | +\pnum |
| 12577 | +\effects |
| 12578 | +Allocates and constructs an object of type \tcode{T}, as follows.\newline |
| 12579 | +Equivalent to: |
| 12580 | +\begin{codeblock} |
| 12581 | +T* p = allocate_object<T>(); |
| 12582 | +try { |
| 12583 | + construct(p, std::forward<CtorArgs>(ctor_args)...); |
| 12584 | +} catch (...) { |
| 12585 | + deallocate_object(p); |
| 12586 | + throw; |
| 12587 | +} |
| 12588 | +return p; |
| 12589 | +\end{codeblock} |
| 12590 | + |
| 12591 | +\pnum |
| 12592 | +\begin{note} |
| 12593 | +\tcode{T} is not deduced and must therefore be provided as a template argument. |
| 12594 | +\end{note} |
| 12595 | +\end{itemdescr} |
| 12596 | + |
| 12597 | +\indexlibrarymember{new_object}{polymorphic_allocator}% |
| 12598 | +\begin{itemdecl} |
| 12599 | +template <class T> |
| 12600 | + void delete_object(T* p); |
| 12601 | +\end{itemdecl} |
| 12602 | + |
| 12603 | +\begin{itemdescr} |
| 12604 | +\pnum |
| 12605 | +\effects |
| 12606 | +Equivalent to: |
| 12607 | +\begin{codeblock} |
| 12608 | +destroy(p); |
| 12609 | +deallocate_object(p); |
| 12610 | +\end{codeblock} |
| 12611 | +\end{itemdescr} |
| 12612 | + |
12493 | 12613 | \indexlibrarymember{construct}{polymorphic_allocator}%
|
12494 | 12614 | \begin{itemdecl}
|
12495 | 12615 | template<class T, class... Args>
|
|
0 commit comments