|
6897 | 6897 | // \ref{allocator.traits}, allocator traits
|
6898 | 6898 | template<class Alloc> struct allocator_traits;
|
6899 | 6899 |
|
| 6900 | + template<class Pointer> |
| 6901 | + struct allocation_result { |
| 6902 | + Pointer ptr; |
| 6903 | + size_t count; |
| 6904 | + }; |
| 6905 | + |
| 6906 | + template<class Allocator> |
| 6907 | + [[nodiscard] constexpr allocation_result<typename allocator_traits<Allocator>::pointer> |
| 6908 | + allocate_at_least(Allocator& a, size_t n); |
| 6909 | + |
6900 | 6910 | // \ref{default.allocator}, the default allocator
|
6901 | 6911 | template<class T> class allocator;
|
6902 | 6912 | template<class T, class U>
|
|
8136 | 8146 | well-formed; otherwise, \tcode{rhs}.
|
8137 | 8147 | \end{itemdescr}
|
8138 | 8148 |
|
| 8149 | +\rSec3[allocator.traits.other]{Other} |
| 8150 | + |
| 8151 | +\pnum |
| 8152 | +The class template \tcode{allocation_result} has |
| 8153 | +the template parameters, data members, and special members specified above. |
| 8154 | +It has no base classes or members other than those specified. |
| 8155 | + |
| 8156 | +\begin{itemdecl} |
| 8157 | +template<class Allocator> |
| 8158 | +[[nodiscard]] constexpr allocation_result<typename allocator_traits<Allocator>::pointer> |
| 8159 | + allocate_at_least(Allocator& a, size_t n); |
| 8160 | +\end{itemdecl} |
| 8161 | + |
| 8162 | +\begin{itemdescr} |
| 8163 | +\pnum |
| 8164 | +\returns |
| 8165 | +\tcode{a.allocate_at_least(n)} if that expression is well-formed; |
| 8166 | +otherwise, \tcode{\{a.allocate(n), n\}}. |
| 8167 | +\end{itemdescr} |
| 8168 | + |
8139 | 8169 | \rSec2[default.allocator]{The default allocator}
|
8140 | 8170 |
|
8141 | 8171 | \rSec3[default.allocator.general]{General}
|
|
8167 | 8197 | constexpr allocator& operator=(const allocator&) = default;
|
8168 | 8198 |
|
8169 | 8199 | [[nodiscard]] constexpr T* allocate(size_t n);
|
| 8200 | + [[nodiscard]] constexpr allocation_result<T*> allocate_at_least(size_t n); |
8170 | 8201 | constexpr void deallocate(T* p, size_t n);
|
8171 | 8202 | };
|
8172 | 8203 | }
|
|
8215 | 8246 | but not that of any of the array elements.
|
8216 | 8247 | \end{itemdescr}
|
8217 | 8248 |
|
| 8249 | +\indexlibrarymember{allocate_at_least}{allocator}% |
| 8250 | +\begin{itemdecl} |
| 8251 | +[[nodiscard]] constexpr allocation_result<T*> allocate_at_least(size_t n); |
| 8252 | +\end{itemdecl} |
| 8253 | + |
| 8254 | +\begin{itemdescr} |
| 8255 | +\pnum |
| 8256 | +\mandates |
| 8257 | +\tcode{T} is not an incomplete type\iref{basic.types}. |
| 8258 | + |
| 8259 | +\pnum |
| 8260 | +\returns |
| 8261 | +\tcode{allocation_result<T*>\{ptr, count\}}, |
| 8262 | +where \tcode{ptr} is a pointer to |
| 8263 | +the initial element of an array of \tcode{count} \tcode{T} and |
| 8264 | +$\tcode{count} \geq \tcode{n}$. |
| 8265 | + |
| 8266 | +\pnum |
| 8267 | +\throws |
| 8268 | +\tcode{bad_array_new_length} |
| 8269 | +if $\tcode{numeric_limits<size_t>::max() / sizeof(T)} < \tcode{n}$, |
| 8270 | +or \tcode{bad_alloc} if the storage cannot be obtained. |
| 8271 | + |
| 8272 | +\pnum |
| 8273 | +\remarks |
| 8274 | +The storage for the array is obtained by calling \tcode{::operator new}, |
| 8275 | +but it is unspecified when or how often this function is called. |
| 8276 | +This function starts the lifetime of the array object, |
| 8277 | +but not that of any of the array elements. |
| 8278 | +\end{itemdescr} |
| 8279 | + |
8218 | 8280 | \indexlibrarymember{deallocate}{allocator}%
|
8219 | 8281 | \begin{itemdecl}
|
8220 | 8282 | constexpr void deallocate(T* p, size_t n);
|
|
8223 | 8285 | \begin{itemdescr}
|
8224 | 8286 | \pnum
|
8225 | 8287 | \expects
|
8226 |
| -\tcode{p} is a pointer value obtained from \tcode{allocate()}. |
| 8288 | +\begin{itemize} |
| 8289 | +\item |
| 8290 | +If \tcode{p} is memory that was obtained by a call to \tcode{allocate_at_least}, |
| 8291 | +let \tcode{ret} be the value returned and |
| 8292 | +\tcode{req} be the value passed as the first argument to that call. |
| 8293 | +\tcode{p} is equal to \tcode{ret.ptr} and |
| 8294 | +\tcode{n} is a value such that $\tcode{req} \leq \tcode{n} \leq \tcode{ret.count}$. |
| 8295 | +\item |
| 8296 | +Otherwise, \tcode{p} is a pointer value obtained from \tcode{allocate}. |
8227 | 8297 | \tcode{n} equals the value passed as the first argument
|
8228 |
| -to the invocation of allocate which returned \tcode{p}. |
| 8298 | +to the invocation of \tcode{allocate} which returned \tcode{p}. |
| 8299 | +\end{itemize} |
8229 | 8300 |
|
8230 | 8301 | \pnum
|
8231 | 8302 | \effects
|
|
0 commit comments