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