BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslma_bslallocator.h
Go to the documentation of this file.
1/// @file bslma_bslallocator.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslma_bslallocator.h -*-C++-*-
8#ifndef INCLUDED_BSLMA_BSLALLOCATOR
9#define INCLUDED_BSLMA_BSLALLOCATOR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslma_bslallocator bslma_bslallocator
15/// @brief Provide an STL-compatible proxy for `bslma::Allocator` objects.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslma
19/// @{
20/// @addtogroup bslma_bslallocator
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslma_bslallocator-purpose"> Purpose</a>
25/// * <a href="#bslma_bslallocator-classes"> Classes </a>
26/// * <a href="#bslma_bslallocator-canonical-header"> Canonical Header </a>
27/// * <a href="#bslma_bslallocator-description"> Description </a>
28/// * <a href="#bslma_bslallocator-relationship-to-bsl-polymorphic_allocator"> Relationship to bsl::polymorphic_allocator </a>
29/// * <a href="#bslma_bslallocator-c-03-restrictions-on-allocator-usage"> C++03 Restrictions on Allocator Usage </a>
30/// * <a href="#bslma_bslallocator-thread-safety"> Thread Safety </a>
31/// * <a href="#bslma_bslallocator-usage"> Usage </a>
32/// * <a href="#bslma_bslallocator-example-1-a-fixed-size-array"> Example 1: A fixed size array </a>
33/// * <a href="#bslma_bslallocator-example-2-propagation-of-the-allocator-to-elements"> Example 2: Propagation of the Allocator to Elements </a>
34///
35/// # Purpose {#bslma_bslallocator-purpose}
36/// Provide an STL-compatible proxy for `bslma::Allocator` objects.
37///
38/// # Classes {#bslma_bslallocator-classes}
39///
40/// - bsl::allocator: STL-compatible allocator template
41/// - bsl::allocator_traits<bsl::allocator>: specialization for `bsl::allocator`
42///
43/// # Canonical Header {#bslma_bslallocator-canonical-header}
44/// bsl_memory.h
45///
46/// @see bslma_allocator
47///
48/// # Description {#bslma_bslallocator-description}
49/// This component provides an STL-compatible proxy for any
50/// allocator class derived from `bslma::Allocator`. The proxy class,
51/// `bsl::allocator` is a template that adheres to the allocator requirements
52/// defined in section 20.5.3.5 [allocator.requirements] of the C++17 standard.
53/// `bsl::allocator` may be used to instantiate any class template that is
54/// parameterized by a standard allocator. The container is expected to
55/// allocate memory for its own use through the allocator. The `bsl::allocator`
56/// object holds a pointer to an object (the allocation *mechanism*) of class
57/// type derived from `bslma::Allocator`. Different mechanism types allocate
58/// memory in different ways or from different pools, so this approach gives the
59/// programmer run time control over how the container obtains memory.
60///
61/// The `bsl::allocator` template is intended to solve a problem created by the
62/// C++ standard allocator protocol. In STL, the allocator type is specified at
63/// compile time as a container template parameter, so the allocation mechanism
64/// becomes an explicit part of the resulting container type. Two containers
65/// cannot have the same type unless they are instantiated with the same
66/// allocator type. The `bsl::allocator` template breaks the connection between
67/// the *compile-time* allocator type and the *run-time* allocation mechanism.
68/// The allocation mechanism is chosen at run-time by *initializing* (contrast
69/// with *instantiating*) the `bsl::allocator` with a pointer to a *mechanism*
70/// *object* derived from `bslma::Allocator`. Each class derived from
71/// `bslma::Allocator` implements a specific allocation mechanism and is thus
72/// called a *mechanism* *class* within this component. The `bsl::allocator`
73/// object forwards calls made through the standard allocator interface to the
74/// mechanism object with which it was initialized. In this way, two containers
75/// instantiated with `bsl::allocator` can use different allocation mechanisms
76/// even though they have the same compile-time type. The default mechanism
77/// object, if none is supplied to the `bsl::allocator` constructor, is
78/// `bslma::Default::defaultAllocator()`.
79///
80/// A container constructs its elements by calling the `construct` method on its
81/// allocator. Importantly, `bsl::allocator` is a *scoped* *allocator* -- when
82/// its `construct` method is called, the allocator passes itself to the
83/// constructor of the object being constructed (if that object is allocator
84/// aware (AA) and uses a compatible allocator type). Thus, a container
85/// instantiated with a scoped allocator ensures that its elements use the same
86/// allocator as the container itself. The `bsl::allocator::construct` method
87/// will propagate the allocator not only to element types that use
88/// `bsl::allocator`, but also to any types that use `bslma::Allocator *` --
89/// i.e., all type for which the `bslma::UsesBslmaAllocator` trait is true.
90///
91/// A container using `bsl::allocator` should not copy its allocator on
92/// assignment and thus assignment of `bsl::allocator` objects is almost always
93/// incorrect. Its base class, `bsl::polymorphic_allocator`, is not assignable,
94/// in fact but, for compatibility with some existing code, assignment of
95/// `bsl::allocator` must compile, but it is a precondition violation if the
96/// allocators being assigned are not already equal at run time (i.e., when
97/// assignment is a a no-op). The assignment operator is deprecated and might
98/// be removed in the future, once all existing uses have been excised.
99///
100/// Instantiations of `bsl::allocator` have reference semantics. A
101/// `bsl::allocator` object does not "own" the `bslma::Allocator` with which it
102/// is initialized; copying a `bsl::allocator` object does not copy its
103/// mechanism object and destroying a `bsl::allocator` does not destroy its
104/// mechanism object. Two `bsl::allocator` objects compare equal if and only if
105/// the mechanism objects they refer to compare equal.
106///
107/// ## Relationship to bsl::polymorphic_allocator {#bslma_bslallocator-relationship-to-bsl-polymorphic_allocator}
108///
109///
110/// The `bsl::allocator` class template was the inspiration for the C++17
111/// `std::pmr::polymorphic_allocator` class template (section 23.12.3,
112/// [mem.poly.allocator.class] in the C++17 Standard) and `bslma::Allocator` was
113/// the inspiration for the C++17 `std::pmr::memory_resource` (section 23.12.2,
114/// mem.res.class] in the C++17 Standard). For compatibility with the C++17
115/// standard, `bsl::allocator` is derived from `bsl::polymorphic_allocator`
116/// which, when using a C++17 library, is identical to
117/// `std::pmr::polymorphic_allocator`. Similarly, `bslma::Allocator` is derived
118/// from `bsl::memory_resource`, which is identical to
119/// `std::pmr::memory_resource`. These inheritance relationships ensure that a
120/// `bsl::allocator` instance can be passed to any type that is instantiated
121/// with a `std::pmr::polymorphic_allocator`, including `pmr` containers from
122/// the platform library. Similarly, a pointer to `bslma::Allocator` is
123/// implicitly convertible to both `std::pmr::memory_resource *` and
124/// `std::pmr::polymorphic_allocator`.
125///
126/// ## C++03 Restrictions on Allocator Usage {#bslma_bslallocator-c-03-restrictions-on-allocator-usage}
127///
128///
129/// The allocator requirements section of the C++03 standard (section 20.1.5
130/// [lib.allocator.requirements]) permits containers to assume that two
131/// allocators of the same type always compare equal, effectively limiting C++03
132/// to stateless allocators. This assumption is incorrect for instantiations of
133/// `bsl::allocator`. Therefore, for a container (or other facility) to use
134/// `bsl::allocator`, it must operate correctly in the presence of non-equal
135/// `bsl::allocator` objects. In practice, this means that a container cannot
136/// transfer ownership of allocated memory to another container unless the two
137/// containers use equal allocators. Older third-party templates that assume
138/// stateless allocators might not work correctly when instantiated with
139/// `bsl::allocator`.
140///
141/// ## Thread Safety {#bslma_bslallocator-thread-safety}
142///
143///
144/// Because it is immutable, non-assignable, and has reference semantics, a
145/// single `bsl::allocator` object is safe for concurrent access by multiple
146/// threads if and only if the `bslma::Allocator` it references is safe for
147/// concurrent access from multiple threads. Separate objects of
148/// `bsl::allocator` type may safely be used in separate threads if and only if
149/// the `bslma::Allocator` objects they reference are, themselves, safe for
150/// concurrent access.
151///
152/// ## Usage {#bslma_bslallocator-usage}
153///
154///
155/// This section illustrates intended use of this component.
156///
157/// ### Example 1: A fixed size array {#bslma_bslallocator-example-1-a-fixed-size-array}
158///
159///
160/// We first show how to define a container type parameterized with an STL-style
161/// allocator template parameter. To avoid issues concerning reallocation,
162/// dynamic growth, etc., we choose an array whose size is fixed at
163/// construction. Our array will accept any STL-compatible allocator; we do not
164/// assume as scoped allocator, which would dictate that we pass the allocator
165/// through to the parameterized `T` contained type (see the @ref bslma_allocator
166/// component and @ref bslma_constructionutil package).
167///
168/// We begin by defining member variables to hold the allocator, length, and
169/// allocated array:
170/// @code
171/// /// This class provides an array of (the template parameter) `TYPE` of
172/// /// fixed length as determined at construction time, using an instance
173/// /// of (the template parameter) `ALLOC` type to supply memory.
174/// template <class TYPE, class ALLOC>
175/// class my_FixedSizeArray {
176///
177/// // DATA
178/// ALLOC d_allocator;
179/// int d_length;
180/// TYPE *d_array;
181/// @endcode
182/// Then, we define the public interface:
183/// @code
184/// public:
185/// // TYPES
186/// typedef ALLOC allocator_type;
187/// typedef TYPE value_type;
188///
189/// // CREATORS
190///
191/// /// Create a fixed-size array of the specified `length`, using the
192/// /// optionally specified `allocator` to supply memory. If
193/// /// `allocator` is not specified, a default-constructed instance of
194/// /// the parameterized `ALLOC` type is used. All the elements in the
195/// /// resulting array are default-constructed.
196/// explicit my_FixedSizeArray(int length,
197/// const ALLOC& allocator = ALLOC());
198///
199/// /// Create a copy of the specified `original` fixed-size array,
200/// /// using the optionally specified `allocator` to supply memory. If
201/// /// `allocator` is not specified, a default-constructed instance of
202/// /// the parameterized `ALLOC` type is used.
203/// my_FixedSizeArray(const my_FixedSizeArray& original,
204/// const ALLOC& allocator = ALLOC());
205///
206/// /// Destroy this fixed size array.
207/// ~my_FixedSizeArray();
208///
209/// // MANIPULATORS
210///
211/// /// Assign to this array the value of the specified `original`
212/// /// array. Note that the length of this array might change.
213/// my_FixedSizeArray& operator=(const my_FixedSizeArray& original);
214///
215/// /// Return a reference to the modifiable element at the specified
216/// /// `index` position in this fixed size array. The behavior is
217/// /// undefined unless `index` is non-negative and less than
218/// /// `length()`.
219/// TYPE& operator[](int index) { return d_array[index]; }
220///
221/// // ACCESSORS
222///
223/// /// Return a reference to the non-modifiable element at the
224/// /// specified `index` position in this fixed size array. The
225/// /// behavior is undefined unless `index` is non-negative and less
226/// /// than `length()`.
227/// const TYPE& operator[](int index) const { return d_array[index]; }
228///
229/// /// Return the allocator used by this fixed size array to supply
230/// /// memory.
231/// allocator_type get_allocator() const { return d_allocator; }
232///
233/// /// Return the length specified at construction of this fixed size
234/// /// array.
235/// int length() const { return d_length; }
236/// };
237///
238/// // FREE OPERATORS
239///
240/// /// Return `true` if the specified `lhs` fixed-size array has the same
241/// /// value as the specified `rhs` fixed-size array, and `false`
242/// /// otherwise. Two fixed-size arrays have the same value if they have
243/// /// the same length and if the element at any index in `lhs` has the
244/// /// same value as the corresponding element at the same index in `rhs`.
245/// template<class TYPE, class ALLOC>
246/// bool operator==(const my_FixedSizeArray<TYPE, ALLOC>& lhs,
247/// const my_FixedSizeArray<TYPE, ALLOC>& rhs);
248///
249/// /// Return `true` if the specified `lhs` fixed-size array does not have
250/// /// the same value as the specified `rhs` fixed-size array, and `false`
251/// /// otherwise. Two fixed-size arrays have the same value if they have
252/// /// the same length and if the element at any index in `lhs` has the
253/// /// same value as the corresponding element at the same index in `rhs`.
254/// template<class TYPE, class ALLOC>
255/// bool operator!=(const my_FixedSizeArray<TYPE, ALLOC>& lhs,
256/// const my_FixedSizeArray<TYPE, ALLOC>& rhs);
257/// @endcode
258/// Next, we define the first constructor, which uses the allocator's `allocate`
259/// memory to obtain memory, then uses its `construct` method to construct each
260/// element. To provide a uniform and future-proof interface, the standard way
261/// to call `allocate` and `construct` is indrectly though
262/// `bsl::allocator_traits`. If `ALLOC` is a `bsl::allocator` object, then the
263/// `construct` method will attempt to pass the allocator to the constructed
264/// elements. Note that exception safety has been sacrificed for simplicity of
265/// presentation; a production version of `my_FixedSizeArray` would need to
266/// unwind any constructed elements and the allocation if an exception were
267/// thrown.
268/// @code
269/// #include <bslma_allocatortraits.h>
270///
271/// // CREATORS
272/// template<class TYPE, class ALLOC>
273/// my_FixedSizeArray<TYPE, ALLOC>::my_FixedSizeArray(int length,
274/// const ALLOC& allocator)
275/// : d_allocator(allocator), d_length(length)
276/// {
277/// typedef bsl::allocator_traits<ALLOC> Traits;
278///
279/// d_array = Traits::allocate(d_allocator, d_length);
280///
281/// // Default construct each element of the array:
282/// for (int i = 0; i < d_length; ++i) {
283/// Traits::construct(d_allocator, &d_array[i]);
284/// }
285/// }
286/// @endcode
287/// Next, we define the copy constructor, which initializes the allocator member
288/// but defers the rest of the work to the assignment operator:
289/// @code
290/// template<class TYPE, class ALLOC>
291/// my_FixedSizeArray<TYPE, ALLOC>::my_FixedSizeArray(
292/// const my_FixedSizeArray& original,
293/// const ALLOC& allocator)
294/// : d_allocator(allocator), d_length(0), d_array(0)
295/// {
296/// *this = original;
297/// }
298/// @endcode
299/// Now we define the assignment operator, which allocates the array and copies
300/// elements from the `rhs` array. Note, again, that we simplified the code by
301/// omitting exception-safety constructs.
302/// @code
303/// template<class TYPE, class ALLOC>
304/// my_FixedSizeArray<TYPE, ALLOC>&
305/// my_FixedSizeArray<TYPE, ALLOC>::operator=(const my_FixedSizeArray& rhs)
306/// {
307/// typedef bsl::allocator_traits<ALLOC> Traits;
308///
309/// if (this != &rhs) {
310/// // Call destructor for each old element
311/// for (int i = 0; i < d_length; ++i) {
312/// Traits::destroy(d_allocator, &d_array[i]);
313/// }
314///
315/// // Deallocate old storage
316/// Traits::deallocate(d_allocator, d_array, d_length);
317///
318/// // Set length and allocate new array. Do not assign the allocator!
319/// d_length = rhs.d_length;
320/// d_array = Traits::allocate(d_allocator, d_length);
321///
322/// // Construct each element of the `lhs` array from the corresponding
323/// // `rhs` element.
324/// for (int i = 0; i < d_length; ++i) {
325/// Traits::construct(d_allocator, &d_array[i], rhs.d_array[i]);
326/// }
327/// }
328///
329/// return *this; // RETURN
330/// }
331/// @endcode
332/// Next, we define the destructor, which uses the allocator's `destroy` method
333/// to destroy each element, then the allocator's `deallocate` method to return
334/// memory to the allocator:
335/// @code
336/// template<class TYPE, class ALLOC>
337/// my_FixedSizeArray<TYPE, ALLOC>::~my_FixedSizeArray()
338/// {
339/// typedef bsl::allocator_traits<ALLOC> Traits;
340///
341/// // Call destructor for each element
342/// for (int i = 0; i < d_length; ++i) {
343/// Traits::destroy(d_allocator, &d_array[i]);
344/// }
345///
346/// // Return memory to allocator.
347/// Traits::deallocate(d_allocator, d_array, d_length);
348/// }
349/// @endcode
350/// The equality and inequality operators simply compare the lengths and element
351/// values of the two arrays:
352/// @code
353/// // FREE OPERATORS
354/// template<class TYPE, class ALLOC>
355/// bool operator==(const my_FixedSizeArray<TYPE, ALLOC>& lhs,
356/// const my_FixedSizeArray<TYPE, ALLOC>& rhs)
357/// {
358/// if (lhs.length() != rhs.length()) {
359/// return false; // RETURN
360/// }
361/// for (int i = 0; i < lhs.length(); ++i) {
362/// if (lhs[i] != rhs[i]) {
363/// return false; // RETURN
364/// }
365/// }
366/// return true;
367/// }
368///
369/// template<class TYPE, class ALLOC>
370/// inline
371/// bool operator!=(const my_FixedSizeArray<TYPE, ALLOC>& lhs,
372/// const my_FixedSizeArray<TYPE, ALLOC>& rhs) {
373/// return ! (lhs == rhs);
374/// }
375/// @endcode
376/// Now we can create array objects with different allocator mechanisms. First
377/// we create an array, `a1`, using the default allocator and fill it with the
378/// values `1 .. 5`:
379/// @code
380/// #include <bslma_bslallocator.h>
381/// #include <bslma_testallocator.h>
382///
383/// int main() {
384///
385/// my_FixedSizeArray<int, bsl::allocator<int> > a1(5);
386/// assert(5 == a1.length());
387/// assert(bslma::Default::defaultAllocator() == a1.get_allocator());
388///
389/// for (int i = 0; i < a1.length(); ++i) {
390/// a1[i] = i + 1;
391/// }
392/// @endcode
393/// Finally, we create a copy of `a1` using a test allocator. The values of
394/// `a1` and `a2` are equal, even though they have different allocation
395/// mechanisms. We verify that the test allocator was used to allocate the new
396/// array elements:
397/// @code
398/// bslma::TestAllocator testAlloc;
399/// my_FixedSizeArray<int, bsl::allocator<int> > a2(a1, &testAlloc);
400/// assert(a1 == a2);
401/// assert(a1.get_allocator() != a2.get_allocator());
402/// assert(&testAlloc == a2.get_allocator());
403/// assert(1 == testAlloc.numBlocksInUse());
404/// }
405/// @endcode
406///
407/// ### Example 2: Propagation of the Allocator to Elements {#bslma_bslallocator-example-2-propagation-of-the-allocator-to-elements}
408///
409///
410/// In this example, we use the `FixedSizeArray` template defined in Example 1
411/// and demonstrate how `bsl::allocator` propagates itself to the elements it
412/// constructs, such that the container and its elements all use the same
413/// allocator.
414///
415/// First, we create a representative element class, `MyType`, that allocates
416/// memory using the `bslma::Allocator` protocol:
417/// @code
418/// #include <bslma_allocator.h>
419/// #include <bslma_default.h>
420/// #include <bslma_usesbslmaallocator.h>
421///
422/// class MyType {
423///
424/// bslma::Allocator *d_allocator_p;
425/// // etc.
426///
427/// public:
428/// // TRAITS
429/// BSLMF_NESTED_TRAIT_DECLARATION(MyType, bslma::UsesBslmaAllocator);
430///
431/// // CREATORS
432/// explicit MyType(bslma::Allocator* basicAlloc = 0)
433/// : d_allocator_p(bslma::Default::allocator(basicAlloc)) { /* ... */ }
434/// MyType(const MyType&, bslma::Allocator* basicAlloc = 0)
435/// : d_allocator_p(bslma::Default::allocator(basicAlloc)) { /* ... */ }
436/// // etc.
437///
438/// // ACCESSORS
439/// bslma::Allocator *allocator() const { return d_allocator_p; }
440///
441/// // etc.
442/// };
443/// @endcode
444/// Now, we instantiate `my_FixedSizeArray` using `MyType` and verify that,
445/// when we provide the address of an allocator to the constructor of the
446/// container, the same address is passed to the constructor of the container's
447/// elements:
448/// @code
449/// #include <bslmf_issame.h>
450///
451/// int main()
452/// {
453/// typedef my_FixedSizeArray<MyType, bsl::allocator<MyType> > ArrayType;
454///
455/// const int arrayLen = 7;
456///
457/// bslma::TestAllocator testAlloc;
458/// ArrayType C1(arrayLen, &testAlloc);
459/// assert((bsl::is_same<ArrayType::allocator_type,
460/// bsl::allocator<MyType> >::value));
461/// assert(C1.get_allocator() == bsl::allocator<MyType>(&testAlloc));
462/// for (int i = 0; i < arrayLen; ++i) {
463/// assert(C1[i].allocator() == &testAlloc);
464/// }
465/// @endcode
466/// Next, we copy-construct the container and verify that the copy uses the
467/// default allocator, not the allocator from the original; moreover, we verify
468/// that the elements stored in the copy also use the default allocator.
469/// @code
470/// ArrayType C2(C1);
471/// assert(C2.get_allocator() != C1.get_allocator());
472/// assert(C2.get_allocator() == bsl::allocator<MyType>());
473/// for (int i = 0; i < arrayLen; ++i) {
474/// assert(C2[i].allocator() != &testAlloc);
475/// assert(C2[i].allocator() == bslma::Default::defaultAllocator());
476/// }
477/// @endcode
478/// Finally, we create a third array using the test allocator and use assignment
479/// to give it the same value as the second array. We then verify that the
480/// assignment did not modify the allocator of the lhs array and that the
481/// elements of the resulting copy use the same allocator as the lhs array:
482/// @code
483/// bslma::TestAllocator testAlloc2;
484/// ArrayType C3(1, &testAlloc2);
485/// assert(1 == testAlloc2.numBlocksInUse());
486/// assert(1 == C3.length());
487/// assert(C3.get_allocator() == bsl::allocator<MyType>(&testAlloc2));
488/// assert(C3[0].allocator() == &testAlloc2);
489///
490/// C3 = C2; // Assignment
491/// assert(1 == testAlloc2.numBlocksInUse());
492/// assert(arrayLen == C3.length());
493/// assert(C3.get_allocator() == bsl::allocator<MyType>(&testAlloc2));
494/// for (int i = 0; i < arrayLen; ++i) {
495/// assert(C3[i].allocator() == &testAlloc2);
496/// }
497/// }
498/// @endcode
499/// @}
500/** @} */
501/** @} */
502
503/** @addtogroup bsl
504 * @{
505 */
506/** @addtogroup bslma
507 * @{
508 */
509/** @addtogroup bslma_bslallocator
510 * @{
511 */
512
513
514#include <bslscm_version.h>
515
516#include <bslma_allocator.h>
519#include <bslma_default.h>
521#include <bslma_isstdallocator.h>
524
528#include <bslmf_util.h> // 'forward(V)' for C++03
529
530#include <bsls_annotation.h>
531#include <bsls_assert.h>
534#include <bsls_keyword.h>
535#include <bsls_platform.h>
536#include <bsls_review.h>
537#include <bsls_util.h> // `addressof`
538
539#include <cstddef>
540
541#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
542// clang-format off
543// Include version that can be compiled with C++03
544// Generated on Mon Jan 13 08:31:27 2025
545// Command line: sim_cpp11_features.pl bslma_bslallocator.h
546
547# define COMPILING_BSLMA_BSLALLOCATOR_H
549# undef COMPILING_BSLMA_BSLALLOCATOR_H
550
551// clang-format on
552#else
553
554#define BSLMA_BSLALLOCATOR_DEPRECATE_ASSIGN \
555 BSLS_DEPRECATE_FEATURE("bsl", "bsl_allocator_assign", \
556 "Do not assign allocators.")
557
558
559namespace bslma {
560
561// FORWARD DECLARATIONS
562
563/// Object type that will be placeholder for 'void'
564struct BslAllocator_Voidish;
565
566} // close package namespace
567
568
569namespace bsl {
570
571 // ===============
572 // class allocator
573 // ===============
574
575/// An STL-compatible allocator that forwards allocation calls to an
576/// underlying mechanism object of a type derived from `bslma::Allocator`.
577/// This class template adheres to the allocator requirements defined in
578/// section [allocator.requirements] and implements a superset of the
579/// `std::pmr::polymorphic_allocator` class template described in section
580/// [mem.poly.allocator.class] of the C++ standard and may be used to
581/// instantiate any [container] class template that follows the STL
582/// allocator protocol. The allocation mechanism is chosen at run-time,
583/// giving the programmer run-time control over how a container allocates
584/// and frees memory.
585///
586/// See @ref bslma_bslallocator
587template <class TYPE = polymorphic_allocator<>::value_type>
588class allocator : public polymorphic_allocator<TYPE> {
589
590 // PRIVATE TYPES
593
594 public:
595 // TRAITS
596 // Note that `allocator` is not trivially copyable because its assignment
597 // operator is not trivial.
599 BloombergLP::bslmf::IsBitwiseCopyable);
601 BloombergLP::bslmf::IsBitwiseEqualityComparable);
602
603 // PUBLIC TYPES
604 typedef TYPE value_type;
609 typedef typename BaseTraits::pointer pointer;
613
614 /// This nested `struct` template, parameterized by `ANY_TYPE`, provides
615 /// a namespace for an `other` type alias, which is this template instantiated with `ANY_TYPE` instead of `TYPE`.
616 ///
617 /// \note Note that this
618 /// allocator type is convertible to and from `other` for any type,
619 /// including `void`.
620 ///
621 /// See @ref bslma_bslallocator
622 template <class ANY_TYPE>
623 struct rebind {
624
626 };
627
628 // CREATORS
629
630 /// Create an allocator that will forward allocation calls to the
631 /// object pointed to by `bslma::Default::defaultAllocator()`.
632 /// Postcondition:
633 /// @code
634 /// this->mechanism() == bslma::Default::defaultAllocator()
635 /// @endcode
637
638 /// Convert a `bslma::Allocator` pointer to an `allocator` object that
639 /// forwards allocation calls to the object pointed to by the specified
640 /// `mechanism`. If `mechanism` is 0, then the currently installed
641 /// default allocator is used instead. Postcondition:
642 /// @code
643 /// this->mechanism() == bslma::Default::allocator(mechanism)
644 /// @endcode
645 allocator(BloombergLP::bslma::Allocator *mechanism); // IMPLICIT
646
647#ifdef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
648 allocator(const allocator& original) BSLS_KEYWORD_NOEXCEPT = default;
649#else
651#endif
652 /// Create an allocator sharing the same mechanism object as the
653 /// specified `original`. The newly constructed allocator will compare
654 /// equal to `original`, even though they may be instantiated on
655 /// different types. Postconditions:
656 /// @code
657 /// *this == original
658 /// this->mechanism() == original.mechanism()
659 /// @endcode
660 template <class ANY_TYPE>
662
663 /// Destroy this object.
664 /// \note Note that this destructor does not delete the
665 /// object pointed to by `mechanism()`.
666 ~allocator() = default;
667
668 // MANIPULATORS
670 /// Modify this allocator to use the same mechanism as the specified `rhs`
671 /// allocator and return a modifiable reference to this object.
672 ///
673 /// \note Note that `bsl::allocator` objects should never be assigned at runtime, but, in
674 /// the absence of `if constexpr`, such assignments can sometimes be found
675 /// legitimately in dead branches (branches that are never taken at
676 /// runtime) within function templates; ideally, such code would be
677 /// replaced by more sophisticated metaprogramming that avoided calls to
678 /// this operator entirely. Invoking this assignment will result in a
679 /// review error unless `rhs == *this`, i.e., when the assignment would be
680 /// a no-op. In the future, the review error may be replaced with an a
681 /// hard assertion failure.
682 ///
683 /// @deprecated `bsl::allocator` should not be assigned.
685
686 /// Return a block of memory having sufficient size and alignment to
687 /// hold the specified `n` objects of `value_type`, allocated from the
688 /// memory resource held by this allocator. Optionally specify a
689 /// `hint`, which is ignored by this allocator type but theoretically
690 /// used by other allocators as an aid for optimizing locality.
692 pointer allocate(size_type n, const void *hint = 0);
693
694 /// Deallocate a block of memory at the specified `p` address by
695 /// returning it to the memory resource held by this allocator.
696 /// Optionally specify the number of objects, `n`, to deallocate.
697 ///
698 /// \pre The behavior is undefined unless `p` is the address of a block
699 /// previously allocated by a call to `allocate` with the same `n` from
700 /// a copy of this allocator having the same `value_type` and not yet
701 /// deallocated.
702 void deallocate(TYPE *p, std::size_t n = 1);
703
704 /// Create a default-constructed object of (template parameter)
705 /// `ELEMENT_TYPE` at the specified `address`. If `ELEMENT_TYPE`
706 /// supports `bslma`-style allocation, this allocator passes itself to
707 /// the extended default constructor. If the constructor throws, the
708 /// memory at `address` is left in an unspecified state.
709 ///
710 /// \pre The behavior is undefined unless `address` refers to a block of sufficient size
711 /// and properly aligned for objects of `ELEMENT_TYPE`.
712 template <class ELEMENT_TYPE>
713 void construct(ELEMENT_TYPE *address);
714
715#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES // $var-args=14
716
717 /// Create an object of (template parameter) `ELEMENT_TYPE` at the
718 /// specified `address`, constructed by forwarding the specified
719 /// `argument1` and the (variable number of) additional specified
720 /// `arguments` to the corresponding constructor of `ELEMENT_TYPE`. If
721 /// `ELEMENT_TYPE` supports `bslma`-style allocation, this allocator
722 /// passes itself to the constructor. If
723 /// the constructor throws, the memory at `address` is left in an unspecified state.
724 ///
725 /// \note Note that, in C++03, perfect forwarding is
726 /// limited such that any lvalue reference in the `arguments` parameter
727 /// pack is const-qualified when forwarded to the `ELEMENT_TYPE`
728 /// constructor; only `argument1` can be forwarded as an unqualified lvalue.
729 ///
730 /// \pre The behavior is undefined unless `address` refers to a
731 /// block of sufficient size and properly aligned for objects of
732 /// `ELEMENT_TYPE`.
733 template <class ELEMENT_TYPE, class ARG1, class... ARGS>
734 void construct(ELEMENT_TYPE *address,
735 ARG1& argument1,
736 ARGS&&... arguments);
737 template <class ELEMENT_TYPE, class ARG1, class... ARGS>
738 void construct(ELEMENT_TYPE *address,
739 BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1,
740 ARGS&&... arguments);
741#endif
742
743 /// Call the `TYPE` destructor for the object pointed to by the
744 /// specified `address`. Do not directly deallocate any memory.
745 template <class ELEMENT_TYPE>
746 void destroy(ELEMENT_TYPE *address);
747
748 // ACCESSORS
749
750 /// Return the address of the object referred to by the specified `x`
751 /// reference, even if the (template parameter) `TYPE` overloads the
752 /// unary `operator&`.
755
756 /// Return the maximum number of elements of (template parameter) `TYPE` that can be allocated using this allocator.
757 ///
758 /// \note Note that there is no
759 /// guarantee that attempts at allocating fewer elements than the value
760 /// returned by @ref max_size will not throw.
763
764 /// Return a pointer to the mechanism object to which this proxy
765 /// forwards allocation and deallocation calls.
766 BloombergLP::bslma::Allocator *mechanism() const;
767
768 /// Return a default-constructed allocator.
770};
771
772 // =====================
773 // class allocator<void>
774 // =====================
775
776/// Specialization of `allocator<T>` where `T` is `void`. Does not contain members that are unrepresentable for `void`.
777///
778/// \note Note that this
779/// specialization may be removed in the future. Use `allocator<>` or
780/// `allocator<char>` instead.
781template <>
782class allocator<void>
783 : public allocator<BloombergLP::bslma::BslAllocator_Voidish>
784{
785
786 // PRIVATE TYPES
788
789 // NOT DEFINED
790 void allocate(); // Hide name inherited from base class
791 void deallocate(); // Hide name inherited from base class
792 void construct(); // Hide name inherited from base class
793 void destroy(); // Hide name inherited from base class
794 void max_size(int); // Hide name inherited from base class
795
796 public:
797 // TRAITS
798 // Note that `allocator` is not trivially copyable because its assignment
799 // operator is not trivial.
801 BloombergLP::bslmf::IsBitwiseCopyable);
803 BloombergLP::bslmf::IsBitwiseEqualityComparable);
804
805 // PUBLIC TYPES
806 typedef void *pointer;
807 typedef const void *const_pointer;
808 typedef void *void_pointer;
809 typedef const void *const_void_pointer;
810 typedef void value_type;
811
812 // CREATORS
813
814 /// Create a proxy object that will forward allocation calls to the
815 /// object pointed to by `bslma::Default::defaultAllocator()`.
816 /// Postcondition:
817 /// @code
818 /// this->mechanism() == bslma::Default::defaultAllocator();
819 /// @endcode
820 allocator();
821
822 /// Convert a `bslma::Allocator` pointer to an `allocator` object that
823 /// forwards allocation calls to the object pointed to by the specified
824 /// `mechanism`. If `mechanism` is 0, then the currently installed
825 /// default allocator is used instead. Postcondition:
826 /// @code
827 /// this->mechanism() == bslma::Default::allocator(mechanism);
828 /// @endcode
829 allocator(BloombergLP::bslma::Allocator *mechanism); // IMPLICIT
830
831 /// Create a proxy object sharing the same mechanism object as the
832 /// specified `original`. The newly constructed allocator will compare
833 /// equal to `original`, even though they may be instantiated on
834 /// different types. Postcondition:
835 /// @code
836 /// this->mechanism() == original.mechanism();
837 /// @endcode
838#ifdef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
839 allocator(const allocator& original) BSLS_KEYWORD_NOEXCEPT = default;
840#else
842#endif
843 template <class ANY_TYPE>
845
846 /// Destroy this object.
847 /// \note Note that this does not delete the object
848 /// pointed to by `mechanism()`. Also note that this method's
849 /// definition is compiler generated.
851
852 // MANIPULATORS
853
854 /// Compiler-generated assign operator.
855 allocator& operator=(const allocator& rhs) = default;
856
857 // ACCESSORS
858
859 /// Return a default-constructed allocator.
861};
862
863 // ========================================
864 // class allocator_traits<allocator<TYPE> >
865 // ========================================
866
867/// This `struct` template provides a specialization of the
868/// `allocator_traits` class template for `bsl::allocator`. This
869/// specialization is not strictly necessary, but its presence speeds up
870/// compliation by bypassing a significant amount of metaprogramming.
871template <class TYPE>
873
874 // PUBLIC TYPES
876 typedef TYPE value_type;
877
878 typedef typename allocator_type::pointer pointer;
879 typedef typename allocator_type::const_pointer const_pointer;
880 typedef typename allocator_type::void_pointer void_pointer;
881 typedef typename allocator_type::const_void_pointer const_void_pointer;
882 typedef typename allocator_type::difference_type difference_type;
883 typedef typename allocator_type::size_type size_type;
884
885#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
886 template <class ELEMENT_TYPE>
887 using rebind_alloc = allocator<ELEMENT_TYPE>;
888
889 template <class ELEMENT_TYPE>
890 using rebind_traits = allocator_traits<allocator<ELEMENT_TYPE> >;
891#else
892 template <class ELEMENT_TYPE>
893 struct rebind_alloc : allocator<ELEMENT_TYPE> {
895 : allocator<ELEMENT_TYPE>()
896 {
897 }
898
899 // Convert from anything that can be used to cosntruct the base type.
900 // This might be better if SFINAE-ed out using `is_convertible`, but
901 // stressing older compilers more seems unwise.
902 template <typename ARG>
903 rebind_alloc(const ARG& allocatorArg)
904 : allocator<ELEMENT_TYPE>(allocatorArg)
905 {
906 }
907 };
908
909 template <class ELEMENT_TYPE>
910 struct rebind_traits : allocator_traits<allocator<ELEMENT_TYPE> > {
911 };
912#endif
913
915 {
916 return m.allocate(n);
917 }
918
920 size_type n,
921 const_void_pointer /* hint */)
922 {
923 return m.allocate(n);
924 }
925
927 {
928 m.deallocate(p, n);
929 }
930
931 template <class TYPE2>
932 static void construct(allocator_type& m,
933 TYPE2 *p)
934 {
935 m.construct(p);
936 }
937
938#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES // $var-args=14
939 template <class TYPE2, class ARG1, class... ARGS>
940 static void construct(allocator_type& m,
941 TYPE2 *p,
942 ARG1& argument1,
943 ARGS&&... arguments)
944 {
945 m.construct(p,
946 argument1,
947 BSLS_COMPILERFEATURES_FORWARD(ARGS, arguments)...);
948 }
949
950 template <class TYPE2, class ARG1, class... ARGS>
951 static void construct(allocator_type& m,
952 TYPE2 *p,
953 BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1,
954 ARGS&&... arguments)
955 {
956 m.construct(p,
957 BSLS_COMPILERFEATURES_FORWARD(ARG1, argument1),
958 BSLS_COMPILERFEATURES_FORWARD(ARGS, arguments)...);
959 }
960#endif
961
962 template <class ELEMENT_TYPE>
963 static void destroy(allocator_type& m, ELEMENT_TYPE *p)
964 {
965 m.destroy(p);
966 }
967
970 {
971 return m.max_size();
972 }
973
974 // Allocator propagation traits
975 static
980
982
984
986
988};
989
990
991// ============================================================================
992// INLINE FUNCTION DEFINITIONS
993// ============================================================================
994
995 // ---------------
996 // class allocator
997 // ---------------
998
999// CREATORS
1000template <class TYPE>
1001inline
1003: Base(BloombergLP::bslma::Default::defaultAllocator())
1004{
1005}
1006
1007template <class TYPE>
1008inline
1009allocator<TYPE>::allocator(BloombergLP::bslma::Allocator *mechanism)
1010: Base(BloombergLP::bslma::Default::allocator(mechanism))
1011{
1012}
1013
1014#ifndef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
1015// In C++11 and later, this copy constructor is defaulted.
1016template <class TYPE>
1017inline
1019: Base(original)
1020{
1021}
1022#endif
1023
1024template <class TYPE>
1025template <class ANY_TYPE>
1026inline
1029: Base(original)
1030{
1031}
1032
1033// MANIPULATORS
1034template <class TYPE>
1035inline
1038{
1039 BSLS_REVIEW_OPT(rhs == *this &&
1040 "'bsl::allocator' objects cannot be assigned");
1041
1042 if (this != &rhs) {
1043 // As the base class does not support assignment, the only way to
1044 // change the mechanism is to destroy and re-create this object
1045 this->~allocator();
1046 return *::new(this) allocator(rhs);
1047 }
1048
1049 return *this;
1050}
1051
1052template <class TYPE>
1053inline
1055allocator<TYPE>::allocate(size_type n, const void * /* hint */)
1056{
1057 return Base::allocate(n);
1058}
1059
1060template <class TYPE>
1061inline
1062void allocator<TYPE>::deallocate(TYPE *p, std::size_t n)
1063{
1064 Base::deallocate(p, n);
1065}
1066
1067template <class TYPE>
1068template <class ELEMENT_TYPE>
1069inline
1070void allocator<TYPE>::construct(ELEMENT_TYPE *address)
1071{
1072 BloombergLP::bslma::ConstructionUtil::construct(address, *this);
1073}
1074
1075#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1076template <class TYPE>
1077template <class ELEMENT_TYPE, class ARG1, class... ARGS>
1078inline
1079void allocator<TYPE>::construct(ELEMENT_TYPE *address,
1080 ARG1& argument1,
1081 ARGS&&... arguments)
1082{
1083 BloombergLP::bslma::ConstructionUtil::construct(
1084 address,
1085 *this,
1086 argument1,
1087 BSLS_COMPILERFEATURES_FORWARD(ARGS, arguments)...);
1088}
1089
1090template <class TYPE>
1091template <class ELEMENT_TYPE, class ARG1, class... ARGS>
1092inline
1094 ELEMENT_TYPE *address,
1095 BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1,
1096 ARGS&&... arguments)
1097{
1098 BloombergLP::bslma::ConstructionUtil::construct(
1099 address,
1100 *this,
1101 BSLS_COMPILERFEATURES_FORWARD(ARG1, argument1),
1102 BSLS_COMPILERFEATURES_FORWARD(ARGS, arguments)...);
1103}
1104#endif
1105
1106template <class TYPE>
1107template <class ELEMENT_TYPE>
1108inline
1109void allocator<TYPE>::destroy(ELEMENT_TYPE *address)
1110{
1111 BloombergLP::bslma::DestructionUtil::destroy(address);
1112}
1113
1114
1115// ACCESSORS
1116template <class TYPE>
1117inline
1120{
1121 return BloombergLP::bsls::Util::addressOf(x);
1122}
1123
1124template <class TYPE>
1125inline
1128{
1129 return BloombergLP::bsls::Util::addressOf(x);
1130}
1131
1132template <class TYPE>
1135{
1136 // Return the largest value, `v`, such that `v * sizeof(T)` fits in a
1137 // `size_type`. Note that `~size_type(0)` is the maximum value for
1138 // `size_type`, the largest possible sequence of bytes to store `TYPE`
1139 // objects in.
1140
1141 return ~size_type(0) / sizeof(TYPE);
1142}
1143
1144template <class TYPE>
1145inline
1146BloombergLP::bslma::Allocator *allocator<TYPE>::mechanism() const
1147{
1148 return static_cast<BloombergLP::bslma::Allocator *>(this->resource());
1149}
1150
1151template <class TYPE>
1152inline
1157
1158 // ---------------------
1159 // class allocator<void>
1160 // ---------------------
1161
1162// CREATORS
1163inline
1167
1168inline
1169allocator<void>::allocator(BloombergLP::bslma::Allocator *mechanism)
1170: Base(mechanism)
1171{
1172}
1173
1174#ifndef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
1175// In C++11 and later, this copy constructor is defaulted.
1176inline
1178: Base(original)
1179{
1180}
1181#endif
1182
1183template <class ANY_TYPE>
1184inline
1187: Base(original)
1188{
1189}
1190
1191inline
1196
1197} // close namespace bsl
1198
1199#if BSLS_PLATFORM_CMP_MSVC
1200// As of MSVC 19.30.30709 (2022), the following workaround is still needed.
1201// When a fix is released, the above `#if` condition should be updated to apply
1202// only to versions before the fixed one.
1203
1204// These equality and inequality operators should be unnecessary because they
1205// automatically fall back on @ref polymoprhic_allocator . However an odd bug in
1206// MSVC causes it, in the presence of `<bslma_convertibleallocator.h>` to
1207// include the `bslma::ConvertibleAllocator` "hidden friend" equality operators
1208// in the the lookup set even if neither argument is `ConvertibleAllocator`,
1209// thus making `operator==` ambiguous when comparing `bsl::allocator` to
1210// `bslma::Allocator *`. Strangely `using namespace bslma` suppresses this
1211// bug, but it is not practical to require clients to do that. The operators
1212// below quash this ambiguity. Although harmless for other platforms, they are
1213// compiled only for affected versions of MSVC and are considered an
1214// implementation detail (not part of the interface for `bsl::allocator`).
1215
1216template <class TYPE>
1217inline
1218bool operator==(const bsl::allocator<TYPE>& a,
1219 BloombergLP::bslma::Allocator *b)
1220{
1221 return a.resource() == b || a.resource()->is_equal(*b);
1222}
1223
1224template <class TYPE>
1225inline
1226bool operator==(BloombergLP::bslma::Allocator *a,
1227 const bsl::allocator<TYPE>& b)
1228{
1229 return a == b.resource() || a->is_equal(*b.resource());
1230}
1231
1232template <class TYPE>
1233inline
1234bool operator!=(const bsl::allocator<TYPE>& a,
1235 BloombergLP::bslma::Allocator *b)
1236{
1237 return ! (a.resource() == b || a.resource()->is_equal(*b));
1238}
1239
1240template <class TYPE>
1241inline
1242bool operator!=(BloombergLP::bslma::Allocator *a,
1243 const bsl::allocator<TYPE>& b)
1244{
1245 return ! (a == b.resource() || a->is_equal(*b.resource()));
1246}
1247#endif
1248
1249// ============================================================================
1250// TYPE TRAITS
1251// ============================================================================
1252
1253
1254namespace bslma {
1255
1256/// An allocator is not *itself* an allocator-aware type, even though it is
1257/// convertible from `bsl::Allocator *`.
1258template <class TYPE>
1261
1262/// A `bsl::allocator` inherits its `allocate` method from a base class,
1263/// which causes `IsStdAllocator` to fail the auto-detected it.
1264template <class TYPE>
1265struct IsStdAllocator<bsl::allocator<TYPE> > : bsl::true_type {
1266};
1267
1268/// `bsl::allocator<void>` is not an allocator type, even though all other
1269/// instantiations are allocator types.
1270template <>
1271struct IsStdAllocator<bsl::allocator<void> > : bsl::false_type {
1272};
1273
1274} // close namespace bslma
1275
1276
1277#endif // End C++11 code
1278
1279#endif
1280
1281// ----------------------------------------------------------------------------
1282// Copyright 2013 Bloomberg Finance L.P.
1283//
1284// Licensed under the Apache License, Version 2.0 (the "License");
1285// you may not use this file except in compliance with the License.
1286// You may obtain a copy of the License at
1287//
1288// http://www.apache.org/licenses/LICENSE-2.0
1289//
1290// Unless required by applicable law or agreed to in writing, software
1291// distributed under the License is distributed on an "AS IS" BASIS,
1292// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1293// See the License for the specific language governing permissions and
1294// limitations under the License.
1295// ----------------------------- END-OF-FILE ----------------------------------
1296
1297/** @} */
1298/** @} */
1299/** @} */
void * void_pointer
Definition bslma_bslallocator.h:808
const void * const_pointer
Definition bslma_bslallocator.h:807
BSLMF_NESTED_TRAIT_DECLARATION(allocator, BloombergLP::bslmf::IsBitwiseEqualityComparable)
allocator & operator=(const allocator &rhs)=default
Compiler-generated assign operator.
BSLMF_NESTED_TRAIT_DECLARATION(allocator, BloombergLP::bslmf::IsBitwiseCopyable)
const void * const_void_pointer
Definition bslma_bslallocator.h:809
void * pointer
Definition bslma_bslallocator.h:806
void value_type
Definition bslma_bslallocator.h:810
Definition bslma_bslallocator.h:588
value_type & reference
Definition bslma_bslallocator.h:605
BloombergLP::bslma::Allocator * mechanism() const
Definition bslma_bslallocator.h:1146
void destroy(ELEMENT_TYPE *address)
Definition bslma_bslallocator.h:1109
void construct(ELEMENT_TYPE *address, ARG1 &argument1, ARGS &&... arguments)
Definition bslma_bslallocator.h:1079
BaseTraits::const_pointer const_pointer
Definition bslma_bslallocator.h:610
BSLMF_NESTED_TRAIT_DECLARATION(allocator, BloombergLP::bslmf::IsBitwiseCopyable)
TYPE value_type
Definition bslma_bslallocator.h:604
allocator(const allocator &original) BSLS_KEYWORD_NOEXCEPT
Definition bslma_bslallocator.h:1018
value_type const & const_reference
Definition bslma_bslallocator.h:606
BaseTraits::pointer pointer
Definition bslma_bslallocator.h:609
BSLMA_BSLALLOCATOR_DEPRECATE_ASSIGN allocator & operator=(const allocator &rhs)
Definition bslma_bslallocator.h:1037
void deallocate(TYPE *p, std::size_t n=1)
Definition bslma_bslallocator.h:1062
allocator(BloombergLP::bslma::Allocator *mechanism)
Definition bslma_bslallocator.h:1009
void construct(ELEMENT_TYPE *address)
Definition bslma_bslallocator.h:1070
BSLS_ANNOTATION_NODISCARD pointer allocate(size_type n, const void *hint=0)
Definition bslma_bslallocator.h:1055
const_pointer address(const_reference x) const
Definition bslma_bslallocator.h:1127
BaseTraits::void_pointer void_pointer
Definition bslma_bslallocator.h:611
pointer address(reference x) const
Definition bslma_bslallocator.h:1119
void construct(ELEMENT_TYPE *address, BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1, ARGS &&... arguments)
Definition bslma_bslallocator.h:1093
allocator select_on_container_copy_construction() const
Return a default-constructed allocator.
Definition bslma_bslallocator.h:1153
BaseTraits::const_void_pointer const_void_pointer
Definition bslma_bslallocator.h:612
~allocator()=default
allocator(const allocator< ANY_TYPE > &original) BSLS_KEYWORD_NOEXCEPT
Definition bslma_bslallocator.h:1027
BaseTraits::difference_type difference_type
Definition bslma_bslallocator.h:608
BSLMF_NESTED_TRAIT_DECLARATION(allocator, BloombergLP::bslmf::IsBitwiseEqualityComparable)
BSLS_KEYWORD_CONSTEXPR size_type max_size() const
Definition bslma_bslallocator.h:1134
allocator()
Definition bslma_bslallocator.h:1002
BaseTraits::size_type size_type
Definition bslma_bslallocator.h:607
bool is_equal(const memory_resource &other) const BSLS_KEYWORD_NOEXCEPT
Definition bslma_memoryresource.h:563
Definition bslma_polymorphicallocator.h:460
memory_resource * resource() const
Return the address of the memory resource supplied on construction.
Definition bslma_polymorphicallocator.h:1074
#define BSLMA_BSLALLOCATOR_DEPRECATE_ASSIGN
Definition bslma_bslallocator.h:554
#define BSLS_ANNOTATION_NODISCARD
Definition bsls_annotation.h:368
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:624
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_REVIEW_OPT(X)
Definition bsls_review.h:1060
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
Definition bdlat_valuetypefunctions.h:939
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
Definition baljsn_encoder_testtypes.h:76
Definition bslma_bslallocator.h:623
allocator< ANY_TYPE > other
Definition bslma_bslallocator.h:625
rebind_alloc(const ARG &allocatorArg)
Definition bslma_bslallocator.h:903
rebind_alloc()
Definition bslma_bslallocator.h:894
allocator_type::size_type size_type
Definition bslma_bslallocator.h:883
allocator_type::difference_type difference_type
Definition bslma_bslallocator.h:882
static void construct(allocator_type &m, TYPE2 *p, ARG1 &argument1, ARGS &&... arguments)
Definition bslma_bslallocator.h:940
allocator_type::void_pointer void_pointer
Definition bslma_bslallocator.h:880
allocator_type::const_void_pointer const_void_pointer
Definition bslma_bslallocator.h:881
static pointer allocate(allocator_type &m, size_type n, const_void_pointer)
Definition bslma_bslallocator.h:919
static allocator_type select_on_container_copy_construction(const allocator_type &)
Definition bslma_bslallocator.h:976
static void destroy(allocator_type &m, ELEMENT_TYPE *p)
Definition bslma_bslallocator.h:963
TYPE value_type
Definition bslma_bslallocator.h:876
false_type propagate_on_container_swap
Definition bslma_bslallocator.h:987
allocator_type::const_pointer const_pointer
Definition bslma_bslallocator.h:879
static void construct(allocator_type &m, TYPE2 *p, BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1, ARGS &&... arguments)
Definition bslma_bslallocator.h:951
static pointer allocate(allocator_type &m, size_type n)
Definition bslma_bslallocator.h:914
static void deallocate(allocator_type &m, pointer p, size_type n)
Definition bslma_bslallocator.h:926
false_type propagate_on_container_move_assignment
Definition bslma_bslallocator.h:985
static void construct(allocator_type &m, TYPE2 *p)
Definition bslma_bslallocator.h:932
false_type is_always_equal
Definition bslma_bslallocator.h:981
allocator_type::pointer pointer
Definition bslma_bslallocator.h:878
false_type propagate_on_container_copy_assignment
Definition bslma_bslallocator.h:983
static BSLS_KEYWORD_CONSTEXPR size_type max_size(const allocator_type &m)
Definition bslma_bslallocator.h:969
allocator< TYPE > allocator_type
Definition bslma_bslallocator.h:875
Definition bslma_allocatortraits.h:1089
BloombergLP::bslma::AllocatorTraits_ConstPointerType< ALLOCATOR_TYPE >::type const_pointer
Definition bslma_allocatortraits.h:1183
BloombergLP::bslma::AllocatorTraits_VoidPointerType< ALLOCATOR_TYPE >::type void_pointer
Definition bslma_allocatortraits.h:1186
BloombergLP::bslma::AllocatorTraits_SizeType< ALLOCATOR_TYPE >::type size_type
Definition bslma_allocatortraits.h:1196
BloombergLP::bslma::AllocatorTraits_PointerType< ALLOCATOR_TYPE >::type pointer
Definition bslma_allocatortraits.h:1180
ALLOCATOR_TYPE allocator_type
Definition bslma_allocatortraits.h:1175
BloombergLP::bslma::AllocatorTraits_ConstVoidPointerType< ALLOCATOR_TYPE >::type const_void_pointer
Definition bslma_allocatortraits.h:1189
BloombergLP::bslma::AllocatorTraits_DifferenceType< ALLOCATOR_TYPE >::type difference_type
Definition bslma_allocatortraits.h:1193
Definition bslmf_integralconstant.h:261
Definition bslma_isstdallocator.h:202
Definition bslma_usesbslmaallocator.h:344