8#ifndef INCLUDED_BSLMA_POLYMORPHICALLOCATOR
9#define INCLUDED_BSLMA_POLYMORPHICALLOCATOR
309#include <bslscm_version.h>
330#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
334# define COMPILING_BSLMA_POLYMORPHICALLOCATOR_H
336# undef COMPILING_BSLMA_POLYMORPHICALLOCATOR_H
339#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
342# include <memory_resource>
347template <
class TYPE = std::
byte>
348using polymorphic_allocator = std::pmr::polymorphic_allocator<TYPE>;
368#if defined(BSLS_PLATFORM_CMP_MSVC)
384struct PolymorphicAllocator_Unique
389#define BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(VAL_T) \
390 std::pmr::polymorphic_allocator< \
391 BloombergLP::bslma::PolymorphicAllocator_Unique>
395#define BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(VAL_T) \
396 typename bsl::type_identity<std::pmr::polymorphic_allocator<VAL_T>>::type
407bool operator==(
const polymorphic_allocator<TYPE>& a,
408 const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& b)
414bool operator==(
const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& a,
415 const polymorphic_allocator<TYPE>& b)
421bool operator!=(
const polymorphic_allocator<TYPE>& a,
422 const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& b)
428bool operator!=(
const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& a,
429 const polymorphic_allocator<TYPE>& b)
451template <
class TYPE =
unsigned char>
476 template <
class ANY_TYPE>
510#ifdef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
517 template<
class ANY_TYPE>
532#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
557 template <
class ELEMENT_TYPE>
573#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
574 template <
class ELEMENT_TYPE,
class ARG1,
class... ARGS>
577 ARGS&&... arguments);
578 template <
class ELEMENT_TYPE,
class ARG1,
class... ARGS>
581 ARGS&&... arguments);
586 template <
class ELEMENT_TYPE>
625 return a.resource() == b.resource() || *a.resource() == *b.resource();
642 return a.resource() != b.resource() && *a.resource() != *b.resource();
653template <
class T1,
class T2>
662template <
class T1,
class T2>
694#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
695 template <
class TYPE2>
698 template <
class TYPE2>
701 template <
class TYPE2>
711 template <
typename ARG>
718 template <
class TYPE2>
740 template <
class TYPE2>
747#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
748 template <
class TYPE2,
class ARG1,
class... ARGS>
759 template <
class TYPE2,
class ARG1,
class... ARGS>
771 template <
class TYPE2>
845#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
856bool std::pmr::operator==(
const std::pmr::polymorphic_allocator<TYPE>& a,
857 const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& b)
860 return a.resource() == b.resource() || *a.resource() == *b.resource();
865bool std::pmr::operator==(
const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& a,
866 const std::pmr::polymorphic_allocator<TYPE>& b)
869 return a.resource() == b.resource() || *a.resource() == *b.resource();
874bool std::pmr::operator!=(
const std::pmr::polymorphic_allocator<TYPE>& a,
875 const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& b)
878 return a.resource() != b.resource() && *a.resource() != *b.resource();
883bool std::pmr::operator!=(
const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& a,
884 const std::pmr::polymorphic_allocator<TYPE>& b)
887 return a.resource() != b.resource() && *a.resource() != *b.resource();
901: d_resource(BloombergLP::
bslma::Default::defaultAllocator())
913#ifndef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
919: d_resource(other.resource())
925template<
class ANY_TYPE>
930: d_resource(other.resource())
939 const size_t k_TYPE_ALIGNMENT =
940 BloombergLP::bsls::AlignmentFromType<TYPE>::VALUE;
942 if (n > this->max_size()) {
943 BloombergLP::bsls::BslExceptionUtil::throwBadAlloc();
946 return static_cast<TYPE *
>(d_resource->
allocate(n *
sizeof(TYPE),
950#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
956 return this->allocate(n);
964 const std::size_t k_TYPE_ALIGNMENT =
965 BloombergLP::bsls::AlignmentFromType<TYPE>::VALUE;
967 d_resource->
deallocate(p, n *
sizeof(TYPE), k_TYPE_ALIGNMENT);
971template <
class ELEMENT_TYPE>
975 BloombergLP::bslma::ConstructionUtil::construct(address, *
this);
978#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
980template <
class ELEMENT_TYPE,
class ARG1,
class... ARGS>
986 BloombergLP::bslma::ConstructionUtil::construct(
994template <
class ELEMENT_TYPE,
class ARG1,
class... ARGS>
997 ELEMENT_TYPE *address,
1001 BloombergLP::bslma::ConstructionUtil::construct(
1009template <
class TYPE>
1010template <
class ELEMENT_TYPE>
1014 BloombergLP::bslma::DestructionUtil::destroy(address);
1019template <
class TYPE>
1024 return BloombergLP::bsls::Util::addressOf(x);
1027template <
class TYPE>
1032 return BloombergLP::bsls::Util::addressOf(x);
1035template <
class TYPE>
1046template <
class TYPE>
1053template <
class TYPE>
1064template <
class T1,
class T2>
1070 return a.resource() == b.resource() || *a.resource() == *b.resource();
1073template <
class T1,
class T2>
1079 return a.resource() != b.resource() && *a.resource() != *b.resource();
Definition bslma_memoryresource.h:441
BSLS_ANNOTATION_NODISCARD void * allocate(size_t bytes, size_t alignment=k_MAX_ALIGN)
Definition bslma_memoryresource.h:541
void deallocate(void *p, size_t bytes, size_t alignment=k_MAX_ALIGN)
Definition bslma_memoryresource.h:547
Definition bslma_polymorphicallocator.h:452
friend bool operator==(const polymorphic_allocator &a, const polymorphic_allocator &b) BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:622
BSLS_ANNOTATION_NODISCARD TYPE * allocate(std::size_t n)
Definition bslma_polymorphicallocator.h:937
memory_resource * resource() const
Return the address of the memory resource supplied on construction.
Definition bslma_polymorphicallocator.h:1048
TYPE * pointer
Definition bslma_polymorphicallocator.h:465
const_pointer address(const_reference x) const
Definition bslma_polymorphicallocator.h:1030
void construct(ELEMENT_TYPE *address, ARG1 &argument1, ARGS &&... arguments)
Definition bslma_polymorphicallocator.h:982
friend bool operator!=(const polymorphic_allocator &a, const polymorphic_allocator &b) BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:639
void construct(ELEMENT_TYPE *address)
Definition bslma_polymorphicallocator.h:973
~polymorphic_allocator()=default
const TYPE * const_pointer
Definition bslma_polymorphicallocator.h:466
polymorphic_allocator(const polymorphic_allocator &original) BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:918
polymorphic_allocator() BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:900
std::ptrdiff_t difference_type
Definition bslma_polymorphicallocator.h:464
void construct(ELEMENT_TYPE *address, BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1, ARGS &&... arguments)
Definition bslma_polymorphicallocator.h:996
TYPE & reference
Definition bslma_polymorphicallocator.h:467
std::size_t size_type
Definition bslma_polymorphicallocator.h:463
BSLS_KEYWORD_CONSTEXPR size_type max_size() const
Definition bslma_polymorphicallocator.h:1038
polymorphic_allocator select_on_container_copy_construction() const
Return a default-constructed polymorphic_allocator.
Definition bslma_polymorphicallocator.h:1056
polymorphic_allocator(const polymorphic_allocator< ANY_TYPE > &original) BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:928
TYPE value_type
Definition bslma_polymorphicallocator.h:469
void deallocate(TYPE *p, std::size_t n)
Definition bslma_polymorphicallocator.h:962
const TYPE & const_reference
Definition bslma_polymorphicallocator.h:468
pointer address(reference x) const
Definition bslma_polymorphicallocator.h:1022
void destroy(ELEMENT_TYPE *address)
Definition bslma_polymorphicallocator.h:1012
#define BSLS_ANNOTATION_NODISCARD
Definition bsls_annotation.h:373
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#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_DELETED
Definition bsls_keyword.h:609
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
Definition bdlb_printmethods.h:283
bool operator!=(const memory_resource &a, const memory_resource &b)
Definition balxml_encoderoptions.h:68
Definition bdlbb_blob.h:576
rebind_alloc(const ARG &allocatorArg)
Definition bslma_polymorphicallocator.h:712
rebind_alloc()
Definition bslma_polymorphicallocator.h:703
false_type propagate_on_container_copy_assignment
Definition bslma_polymorphicallocator.h:796
TYPE value_type
Definition bslma_polymorphicallocator.h:685
std::ptrdiff_t difference_type
Definition bslma_polymorphicallocator.h:691
false_type propagate_on_container_swap
Definition bslma_polymorphicallocator.h:798
polymorphic_allocator< TYPE > allocator_type
Definition bslma_polymorphicallocator.h:684
static pointer allocate(allocator_type &m, size_type n)
Definition bslma_polymorphicallocator.h:723
static BSLS_KEYWORD_CONSTEXPR size_type max_size(const allocator_type &)
Definition bslma_polymorphicallocator.h:778
std::size_t size_type
Definition bslma_polymorphicallocator.h:692
static void construct(allocator_type &m, TYPE2 *p)
Definition bslma_polymorphicallocator.h:741
static void construct(allocator_type &m, TYPE2 *p, ARG1 &argument1, ARGS &&... arguments)
Definition bslma_polymorphicallocator.h:749
const TYPE * const_pointer
Definition bslma_polymorphicallocator.h:688
TYPE * pointer
Definition bslma_polymorphicallocator.h:687
false_type propagate_on_container_move_assignment
Definition bslma_polymorphicallocator.h:797
const void * const_void_pointer
Definition bslma_polymorphicallocator.h:690
static void destroy(allocator_type &, TYPE2 *p)
Definition bslma_polymorphicallocator.h:772
static void deallocate(allocator_type &m, pointer p, size_type n)
Definition bslma_polymorphicallocator.h:735
void * void_pointer
Definition bslma_polymorphicallocator.h:689
false_type is_always_equal
Definition bslma_polymorphicallocator.h:795
static void construct(allocator_type &m, TYPE2 *p, BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1, ARGS &&... arguments)
Definition bslma_polymorphicallocator.h:760
static allocator_type select_on_container_copy_construction(const allocator_type &)
Definition bslma_polymorphicallocator.h:790
static pointer allocate(allocator_type &m, size_type n, const_void_pointer)
Definition bslma_polymorphicallocator.h:728
Definition bslma_allocatortraits.h:1061
BloombergLP::bslma::AllocatorTraits_SizeType< ALLOCATOR_TYPE >::type size_type
Definition bslma_allocatortraits.h:1165
ALLOCATOR_TYPE allocator_type
Definition bslma_allocatortraits.h:1144
Definition bslmf_integralconstant.h:244
Definition bslmf_istriviallycopyable.h:329
Definition bslma_polymorphicallocator.h:477
polymorphic_allocator< ANY_TYPE > other
Definition bslma_polymorphicallocator.h:478
Definition bslma_isstdallocator.h:201
Definition bslma_usesbslmaallocator.h:343
Definition bslmf_isbitwiseequalitycomparable.h:499