KTL
Loading...
Searching...
No Matches
null_allocator.h
Go to the documentation of this file.
1#pragma once
2
3#include "../utility/assert.h"
4
5namespace ktl
6{
12 {
13 public:
14 null_allocator() noexcept = default;
15
16 null_allocator(const null_allocator&) noexcept = default;
17
18 null_allocator(null_allocator&&) noexcept = default;
19
20 null_allocator& operator=(const null_allocator&) noexcept = default;
21
22 null_allocator& operator=(null_allocator&&) noexcept = default;
23
24 bool operator==(const null_allocator& rhs) const noexcept
25 {
26 return true;
27 }
28
29 bool operator!=(const null_allocator& rhs) const noexcept
30 {
31 return false;
32 }
33
34#pragma region Allocation
35 void* allocate(size_t n) noexcept
36 {
37 return nullptr;
38 }
39
40 void deallocate(void* p, size_t n) noexcept
41 {
42 KTL_ASSERT(p == nullptr);
43 }
44#pragma endregion
45
46#pragma region Utility
47 bool owns(void* p) const noexcept
48 {
49 return p == nullptr;
50 }
51#pragma endregion
52 };
53}
#define KTL_ASSERT(x)
Definition assert.h:17
An allocator which does nothing. Useful for debugging composite allocators, like ensuring a specific ...
Definition null_allocator.h:12
null_allocator() noexcept=default
bool owns(void *p) const noexcept
Definition null_allocator.h:47
void deallocate(void *p, size_t n) noexcept
Definition null_allocator.h:40
void * allocate(size_t n) noexcept
Definition null_allocator.h:35
bool operator!=(const null_allocator &rhs) const noexcept
Definition null_allocator.h:29
Definition cascading.h:16