13 #include "allocator_base.hpp"
17 inline namespace v_100 {
19 template <
typename T,
class Allocator>
22 template <
class Allocator>
25 using pointer =
void *;
26 using const_pointer =
const void *;
27 using value_type = void;
28 template <
class U>
struct rebind {
33 template <
typename T,
class Allocator>
35 const Allocator& allocator_;
38 using size_type = size_t;
39 using difference_type = ptrdiff_t;
41 using const_pointer =
const T *;
42 using reference = T &;
43 using const_reference =
const T &;
46 template <
typename U>
struct rebind {
51 : allocator_(allocator)
57 const Allocator& allocator()
const
63 explicit std_allocator_adapter(
const std_allocator_adapter<U, Allocator> &other)
64 : allocator_(other.allocator())
68 pointer address(reference r)
const
73 const_pointer address(const_reference r)
const
78 T *allocate(std::size_t n,
const void * =
nullptr)
80 auto b =
const_cast<Allocator&
>(allocator_).allocate(n *
sizeof(T));
82 auto p = allocator_.outer_to_prefix(b);
84 return static_cast<T *
>(b.ptr);
89 void deallocate(T *ptr, std::size_t n)
91 block pseudoBlock(ptr, n);
92 auto p = allocator_.outer_to_prefix(pseudoBlock);
93 block realBlock(ptr, *p);
94 const_cast<Allocator&
>(allocator_).deallocate(realBlock);
97 size_t max_size()
const
99 return ((
size_t)(-1) /
sizeof(T));
102 void construct(pointer ptr)
104 ::new (static_cast<void *>(ptr)) T;
107 template <class... U>
108 void construct(pointer ptr, U&&... val)
110 ::new (static_cast<void *>(ptr)) T(std::forward<U>(val)...);
113 void destroy(pointer p)
119 template <
class Allocator,
typename T1,
typename T2>
120 bool operator==(
const std_allocator_adapter<T1, Allocator> &,
const std_allocator_adapter<T2, Allocator> &)
125 template <
class Allocator,
typename T1,
typename T2>
126 bool operator!=(
const std_allocator_adapter<T1, Allocator> &x,
const std_allocator_adapter<T2, Allocator> &y)
132 using namespace v_100;