bsl::allocator

An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.

Synopsis

Declared in <bslma_bslallocator.h>

template<class TYPE = polymorphic_allocator<>::value_type>
class allocator
    : public polymorphic_allocator<TYPE>

Base Classes

NameDescription
polymorphic_allocator<TYPE>Alias for std::pmr::polymorphic_allocator in the bsl namespace.

Types

NameDescription
rebind This nested struct template, parameterized by ANY_TYPE, provides a namespace for an other type alias, which is this template instantiated with ANY_TYPE instead of TYPE. Note that this allocator type is convertible to and from other for any type, including void.

Type Aliases

NameDescription
const_pointer This typedef is an alias to BaseTraits::const_pointer.
const_reference This typedef is an alias to a constant value_type reference.
const_void_pointer This typedef is an alias to BaseTraits::const_void_pointer.
difference_type Difference type for allocations from this allocator.
pointer This typedef is an alias to BaseTraits::pointer.
reference This typedef is an alias to a modifiable value_type reference.
size_type Size type for allocations from this allocator.
value_type This typedef is an alias to the (template parameter) TYPE.
void_pointer This typedef is an alias to BaseTraits::void_pointer.

Member Functions

NameDescription
allocator [constructor]Create an allocator that will forward allocation calls to the object pointed to by bslma::Default::defaultAllocator(). Postcondition: ` this->mechanism() == bslma::Default::defaultAllocator() `
allocator [constructor]Create a copy of this allocator.
allocator [constructor]Create an allocator sharing the same mechanism object as the specified original. The newly constructed allocator will compare equal to original, even though they may be instantiated on different types. Postconditions: ` *this == original this->mechanism() == original.mechanism() `
allocator [constructor]Convert a bslma::Allocator pointer to an allocator object that forwards allocation calls to the object pointed to by the specified mechanism. If mechanism is 0, then the currently installed default allocator is used instead. Postcondition: ` this->mechanism() == bslma::Default::allocator(mechanism) `
operator= Modify this allocator to use the same mechanism as the specified rhs allocator and return a modifiable reference to this object. Note that bsl::allocator objects should never be assigned at runtime, but, in the absence of if constexpr, such assignments can sometimes be found legitimately in dead branches (branches that are never taken at runtime) within function templates; ideally, such code would be replaced by more sophisticated metaprogramming that avoided calls to this operator entirely. Invoking this assignment will result in a review error unless rhs == *this, i.e., when the assignment would be a no-op. In the future, the review error may be replaced with an a hard assertion failure.
address Return the address of the object referred to by the specified x reference, even if the (template parameter) TYPE overloads the unary operator&.
address Return the address of the object referred to by the specified x reference, even if the (template parameter) TYPE overloads the unary operator&.
allocate Return a block of memory having sufficient size and alignment to hold the specified n objects of value_type, allocated from the memory resource held by this allocator. Optionally specify a hint, which is ignored by this allocator type but theoretically used by other allocators as an aid for optimizing locality.
construct Create a default-constructed object of (template parameter) ELEMENT_TYPE at the specified address. If ELEMENT_TYPE supports bslma-style allocation, this allocator passes itself to the extended default constructor. If the constructor throws, the memory at address is left in an unspecified state. The behavior is undefined unless address refers to a block of sufficient size and properly aligned for objects of ELEMENT_TYPE.
construct Create an object of (template parameter) ELEMENT_TYPE at the specified address, constructed by forwarding the specified argument1 and the (variable number of) additional specified arguments to the corresponding constructor of ELEMENT_TYPE. If ELEMENT_TYPE supports bslma-style allocation, this allocator passes itself to the constructor. If the constructor throws, the memory at address is left in an unspecified state. Note that, in C++03, perfect forwarding is limited such that any lvalue reference in the arguments parameter pack is const-qualified when forwarded to the ELEMENT_TYPE constructor; only argument1 can be forwarded as an unqualified lvalue. The behavior is undefined unless address refers to a block of sufficient size and properly aligned for objects of ELEMENT_TYPE.
construct Same as the preceding construct overload, using perfect forwarding.
deallocate Deallocate a block of memory at the specified p address by returning it to the memory resource held by this allocator. Optionally specify the number of objects, n, to deallocate. The behavior is undefined unless p is the address of a block previously allocated by a call to allocate with the same n from a copy of this allocator having the same value_type and not yet deallocated.
destroy Call the TYPE destructor for the object pointed to by the specified address. Do not directly deallocate any memory.
max_size Return the maximum number of elements of (template parameter) TYPE that can be allocated using this allocator. Note that there is no guarantee that attempts at allocating fewer elements than the value returned by max_size will not throw.
mechanism Return a pointer to the mechanism object to which this proxy forwards allocation and deallocation calls.
select_on_container_copy_construction Return a default-constructed allocator.
operator BloombergLP::bslmf::NestedTraitDeclaration<allocator, IsBitwiseCopyable> Declare allocator as bitwise copyable.
operator BloombergLP::bslmf::NestedTraitDeclaration<allocator, IsBitwiseEqualityComparable> Declare allocator as bitwise equality comparable.

Specializations

NameDescription
allocator<Attribute> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<Json> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<ManagedAttribute> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<MetricSampleGroup> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<UserFieldValue> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<ZoneinfoTransition> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<bool> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<char> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<char16_t> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<char32_t> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<char8_t> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<double> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<float> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<int> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<long> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<long double> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<long long> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<short> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<signed char> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<unsigned char> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<unsigned int> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<unsigned long> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<unsigned long long> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<unsigned short> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<void> Specialization of allocator<T> where T is void. Does not contain members that are unrepresentable for void. Note that this specialization may be removed in the future. Use allocator<> or allocator<char> instead.
allocator<wchar_t> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<pair<Date, DayOfWeekSet>> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<pair<TimeInterval const, Node*>> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<pair<int const, pair<shared_ptr<Statistics>, shared_ptr<Collector<OsLinux>>>>> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<pair<basic_string<char> const, Json>> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<void*> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.
allocator<char const*> An STL-compatible allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::Allocator. This class template adheres to the allocator requirements defined in section [allocator.requirements]and implements a superset of the std::pmr::polymorphic_allocator class template described in section [mem.poly.allocator.class]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.

Non-Member Functions

NameDescription
formatFormat the specified args according to the specification given by the specified fmtStr in the locale of the specified loc, using the specified allocator to supply memory (if required), and return the result. In the event of an error throw the exception format_error.
formatFormat the specified args according to the specification given by the specified fmtStr, using the specified alloc to supply memory (if required), and return the result. In the event of an error throw the exception format_error.
formatFormat the specified args according to the specification given by the specified fmtStr in the locale of the specified loc, using the specified allocator to supply memory (if required), and return the result. In the event of an error throw the exception format_error.
formatFormat the specified args according to the specification given by the specified fmtStr, using the specified alloc to supply memory (if required), and return the result. In the event of an error throw the exception format_error.
vformatFormat the specified args according to the specification given by the specified fmtStr in the locale of the specified loc, using the specified allocator to supply memory (if required), and return the result. In the event of an error throw the exception format_error.
vformatFormat the specified args according to the specification given by the specified fmtStr, using the specified allocator to supply memory (if required), and return the result. In the event of an error throw the exception format_error.
vformatFormat the specified args according to the specification given by the specified fmtStr, using the specified allocator to supply memory (if required), and return the result. In the event of an error throw the exception format_error.
vformatFormat the specified args according to the specification given by the specified fmtStr in the locale of the specified loc, using the specified allocator to supply memory (if required), and return the result. In the event of an error throw the exception format_error.
::BloombergLP::bslfmt::formatFormat the specified args according to the specification given by the specified fmtStr, using the specified alloc to supply memory (if required), and return the result. In the event of an error the exception format_error is thrown.
::BloombergLP::bslfmt::formatFormat the specified args according to the specification given by the specified fmtStr, using the specified alloc to supply memory (if required), and return the result. In the event of an error the exception format_error is thrown.
::BloombergLP::bslfmt::vformatFormat the specified args according to the specification given by the specified fmtStr, using the specified allocator to supply memory (if required), and return the result. In the event of an error the exception format_error is thrown.
::BloombergLP::bslfmt::vformatFormat the specified args according to the specification given by the specified fmtStr, using the specified allocator to supply memory (if required), and return the result. In the event of an error the exception format_error is thrown.

Derived Classes

NameDescription
allocator<void> Specialization of allocator<T> where T is void. Does not contain members that are unrepresentable for void. Note that this specialization may be removed in the future. Use allocator<> or allocator<char> instead.