diff --git a/ostd/memory.hh b/ostd/memory.hh index 066ba96..0f14752 100644 --- a/ostd/memory.hh +++ b/ostd/memory.hh @@ -125,12 +125,12 @@ namespace detail { template struct PointerRebindType { - using type = typename PointerRebindBase::Type; + using Type = typename PointerRebindBase::Type; }; template struct PointerRebindType { - using type = U *; + using Type = U *; }; template @@ -544,108 +544,21 @@ typename detail::BoxIf::BoxKnownSize make_box(A &&...args) = delete; /* allocator */ -template -struct Allocator; - -template<> -struct Allocator { - using Value = void; - using Pointer = void *; - using ConstPointer = void const *; - - template - using Rebind = Allocator; -}; - -template<> -struct Allocator { - using Value = void const; - using Pointer = void const *; - using ConstPointer = void const *; - - template - using Rebind = Allocator; -}; - template struct Allocator { - using Size = ostd::Size; - using Difference = Ptrdiff; using Value = T; - using Reference = T &; - using ConstReference = T const &; - using Pointer = T *; - using ConstPointer = T const *; - - template - using Rebind = Allocator; Allocator() noexcept {} template Allocator(Allocator const &) noexcept {} - Pointer address(Reference v) const noexcept { - return address_of(v); - }; - ConstPointer address(ConstReference v) const noexcept { - return address_of(v); - }; - - Size max_size() const noexcept { return Size(~0) / sizeof(T); } - - Pointer allocate(Size n, Allocator::ConstPointer = nullptr) { - return reinterpret_cast(::new byte[n * sizeof(T)]); + Value *allocate(Size n) { + return reinterpret_cast(::new byte[n * sizeof(T)]); } - void deallocate(Pointer p, Size) noexcept { + void deallocate(Value *p, Size) noexcept { ::delete[] reinterpret_cast(p); } - - template - void construct(U *p, A &&...args) { - ::new(p) U(forward(args)...); - } - - void destroy(Pointer p) noexcept { p->~T(); } -}; - -template -struct Allocator { - using Size = ostd::Size; - using Difference = Ptrdiff; - using Value = T const; - using Reference = T const &; - using ConstReference = T const &; - using Pointer = T const *; - using ConstPointer = T const *; - - template - using Rebind = Allocator; - - Allocator() noexcept {} - template - Allocator(Allocator const &) noexcept {} - - ConstPointer address(ConstReference v) const noexcept { - return address_of(v); - }; - - Size max_size() const noexcept { return Size(~0) / sizeof(T); } - - Pointer allocate(Size n, Allocator::ConstPointer = nullptr) { - return reinterpret_cast(::new byte[n * sizeof(T)]); - } - - void deallocate(Pointer p, Size) noexcept { - ::delete[] reinterpret_cast(p); - } - - template - void construct(U *p, A &&...args) { - ::new(p) U(forward(args)...); - } - - void destroy(Pointer p) noexcept { p->~T(); } }; template