8#ifndef INCLUDED_BSLMA_POLYMORPHICALLOCATOR
9#define INCLUDED_BSLMA_POLYMORPHICALLOCATOR
311#include <bslscm_version.h>
333#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
339# define COMPILING_BSLMA_POLYMORPHICALLOCATOR_H
341# undef COMPILING_BSLMA_POLYMORPHICALLOCATOR_H
346#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
349# include <memory_resource>
354template <
class TYPE = std::
byte>
355using polymorphic_allocator = std::pmr::polymorphic_allocator<TYPE>;
375#if defined(BSLS_PLATFORM_CMP_MSVC)
391struct PolymorphicAllocator_Unique
396#define BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(VAL_T) \
397 std::pmr::polymorphic_allocator< \
398 BloombergLP::bslma::PolymorphicAllocator_Unique>
402#define BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(VAL_T) \
403 typename bsl::type_identity<std::pmr::polymorphic_allocator<VAL_T>>::type
414bool operator==(
const polymorphic_allocator<TYPE>& a,
415 const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& b)
421bool operator==(
const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& a,
422 const polymorphic_allocator<TYPE>& b)
428bool operator!=(
const polymorphic_allocator<TYPE>& a,
429 const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& b)
435bool operator!=(
const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& a,
436 const polymorphic_allocator<TYPE>& b)
459template <
class TYPE =
unsigned char>
488 template <
class ANY_TYPE>
524#ifdef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
531 template<
class ANY_TYPE>
547#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
575 template <
class ELEMENT_TYPE>
593#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
594 template <
class ELEMENT_TYPE,
class ARG1,
class... ARGS>
597 ARGS&&... arguments);
598 template <
class ELEMENT_TYPE,
class ARG1,
class... ARGS>
601 ARGS&&... arguments);
606 template <
class ELEMENT_TYPE>
647 return a.resource() == b.resource() || *a.resource() == *b.resource();
665 return a.resource() != b.resource() && *a.resource() != *b.resource();
677template <
class T1,
class T2>
687template <
class T1,
class T2>
719#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
720 template <
class TYPE2>
723 template <
class TYPE2>
726 template <
class TYPE2>
736 template <
typename ARG>
743 template <
class TYPE2>
765 template <
class TYPE2>
772#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
773 template <
class TYPE2,
class ARG1,
class... ARGS>
784 template <
class TYPE2,
class ARG1,
class... ARGS>
796 template <
class TYPE2>
871#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
882bool std::pmr::operator==(
const std::pmr::polymorphic_allocator<TYPE>& a,
883 const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& b)
886 return a.resource() == b.resource() || *a.resource() == *b.resource();
891bool std::pmr::operator==(
const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& a,
892 const std::pmr::polymorphic_allocator<TYPE>& b)
895 return a.resource() == b.resource() || *a.resource() == *b.resource();
900bool std::pmr::operator!=(
const std::pmr::polymorphic_allocator<TYPE>& a,
901 const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& b)
904 return a.resource() != b.resource() && *a.resource() != *b.resource();
909bool std::pmr::operator!=(
const BSLMF_POLYMORPHICALLOCATOR_NODEDUCE_T(TYPE)& a,
910 const std::pmr::polymorphic_allocator<TYPE>& b)
913 return a.resource() != b.resource() && *a.resource() != *b.resource();
927: d_resource(BloombergLP::
bslma::Default::defaultAllocator())
939#ifndef BSLS_COMPILERFEATURES_SUPPORT_DEFAULTED_FUNCTIONS
945: d_resource(other.resource())
951template<
class ANY_TYPE>
956: d_resource(other.resource())
965 const size_t k_TYPE_ALIGNMENT =
966 BloombergLP::bsls::AlignmentFromType<TYPE>::VALUE;
968 if (n > this->max_size()) {
969 BloombergLP::bsls::BslExceptionUtil::throwBadAlloc();
972 return static_cast<TYPE *
>(d_resource->
allocate(n *
sizeof(TYPE),
976#ifndef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
982 return this->allocate(n);
990 const std::size_t k_TYPE_ALIGNMENT =
991 BloombergLP::bsls::AlignmentFromType<TYPE>::VALUE;
993 d_resource->
deallocate(p, n *
sizeof(TYPE), k_TYPE_ALIGNMENT);
997template <
class ELEMENT_TYPE>
1001 BloombergLP::bslma::ConstructionUtil::construct(address, *
this);
1004#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1005template <
class TYPE>
1006template <
class ELEMENT_TYPE,
class ARG1,
class... ARGS>
1010 ARGS&&... arguments)
1012 BloombergLP::bslma::ConstructionUtil::construct(
1019template <
class TYPE>
1020template <
class ELEMENT_TYPE,
class ARG1,
class... ARGS>
1023 ELEMENT_TYPE *address,
1025 ARGS&&... arguments)
1027 BloombergLP::bslma::ConstructionUtil::construct(
1035template <
class TYPE>
1036template <
class ELEMENT_TYPE>
1040 BloombergLP::bslma::DestructionUtil::destroy(address);
1045template <
class TYPE>
1050 return BloombergLP::bsls::Util::addressOf(x);
1053template <
class TYPE>
1058 return BloombergLP::bsls::Util::addressOf(x);
1061template <
class TYPE>
1072template <
class TYPE>
1079template <
class TYPE>
1090template <
class T1,
class T2>
1096 return a.resource() == b.resource() || *a.resource() == *b.resource();
1099template <
class T1,
class T2>
1105 return a.resource() != b.resource() && *a.resource() != *b.resource();
Definition bslma_memoryresource.h:443
BSLA_NODISCARD void * allocate(size_t bytes, size_t alignment=k_MAX_ALIGN)
Definition bslma_memoryresource.h:550
void deallocate(void *p, size_t bytes, size_t alignment=k_MAX_ALIGN)
Definition bslma_memoryresource.h:556
Definition bslma_polymorphicallocator.h:460
friend bool operator==(const polymorphic_allocator &a, const polymorphic_allocator &b) BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:644
BSLS_ANNOTATION_NODISCARD TYPE * allocate(std::size_t n)
Definition bslma_polymorphicallocator.h:963
memory_resource * resource() const
Return the address of the memory resource supplied on construction.
Definition bslma_polymorphicallocator.h:1074
TYPE * pointer
Definition bslma_polymorphicallocator.h:474
const_pointer address(const_reference x) const
Definition bslma_polymorphicallocator.h:1056
void construct(ELEMENT_TYPE *address, ARG1 &argument1, ARGS &&... arguments)
Definition bslma_polymorphicallocator.h:1008
friend bool operator!=(const polymorphic_allocator &a, const polymorphic_allocator &b) BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:662
void construct(ELEMENT_TYPE *address)
Definition bslma_polymorphicallocator.h:999
~polymorphic_allocator()=default
const TYPE * const_pointer
Definition bslma_polymorphicallocator.h:475
polymorphic_allocator(const polymorphic_allocator &original) BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:944
polymorphic_allocator() BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:926
std::ptrdiff_t difference_type
Definition bslma_polymorphicallocator.h:473
void construct(ELEMENT_TYPE *address, BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1, ARGS &&... arguments)
Definition bslma_polymorphicallocator.h:1022
TYPE & reference
Definition bslma_polymorphicallocator.h:476
std::size_t size_type
Definition bslma_polymorphicallocator.h:472
BSLS_KEYWORD_CONSTEXPR size_type max_size() const
Definition bslma_polymorphicallocator.h:1064
polymorphic_allocator select_on_container_copy_construction() const
Return a default-constructed polymorphic_allocator.
Definition bslma_polymorphicallocator.h:1082
BSLS_ANNOTATION_NODISCARD TYPE * allocate(std::size_t n, const void *hint)
Definition bslma_polymorphicallocator.h:980
polymorphic_allocator(const polymorphic_allocator< ANY_TYPE > &original) BSLS_KEYWORD_NOEXCEPT
Definition bslma_polymorphicallocator.h:954
TYPE value_type
Definition bslma_polymorphicallocator.h:478
void deallocate(TYPE *p, std::size_t n)
Definition bslma_polymorphicallocator.h:988
const TYPE & const_reference
Definition bslma_polymorphicallocator.h:477
pointer address(reference x) const
Definition bslma_polymorphicallocator.h:1048
void destroy(ELEMENT_TYPE *address)
Definition bslma_polymorphicallocator.h:1038
#define BSLS_ANNOTATION_NODISCARD
Definition bsls_annotation.h:368
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:624
#define BSLS_KEYWORD_DELETED
Definition bsls_keyword.h:651
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
Definition bdlat_valuetypefunctions.h:939
bool operator!=(const memory_resource &a, const memory_resource &b)
Definition baljsn_encoder_testtypes.h:76
Definition bdlbb_blob.h:579
rebind_alloc(const ARG &allocatorArg)
Definition bslma_polymorphicallocator.h:737
rebind_alloc()
Definition bslma_polymorphicallocator.h:728
false_type propagate_on_container_copy_assignment
Definition bslma_polymorphicallocator.h:821
TYPE value_type
Definition bslma_polymorphicallocator.h:710
std::ptrdiff_t difference_type
Definition bslma_polymorphicallocator.h:716
false_type propagate_on_container_swap
Definition bslma_polymorphicallocator.h:823
polymorphic_allocator< TYPE > allocator_type
Definition bslma_polymorphicallocator.h:709
static pointer allocate(allocator_type &m, size_type n)
Definition bslma_polymorphicallocator.h:748
static BSLS_KEYWORD_CONSTEXPR size_type max_size(const allocator_type &)
Definition bslma_polymorphicallocator.h:803
std::size_t size_type
Definition bslma_polymorphicallocator.h:717
static void construct(allocator_type &m, TYPE2 *p)
Definition bslma_polymorphicallocator.h:766
static void construct(allocator_type &m, TYPE2 *p, ARG1 &argument1, ARGS &&... arguments)
Definition bslma_polymorphicallocator.h:774
const TYPE * const_pointer
Definition bslma_polymorphicallocator.h:713
TYPE * pointer
Definition bslma_polymorphicallocator.h:712
false_type propagate_on_container_move_assignment
Definition bslma_polymorphicallocator.h:822
const void * const_void_pointer
Definition bslma_polymorphicallocator.h:715
static void destroy(allocator_type &, TYPE2 *p)
Definition bslma_polymorphicallocator.h:797
static void deallocate(allocator_type &m, pointer p, size_type n)
Definition bslma_polymorphicallocator.h:760
void * void_pointer
Definition bslma_polymorphicallocator.h:714
false_type is_always_equal
Definition bslma_polymorphicallocator.h:820
static void construct(allocator_type &m, TYPE2 *p, BSLS_COMPILERFEATURES_FORWARD_REF(ARG1) argument1, ARGS &&... arguments)
Definition bslma_polymorphicallocator.h:785
static allocator_type select_on_container_copy_construction(const allocator_type &)
Definition bslma_polymorphicallocator.h:815
static pointer allocate(allocator_type &m, size_type n, const_void_pointer)
Definition bslma_polymorphicallocator.h:753
Definition bslma_allocatortraits.h:1089
BloombergLP::bslma::AllocatorTraits_SizeType< ALLOCATOR_TYPE >::type size_type
Definition bslma_allocatortraits.h:1196
ALLOCATOR_TYPE allocator_type
Definition bslma_allocatortraits.h:1175
Definition bslmf_integralconstant.h:261
Definition bslmf_istriviallycopyable.h:324
Definition bslma_polymorphicallocator.h:489
polymorphic_allocator< ANY_TYPE > other
Definition bslma_polymorphicallocator.h:490
Definition bslma_isstdallocator.h:202
Definition bslma_usesbslmaallocator.h:344
Definition bslmf_isbitwiseequalitycomparable.h:500