12 #include "internal/traits.hpp"
13 #include "internal/array_creation_evaluator.hpp"
14 #include "stl_allocator_adapter.hpp"
16 #include <type_traits>
21 inline namespace v_100 {
52 block &operator=(
const block &x) noexcept =
default;
75 explicit operator bool()
const
80 bool operator==(
const block &rhs)
const
82 return ptr == rhs.
ptr && length == rhs.
length;
93 template<
class T,
class Allocator,
class... Args>
94 std::shared_ptr<T> make_shared(
const Allocator& alloc, Args&&... args)
97 auto localAllocator = LocalAllocator(alloc);
98 return std::allocate_shared<T, LocalAllocator>(localAllocator, std::forward<Args>(args)...);
106 template <
typename Allocator>
109 Allocator *allocator_;
112 using allocator = Allocator;
114 deleter() : allocator_(
nullptr), extend_(1) {}
120 void set_allocator(Allocator& a)
125 void set_extend(
size_t e)
130 template <
typename U>
131 void operator()(U* p) {
134 for (
auto i = 0u; i < extend_; ++i) { p[i].~U(); }
137 auto realMemoryLocation = (extend_ == 1 || std::is_trivially_destructible<U>::value)? p :
138 (static_cast<void*>(reinterpret_cast<char*>(p) - helpers::array_offset()));
140 block pseudoBlock(realMemoryLocation , 1 );
141 auto size_prefix = allocator_->outer_to_prefix(pseudoBlock);
142 block realBlock(realMemoryLocation, *size_prefix);
143 allocator_->deallocate(realBlock);
148 template<
class T,
typename Allocator>
151 typedef std::unique_ptr<T, deleter<Allocator>> _Single_object;
154 template<
class T,
typename Allocator>
156 typedef std::unique_ptr<T[], deleter<Allocator>> _Unknown_bound;
159 template<
class T,
size_t N,
typename Allocator>
161 typedef void _Known_bound;
164 template<
class T,
class Allocator,
class... Args>
165 typename _Unique_if<T, Allocator>::_Single_object make_unique(Allocator& a, Args&&... args) {
166 auto b = a.allocate(
sizeof(T));
169 auto p = a.outer_to_prefix(b);
170 *p =
static_cast<typename Allocator::prefix
>(b.length);
171 auto result = std::unique_ptr<T, deleter<Allocator>>(
new (b.ptr) T(std::forward<Args>(args)...));
172 result.get_deleter().set_allocator(a);
175 return std::unique_ptr<T, deleter<Allocator>>();
178 template<
class T,
class Allocator>
179 typename _Unique_if<T, Allocator>::_Unknown_bound make_unique(Allocator& a,
size_t n) {
180 typedef typename std::remove_extent<T>::type U;
182 auto b = a.allocate(
sizeof(U) * n + helpers::array_offset());
185 auto p = a.outer_to_prefix(b);
186 *p =
static_cast<typename Allocator::prefix
>(b.length);
187 auto result = std::unique_ptr<U[], deleter<Allocator>>(
new (b.ptr) U[n]);
188 result.get_deleter().set_allocator(a);
189 result.get_deleter().set_extend(n);
192 return std::unique_ptr<T, deleter<Allocator>>();
195 template<
class T,
class Allocator,
class... Args>
196 typename _Unique_if<T, deleter<Allocator>>::_Known_bound make_unique(Allocator&, Args&&...) =
delete;
207 void block_copy(
const block &source, block &destination) noexcept;
217 return n + ((n % basis == 0) ? 0 : (basis - n % basis));
222 using namespace v_100;
void block_copy(const block &source, block &destination) noexcept
size_t length
This describes the length of the reserved bytes.
constexpr size_t round_to_alignment(size_t basis, size_t n) noexcept
void * ptr
This points to the start address of the described memory block.