|
6885 | 6885 | // \ref{allocator.traits}, allocator traits
|
6886 | 6886 | template<class Alloc> struct allocator_traits;
|
6887 | 6887 |
|
| 6888 | + template<class Pointer> |
| 6889 | + struct allocation_result { |
| 6890 | + Pointer ptr; |
| 6891 | + size_t count; |
| 6892 | + }; |
| 6893 | + |
| 6894 | + template<class Allocator> |
| 6895 | + [[nodiscard] constexpr allocation_result<typename allocator_traits<Allocator>::pointer> |
| 6896 | + allocate_at_least(Allocator& a, size_t n); |
| 6897 | + |
6888 | 6898 | // \ref{default.allocator}, the default allocator
|
6889 | 6899 | template<class T> class allocator;
|
6890 | 6900 | template<class T, class U>
|
|
8254 | 8264 | well-formed; otherwise, \tcode{rhs}.
|
8255 | 8265 | \end{itemdescr}
|
8256 | 8266 |
|
| 8267 | +\rSec3[allocator.traits.other]{Other} |
| 8268 | + |
| 8269 | +\pnum |
| 8270 | +The class template \tcode{allocation_result} has |
| 8271 | +the template parameters, data members, and special members specified above. |
| 8272 | +It has no base classes or members other than those specified. |
| 8273 | + |
| 8274 | +\begin{itemdecl} |
| 8275 | +template<class Allocator> |
| 8276 | +[[nodiscard]] constexpr allocation_result<typename allocator_traits<Allocator>::pointer> |
| 8277 | + allocate_at_least(Allocator& a, size_t n); |
| 8278 | +\end{itemdecl} |
| 8279 | + |
| 8280 | +\begin{itemdescr} |
| 8281 | +\pnum |
| 8282 | +\returns |
| 8283 | +\tcode{a.allocate_at_least(n)} if that expression is well-formed; |
| 8284 | +otherwise, \tcode{\{a.allocate(n), n\}}. |
| 8285 | +\end{itemdescr} |
| 8286 | + |
8257 | 8287 | \rSec2[default.allocator]{The default allocator}
|
8258 | 8288 |
|
8259 | 8289 | \rSec3[default.allocator.general]{General}
|
|
8285 | 8315 | constexpr allocator& operator=(const allocator&) = default;
|
8286 | 8316 |
|
8287 | 8317 | [[nodiscard]] constexpr T* allocate(size_t n);
|
| 8318 | + [[nodiscard]] constexpr allocation_result<T*> allocate_at_least(size_t n); |
8288 | 8319 | constexpr void deallocate(T* p, size_t n);
|
8289 | 8320 | };
|
8290 | 8321 | }
|
|
8333 | 8364 | but not that of any of the array elements.
|
8334 | 8365 | \end{itemdescr}
|
8335 | 8366 |
|
| 8367 | +\indexlibrarymember{allocate_at_least}{allocator}% |
| 8368 | +\begin{itemdecl} |
| 8369 | +[[nodiscard]] constexpr allocation_result<T*> allocate_at_least(size_t n); |
| 8370 | +\end{itemdecl} |
| 8371 | + |
| 8372 | +\begin{itemdescr} |
| 8373 | +\pnum |
| 8374 | +\mandates |
| 8375 | +\tcode{T} is not an incomplete type\iref{basic.types}. |
| 8376 | + |
| 8377 | +\pnum |
| 8378 | +\returns |
| 8379 | +\tcode{allocation_result<T*>\{ptr, count\}}, |
| 8380 | +where \tcode{ptr} is a pointer to |
| 8381 | +the initial element of an array of \tcode{count} \tcode{T} and |
| 8382 | +$\tcode{count} >= \tcode{n}$. |
| 8383 | + |
| 8384 | +\pnum |
| 8385 | +\throws |
| 8386 | +\tcode{bad_array_new_length} |
| 8387 | +if $\tcode{numeric_limits<size_t>::max() / sizeof(T)} < \tcode{n}$, |
| 8388 | +or \tcode{bad_alloc} if the storage cannot be obtained. |
| 8389 | + |
| 8390 | +\pnum |
| 8391 | +\remarks |
| 8392 | +The storage for the array is obtained by calling \tcode{::operator new}, |
| 8393 | +but it is unspecified when or how often this function is called. |
| 8394 | +This function starts the lifetime of the array object, |
| 8395 | +but not that of any of the array elements. |
| 8396 | +\end{itemdescr} |
| 8397 | + |
8336 | 8398 | \indexlibrarymember{deallocate}{allocator}%
|
8337 | 8399 | \begin{itemdecl}
|
8338 | 8400 | constexpr void deallocate(T* p, size_t n);
|
|
8341 | 8403 | \begin{itemdescr}
|
8342 | 8404 | \pnum
|
8343 | 8405 | \expects
|
8344 |
| -\tcode{p} is a pointer value obtained from \tcode{allocate()}. |
| 8406 | +\begin{itemize} |
| 8407 | +\item |
| 8408 | +If \tcode{p} is memory that was obtained by a call to \tcode{allocate_at_least}, |
| 8409 | +let \tcode{ret} be the value returned and |
| 8410 | +\tcode{req} be the value passed as the first argument to that call. |
| 8411 | +\tcode{p} is equal to \tcode{ret.ptr} and |
| 8412 | +\tcode{n} is a value such that $\tcode{req} <= \tcode{n} <= \tcode{ret.count}$. |
| 8413 | +\item |
| 8414 | +Otherwise, \tcode{p} is a pointer value obtained from \tcode{allocate}. |
8345 | 8415 | \tcode{n} equals the value passed as the first argument
|
8346 |
| -to the invocation of allocate which returned \tcode{p}. |
| 8416 | +to the invocation of \tcode{allocate} which returned \tcode{p}. |
| 8417 | +\end{itemize} |
8347 | 8418 |
|
8348 | 8419 | \pnum
|
8349 | 8420 | \effects
|
|
0 commit comments