8#ifndef INCLUDED_BSLMA_ALLOCATORTRAITS
9#define INCLUDED_BSLMA_ALLOCATORTRAITS
491#include <bslscm_version.h>
504#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
508# define COMPILING_BSLMA_ALLOCATORTRAITS_H
510# undef COMPILING_BSLMA_ALLOCATORTRAITS_H
528template <
class ALLOC>
533 typedef struct {
char d_a; } yes_type;
534 typedef struct {
char d_a[2]; } no_type;
541 static yes_type match(
typename U::is_always_equal *);
543 static no_type match(...);
547 static const bool value =
sizeof(match<ALLOC>(0)) ==
sizeof(yes_type);
561template <class ALLOC, bool = AllocatorTraits_HasIsAlwaysEqual<ALLOC>::value>
570template <
class ALLOC>
587template <
class ALLOCATOR_TYPE>
591 typedef struct {
char a; } yes_type;
592 typedef struct {
char a[2]; } no_type;
596 template <
class T, T>
struct MatchType { };
599 struct MethodAlias {
typedef T (T::*Method)()
const; };
605 template <
class TYPE>
606 static yes_type match(MatchType<
typename MethodAlias<TYPE>::Method,
607 &TYPE::select_on_container_copy_construction> *);
608 template <
class TYPE>
609 static no_type match(...);
613 sizeof(match<ALLOCATOR_TYPE>(0)) ==
sizeof(yes_type);
627template <
class ALLOCATOR_TYPE>
631 typedef struct {
char a; } yes_type;
632 typedef struct {
char a[2]; } no_type;
639 yes_type match(
typename U::propagate_on_container_copy_assignment *);
641 static no_type match(...);
645 sizeof(match<ALLOCATOR_TYPE>(0)) ==
sizeof(yes_type);
658template <
class ALLOCATOR_TYPE,
669template <
class ALLOC>
671 :
public ALLOC::propagate_on_container_copy_assignment
685template <
class ALLOC>
689 typedef struct {
char a; } yes_type;
690 typedef struct {
char a[2]; } no_type;
697 yes_type match(
typename U::propagate_on_container_move_assignment *);
699 static no_type match(...);
702 static const bool value =
sizeof(match<ALLOC>(0)) ==
sizeof(yes_type);
715template <
class ALLOC,
726template <
class ALLOC>
728 :
public ALLOC::propagate_on_container_move_assignment
741template <
class ALLOC>
745 typedef struct {
char a; } yes_type;
746 typedef struct {
char a[2]; } no_type;
753 yes_type match(
typename U::propagate_on_container_swap *);
755 static no_type match(...);
758 static const bool value =
sizeof(match<ALLOC>(0)) ==
sizeof(yes_type);
770template <class ALLOC, bool = AllocatorTraits_HasPropOnSwap<ALLOC>::value>
780template <
class ALLOC>
782 :
public ALLOC::propagate_on_container_swap
786#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE) && \
787 defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \
788 defined(BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES)
794template <
class T,
class Return,
class... Args>
795struct AllocatorTraits_HasConstructMethod {
798 static auto match(U *) ->
800 bslmf::Util::declval<Args>()...)),
806 typedef decltype(match<T>(0)) type;
807 static const bool value = type::value;
814template <
class T,
class Return,
class... Args>
815struct AllocatorTraits_HasDestroyMethod {
818 static auto match(U *) ->
820 bslmf::Util::declval<Args>()...)),
826 typedef decltype(match<T>(0)) type;
827 static const bool value = type::value;
836template <
class T,
class =
void>
838 typedef typename T::value_type *
type;
844 typedef typename T::pointer
type;
851template <
class T,
class =
void>
854 typedef const typename T::value_type *
type;
862 typedef typename T::const_pointer
type;
870template <
class T,
class =
void>
881 typedef typename T::void_pointer
type;
888template <
class T,
class =
void>
899 typedef typename T::const_void_pointer
type;
906template <
class T,
class =
void>
914 typedef typename T::size_type
type;
922template <
class T,
class =
void>
933 typedef typename T::difference_type
type;
940#if defined(BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES)
943template <
class T,
class U>
947template <
template <
class,
class...>
class ALLOC,
951struct AllocatorTraits_RebindFront<ALLOC<T, ARGS...>, U> {
952 using type = ALLOC<U, ARGS...>;
955template <
class T,
class U>
961template <
template <
class>
class ALLOC,
974template <
class T,
class U,
class =
void>
980template <
class T,
class U>
985 typedef typename T::template rebind<U>::other
type;
992#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE)
993template <
class T,
class =
void>
994struct AllocatorTraits_CallMaxSize {
1004 static SizeType max_size(
const T &)
1006 return std::numeric_limits<SizeType>::max() /
1007 sizeof(
typename T::value_type);
1015struct AllocatorTraits_CallMaxSize<
1020 typedef typename AllocatorTraits_SizeType<T>::type SizeType;
1027 static SizeType max_size(
const T &alloc)
1029 return alloc.max_size();
1060template <
class ALLOCATOR_TYPE>
1065 typedef typename BloombergLP::bslma::AllocatorTraits_HasSelectOnCopyMethod<
1066 ALLOCATOR_TYPE>::type DelegateSelectMethod;
1072 ALLOCATOR_TYPE selectOnCopyConstruct(
const ALLOCATOR_TYPE& stdAllocator,
1079 ALLOCATOR_TYPE selectOnCopyConstruct(
const ALLOCATOR_TYPE& stdAllocator,
1082#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE) && \
1083 defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \
1084 defined(BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES)
1094 template <
class ELEMENT_TYPE,
class... Args>
1096 BloombergLP::bslma::AllocatorTraits_HasConstructMethod<ALLOCATOR_TYPE,
1101 privateConstruct(ALLOCATOR_TYPE& basicAllocator,
1102 ELEMENT_TYPE *elementAddr,
1103 Args&&... arguments);
1104 template <
class ELEMENT_TYPE,
class... Args>
1106 !BloombergLP::bslma::AllocatorTraits_HasConstructMethod<
1112 privateConstruct(ALLOCATOR_TYPE& basicAllocator,
1113 ELEMENT_TYPE *elementAddr,
1114 Args&&... arguments);
1116 template <
class ELEMENT_TYPE>
1118 BloombergLP::bslma::AllocatorTraits_HasDestroyMethod<
1121 ELEMENT_TYPE *>::value,
1123 privateDestroy(ALLOCATOR_TYPE& basicAllocator, ELEMENT_TYPE *elementAddr);
1132 template <
class ELEMENT_TYPE>
1134 !BloombergLP::bslma::AllocatorTraits_HasDestroyMethod<
1137 ELEMENT_TYPE *>::value,
1139 privateDestroy(ALLOCATOR_TYPE& basicAllocator, ELEMENT_TYPE *elementAddr);
1148 BloombergLP::bslma::AllocatorTraits_PointerType<ALLOCATOR_TYPE>::type
1151 BloombergLP::bslma::AllocatorTraits_ConstPointerType<ALLOCATOR_TYPE>::type
1154 BloombergLP::bslma::AllocatorTraits_VoidPointerType<ALLOCATOR_TYPE>::type
1156 typedef typename BloombergLP::bslma::
1157 AllocatorTraits_ConstVoidPointerType<ALLOCATOR_TYPE>::type
1161 BloombergLP::bslma::AllocatorTraits_DifferenceType<ALLOCATOR_TYPE>::type
1164 BloombergLP::bslma::AllocatorTraits_SizeType<ALLOCATOR_TYPE>::type
1167#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
1168 template <
class ELEMENT_TYPE>
1170 BloombergLP::bslma::AllocatorTraits_RebindAlloc<ALLOCATOR_TYPE,
1171 ELEMENT_TYPE>::type;
1173 template <
class ELEMENT_TYPE>
1176 template <
class ELEMENT_TYPE>
1178 : BloombergLP::bslma::AllocatorTraits_RebindAlloc<ALLOCATOR_TYPE,
1188 typedef typename BloombergLP::bslma::
1189 AllocatorTraits_RebindAlloc<ALLOCATOR_TYPE, ELEMENT_TYPE>::type
1192 template <
typename ARG>
1203 template <
class ELEMENT_TYPE>
1205 rebind_alloc<ELEMENT_TYPE>::allocator_type>
1231#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1242 template <
class ELEMENT_TYPE,
class... Args>
1244 ELEMENT_TYPE *elementAddr,
1245 Args&&... arguments);
1255 template <
class ELEMENT_TYPE>
1256 static void destroy(ALLOCATOR_TYPE& basicAllocator,
1257 ELEMENT_TYPE *elementAddr);
1279 static ALLOCATOR_TYPE
1287 typedef typename BloombergLP::bslma::AllocatorTraits_IsAlwaysEqual<
1296 typedef typename BloombergLP::bslma::AllocatorTraits_PropOnCopyAssign<
1305 typedef typename BloombergLP::bslma::AllocatorTraits_PropOnMoveAssign<
1314 typedef typename BloombergLP::bslma::AllocatorTraits_PropOnSwap<
1330template <
class ALLOCATOR_TYPE>
1348template <
class ALLOCATOR_TYPE>
1350ALLOCATOR_TYPE allocator_traits<ALLOCATOR_TYPE>::selectOnCopyConstruct(
1351 const ALLOCATOR_TYPE& stdAllocator,
1354 return stdAllocator.select_on_container_copy_construction();
1357template <
class ALLOCATOR_TYPE>
1359ALLOCATOR_TYPE allocator_traits<ALLOCATOR_TYPE>::selectOnCopyConstruct(
1360 const ALLOCATOR_TYPE& stdAllocator,
1363 return stdAllocator;
1366#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE) && \
1367 defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \
1368 defined(BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES)
1369template <
class ALLOCATOR_TYPE>
1370template <
class ELEMENT_TYPE,
class... Args>
1373 BloombergLP::bslma::AllocatorTraits_HasConstructMethod<ALLOCATOR_TYPE,
1378allocator_traits<ALLOCATOR_TYPE>::privateConstruct(
1379 ALLOCATOR_TYPE& basicAllocator,
1380 ELEMENT_TYPE *elementAddr,
1381 Args&&... arguments)
1383 basicAllocator.construct(
1387template <
class ALLOCATOR_TYPE>
1388template <
class ELEMENT_TYPE,
class... Args>
1391 !BloombergLP::bslma::AllocatorTraits_HasConstructMethod<ALLOCATOR_TYPE,
1396allocator_traits<ALLOCATOR_TYPE>::privateConstruct(ALLOCATOR_TYPE&,
1397 ELEMENT_TYPE *elementAddr,
1398 Args&&... arguments)
1400 ::new (
static_cast<void *
>(elementAddr))
1404template <
class ALLOCATOR_TYPE>
1405template <
class ELEMENT_TYPE>
1407typename bsl::enable_if<BloombergLP::bslma::AllocatorTraits_HasDestroyMethod<
1410 ELEMENT_TYPE *>::value,
1412allocator_traits<ALLOCATOR_TYPE>::privateDestroy(
1413 ALLOCATOR_TYPE& basicAllocator,
1414 ELEMENT_TYPE *elementAddr)
1416 basicAllocator.destroy(elementAddr);
1419template <
class ALLOCATOR_TYPE>
1420template <
class ELEMENT_TYPE>
1422typename bsl::enable_if<!BloombergLP::bslma::AllocatorTraits_HasDestroyMethod<
1425 ELEMENT_TYPE *>::value,
1427allocator_traits<ALLOCATOR_TYPE>::privateDestroy(ALLOCATOR_TYPE&,
1428 ELEMENT_TYPE *elementAddr)
1430 elementAddr->~ELEMENT_TYPE();
1436template <
class ALLOCATOR_TYPE>
1442 return basicAllocator.allocate(n);
1445template <
class ALLOCATOR_TYPE>
1452 return basicAllocator.allocate(n, hint);
1455template <
class ALLOCATOR_TYPE>
1462 basicAllocator.deallocate(elementAddr, n);
1467#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
1468template <
class ALLOCATOR_TYPE>
1469template <
class ELEMENT_TYPE,
class... Args>
1473 ELEMENT_TYPE *elementAddr,
1474 Args&&... arguments)
1476#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE)
1477 privateConstruct(basicAllocator,
1484 basicAllocator.construct(
1490template <
class ALLOCATOR_TYPE>
1491template <
class ELEMENT_TYPE>
1495 ELEMENT_TYPE *elementAddr)
1503#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE) && \
1504 defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
1505 privateDestroy(stdAllocator, elementAddr);
1507 elementAddr->~ELEMENT_TYPE();
1508 (void) stdAllocator;
1512template <
class ALLOCATOR_TYPE>
1518#if defined(BSLS_COMPILERFEATURES_SUPPORT_DECLTYPE)
1519 return BloombergLP::bslma::
1520 AllocatorTraits_CallMaxSize<ALLOCATOR_TYPE>::max_size(basicAllocator);
1525 return basicAllocator.max_size();
1529template <
class ALLOCATOR_TYPE>
1533 const ALLOCATOR_TYPE& rhs)
1535 return selectOnCopyConstruct(rhs, DelegateSelectMethod());
#define BSLMF_VOIDTYPE(ARG)
Definition bslmf_voidtype.h:335
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2018
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
Definition bdlb_printmethods.h:283
integral_constant< bool, false > false_type
Definition bslmf_integralconstant.h:297
integral_constant< bool, true > true_type
Definition bslmf_integralconstant.h:303
Definition balxml_encoderoptions.h:68
Definition bdlbb_blob.h:576
Definition bslma_allocatortraits.h:1180
rebind_alloc(const ARG &allocatorArg)
Definition bslma_allocatortraits.h:1193
BloombergLP::bslma::AllocatorTraits_RebindAlloc< ALLOCATOR_TYPE, ELEMENT_TYPE >::type allocator_type
Definition bslma_allocatortraits.h:1190
Definition bslma_allocatortraits.h:1206
Definition bslma_allocatortraits.h:1061
static pointer allocate(ALLOCATOR_TYPE &basicAllocator, size_type n)
Return basicAllocator.allocate(n).
Definition bslma_allocatortraits.h:1439
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_PropOnCopyAssign< ALLOCATOR_TYPE >::type propagate_on_container_copy_assignment
Definition bslma_allocatortraits.h:1297
BloombergLP::bslma::AllocatorTraits_PropOnMoveAssign< ALLOCATOR_TYPE >::type propagate_on_container_move_assignment
Definition bslma_allocatortraits.h:1306
static ALLOCATOR_TYPE select_on_container_copy_construction(const ALLOCATOR_TYPE &rhs)
Definition bslma_allocatortraits.h:1532
BloombergLP::bslma::AllocatorTraits_SizeType< ALLOCATOR_TYPE >::type size_type
Definition bslma_allocatortraits.h:1165
static void construct(ALLOCATOR_TYPE &basicAllocator, ELEMENT_TYPE *elementAddr, Args &&... arguments)
Definition bslma_allocatortraits.h:1472
static pointer allocate(ALLOCATOR_TYPE &basicAllocator, size_type n, const_void_pointer hint)
Return basicAllocator.allocate(n, hint).
Definition bslma_allocatortraits.h:1448
static size_type max_size(const ALLOCATOR_TYPE &basicAllocator) BSLS_KEYWORD_NOEXCEPT
Definition bslma_allocatortraits.h:1515
BloombergLP::bslma::AllocatorTraits_PointerType< ALLOCATOR_TYPE >::type pointer
Definition bslma_allocatortraits.h:1149
static void destroy(ALLOCATOR_TYPE &basicAllocator, ELEMENT_TYPE *elementAddr)
Definition bslma_allocatortraits.h:1494
BloombergLP::bslma::AllocatorTraits_IsAlwaysEqual< ALLOCATOR_TYPE >::type is_always_equal
Definition bslma_allocatortraits.h:1288
static void deallocate(ALLOCATOR_TYPE &basicAllocator, pointer elementAddr, size_type n)
Definition bslma_allocatortraits.h:1458
BloombergLP::bslma::AllocatorTraits_PropOnSwap< ALLOCATOR_TYPE >::type propagate_on_container_swap
Definition bslma_allocatortraits.h:1315
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
ALLOCATOR_TYPE::value_type value_type
Definition bslma_allocatortraits.h:1145
Definition bslmf_enableif.h:525
Definition bslmf_integralconstant.h:244
Definition bslmf_isempty.h:315
Definition bslmf_issame.h:146
T::const_pointer type
Definition bslma_allocatortraits.h:862
Definition bslma_allocatortraits.h:852
const T::value_type * type
should be pointer_traits::rebind of template above
Definition bslma_allocatortraits.h:854
T::const_void_pointer type
Definition bslma_allocatortraits.h:899
Definition bslma_allocatortraits.h:889
const void * type
should be pointer_traits::rebind of template above
Definition bslma_allocatortraits.h:891
T::difference_type type
Definition bslma_allocatortraits.h:933
should be pointer_traits::rebind of template above
Definition bslma_allocatortraits.h:923
std::ptrdiff_t type
Definition bslma_allocatortraits.h:924
Definition bslma_allocatortraits.h:529
static const bool value
Definition bslma_allocatortraits.h:547
bsl::integral_constant< bool, value > type
Definition bslma_allocatortraits.h:550
Definition bslma_allocatortraits.h:628
static const bool value
Definition bslma_allocatortraits.h:644
bsl::integral_constant< bool, value > type
Definition bslma_allocatortraits.h:646
Definition bslma_allocatortraits.h:686
bsl::integral_constant< bool, value > type
Definition bslma_allocatortraits.h:703
static const bool value
Definition bslma_allocatortraits.h:702
Definition bslma_allocatortraits.h:742
bsl::integral_constant< bool, value > type
Definition bslma_allocatortraits.h:759
static const bool value
Definition bslma_allocatortraits.h:758
Definition bslma_allocatortraits.h:588
bsl::integral_constant< bool, value > type
Definition bslma_allocatortraits.h:614
static const bool value
Definition bslma_allocatortraits.h:612
Definition bslma_allocatortraits.h:563
T::pointer type
Definition bslma_allocatortraits.h:844
Definition bslma_allocatortraits.h:837
T::value_type * type
Definition bslma_allocatortraits.h:838
Definition bslma_allocatortraits.h:661
Definition bslma_allocatortraits.h:718
Definition bslma_allocatortraits.h:772
T::template rebind< U >::other type
Definition bslma_allocatortraits.h:985
should be pointer_traits::rebind of template above
Definition bslma_allocatortraits.h:975
AllocatorTraits_RebindFront< T, U >::type type
Definition bslma_allocatortraits.h:976
ALLOC< U > type
Definition bslma_allocatortraits.h:965
Definition bslma_allocatortraits.h:956
T::size_type type
Definition bslma_allocatortraits.h:914
Definition bslma_allocatortraits.h:907
std::size_t type
Definition bslma_allocatortraits.h:908
T::void_pointer type
Definition bslma_allocatortraits.h:881
Definition bslma_allocatortraits.h:871
void * type
should be pointer_traits::rebind of template above
Definition bslma_allocatortraits.h:873