Skip to content

Commit 2c41a2a

Browse files
authored
Merge 2019-02 LWG Motion 3
P0339R6 polymorphic_allocator<> as a vocabulary type Fixes #2695.
2 parents cb67ff1 + e11e27a commit 2c41a2a

File tree

2 files changed

+122
-2
lines changed

2 files changed

+122
-2
lines changed

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5068,7 +5068,7 @@
50685068
void destroy() const;
50695069

50705070
private:
5071-
void* ptr; // exposition only
5071+
void* ptr; // \expos
50725072
};
50735073

50745074
template<class Promise>

source/utilities.tex

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12369,7 +12369,7 @@
1236912369
\indexlibrarymember{value_type}{polymorphic_allocator}%
1237012370
\begin{codeblock}
1237112371
namespace std::pmr {
12372-
template<class Tp> class polymorphic_allocator {
12372+
template<class Tp = byte> class polymorphic_allocator {
1237312373
memory_resource* memory_rsrc; // \expos
1237412374

1237512375
public:
@@ -12390,6 +12390,13 @@
1239012390
[[nodiscard]] Tp* allocate(size_t n);
1239112391
void deallocate(Tp* p, size_t n);
1239212392

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+
1239312400
template<class T, class... Args>
1239412401
void construct(T* p, Args&&... args);
1239512402

@@ -12490,6 +12497,119 @@
1249012497
Nothing.
1249112498
\end{itemdescr}
1249212499

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+
1249312613
\indexlibrarymember{construct}{polymorphic_allocator}%
1249412614
\begin{itemdecl}
1249512615
template<class T, class... Args>

0 commit comments

Comments
 (0)