16namespace sequoia::testing
39 template<
class T,
bool PropagateCopy=true,
bool PropagateMove=true,
bool PropagateSwap=false>
44 using size_type = std::size_t;
45 using difference_type = std::ptrdiff_t;
46 using propagate_on_container_copy_assignment = std::bool_constant<PropagateCopy>;
47 using propagate_on_container_move_assignment = std::bool_constant<PropagateMove>;
48 using propagate_on_container_swap = std::bool_constant<PropagateSwap>;
49 using is_always_equal = std::false_type;
58 : m_pAllocs{std::make_shared<int>()}, m_pDeallocs{std::make_shared<int>()}
65 [[nodiscard]] T* allocate(std::size_t n)
67 const auto ptr{
static_cast<T*
>(::operator
new(n *
sizeof(T)))};
74 void deallocate(T* p, std::size_t n)
77 if(n) ++(*m_pDeallocs);
81 int allocs() const noexcept {
return *m_pAllocs; }
84 int deallocs() const noexcept {
return *m_pDeallocs; }
87 friend bool operator==(
const shared_counting_allocator&,
const shared_counting_allocator&)
noexcept =
default;
89 std::shared_ptr<int> m_pAllocs{}, m_pDeallocs{};
92#if _ITERATOR_DEBUG_LEVEL != 0
97 template<
class,
bool,
bool,
bool>
98 friend class shared_counting_allocator;
100 shared_counting_allocator(std::shared_ptr<int> pAllocs, std::shared_ptr<int> pDeallocs)
101 : m_pAllocs{ std::move(pAllocs) }
102 , m_pDeallocs{ std::move(pDeallocs) }
107 explicit operator shared_counting_allocator<U, PropagateCopy, PropagateMove, PropagateSwap>()
const
109 return {m_pAllocs, m_pDeallocs};
116 struct type_demangler;
118 template<
class T,
bool PropagateCopy,
bool PropagateMove,
bool PropagateSwap>
122 static std::string make()
124 auto info{std::string{
"shared_counting_allocator<\n\t\t"}.append(demangle<T>()).append(
",\n")};
126 auto toString{[](
bool b){
return b ?
"true" :
"false";}};
128 info.append(
"\t\tPropagate on copy assignment = ").append(toString(PropagateCopy)).append(
",\n");
129 info.append(
"\t\tPropagate on move assignment = ").append(toString(PropagateMove)).append(
",\n");
130 info.append(
"\t\tPropagate on swap = ").append(toString(PropagateSwap)).append(
"\n >");
Traits which are sufficiently general to appear in the sequoia namespace.
Somewhat similar to std::allocator but logs (de)allocations via an counter which is shared upon copyi...
Definition: AllocationTestUtilities.hpp:41
Definition: AllocationTestUtilities.hpp:53
Specialize this struct template to customize the way in which type info is generated for a given clas...
Definition: Output.hpp:256