3#include "../utility/assert.h"
4#include "../utility/empty_base.h"
5#include "../utility/meta.h"
6#include "../utility/source_location.h"
17 template<
typename Alloc,
typename Container>
31 explicit debug(Container& container)
32 noexcept(std::is_nothrow_default_constructible_v<Alloc>) :
33 m_Container(container),
39 template<
typename... Args,
40 typename = std::enable_if_t<
41 std::is_constructible_v<Alloc, Args...>>>
42 explicit debug(Container& container, Args&&... args)
43 noexcept(std::is_nothrow_constructible_v<Alloc, Args...>) :
44 m_Container(container),
45 m_Alloc(std::forward<Args>(args)...) {}
58 return m_Alloc == rhs.m_Alloc;
64 return m_Alloc != rhs.m_Alloc;
67#pragma region Allocation
74 noexcept(detail::has_nothrow_allocate_v<Alloc>)
76#ifdef KTL_SOURCE_LOCATION
77 m_Container.push_back({ source.file_name(), source.line(), n });
91 m_Alloc.deallocate(p, n);
95#pragma region Construction
103 template<
typename T,
typename... Args>
108 m_Alloc.construct(p, std::forward<Args>(args)...);
117 typename std::enable_if<detail::has_destroy_v<Alloc, T*>,
void>::type
125#pragma region Utility
131 template<
typename A = Alloc>
132 typename std::enable_if<detail::has_max_size_v<A>,
size_type>::type
134 noexcept(detail::has_nothrow_max_size_v<A>)
136 return m_Alloc.max_size();
145 template<
typename A = Alloc>
146 typename std::enable_if<detail::has_owns_v<A>,
bool>::type
150 return m_Alloc.owns(p);
191 Container& m_Container;
Container & get_container() noexcept
Return a reference to the container that will be used to accumulate statistics.
Definition debug.h:176
bool operator==(const debug &rhs) const noexcept(detail::has_nothrow_equal_v< Alloc >)
Definition debug.h:55
const Alloc & get_allocator() const noexcept
Returns a const reference to the underlying allocator.
Definition debug.h:167
debug(Container &container) noexcept(std::is_nothrow_default_constructible_v< Alloc >)
Construct the allocator with a reference to a container object.
Definition debug.h:31
debug & operator=(const debug &)=default
void deallocate(void *p, size_type n) noexcept(detail::has_nothrow_deallocate_v< Alloc >)
Attempts to deallocate the memory at location p.
Definition debug.h:88
debug(const debug &)=default
detail::get_size_type_t< Alloc > size_type
Definition debug.h:24
Alloc & get_allocator() noexcept
Returns a reference to the underlying allocator.
Definition debug.h:158
std::enable_if< detail::has_destroy_v< Alloc, T * >, void >::type destroy(T *p) noexcept(detail::has_nothrow_destroy_v< Alloc, T * >)
Destructs an object of T at the given location.
Definition debug.h:118
std::enable_if< detail::has_owns_v< A >, bool >::type owns(void *p) const noexcept(detail::has_nothrow_owns_v< A >)
Returns whether or not the allocator owns the given location in memory.
Definition debug.h:147
bool operator!=(const debug &rhs) const noexcept(detail::has_nothrow_not_equal_v< Alloc >)
Definition debug.h:61
std::enable_if< detail::has_max_size_v< A >, size_type >::type max_size() const noexcept(detail::has_nothrow_max_size_v< A >)
Returns the maximum size that an allocation can be.
Definition debug.h:133
void * allocate(size_type n, const source_location &source=KTL_SOURCE()) noexcept(detail::has_nothrow_allocate_v< Alloc >)
Attempts to allocate a chunk of memory defined by n.
Definition debug.h:73
debug(Container &container, Args &&... args) noexcept(std::is_nothrow_constructible_v< Alloc, Args... >)
Constructor for forwarding any arguments to the underlying allocator.
Definition debug.h:42
std::enable_if< detail::has_construct_v< Alloc, T *, Args... >, void >::type construct(T *p, Args &&... args) noexcept(detail::has_nothrow_construct_v< Alloc, T *, Args... >)
Constructs an object of T with the given ...args at the given location.
Definition debug.h:105
const Container & get_container() const noexcept
Return a const reference to the container that will be used to accumulate statistics.
Definition debug.h:185
debug & operator=(debug &&)=default
#define KTL_EMPTY_BASE
Definition empty_base.h:6
typename get_size_type< Alloc, void >::type get_size_type_t
Definition meta.h:33
constexpr bool has_nothrow_construct_v
Definition meta.h:123
constexpr bool has_construct_v
Definition meta.h:53
void * allocate(Alloc &alloc, size_t n, const source_location source) noexcept(false)
Definition meta.h:161
constexpr bool has_no_value_type_v
Definition meta.h:17
Definition cascading.h:16
#define KTL_SOURCE()
Definition source_location.h:11
Definition source_location.h:19