From cf7db48c261ee9c896c813a38ff8c59da5b8fe07 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sun, 26 Jan 2025 00:40:51 +0100 Subject: Fix line endings --- asl/allocator.hpp | 116 +++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'asl/allocator.hpp') diff --git a/asl/allocator.hpp b/asl/allocator.hpp index 265378b..90793dd 100644 --- a/asl/allocator.hpp +++ b/asl/allocator.hpp @@ -1,58 +1,58 @@ -#pragma once - -#include "asl/layout.hpp" -#include "asl/meta.hpp" -#include "asl/memory.hpp" - -namespace asl -{ - -template -concept allocator = moveable && equality_comparable && - requires(T& alloc, layout layout, void* ptr) - { - { alloc.alloc(layout) } -> same_as; - { alloc.realloc(ptr, layout, layout) } -> same_as; - alloc.dealloc(ptr, layout); - }; - -class GlobalHeap -{ -public: - static void* alloc(const layout&); - static void* realloc(void* ptr, const layout& old, const layout& new_layout); - static void dealloc(void* ptr, const layout&); - - constexpr bool operator==(const GlobalHeap&) const { return true; } -}; -static_assert(allocator); - -using DefaultAllocator = GlobalHeap; - -template -T* alloc_new(allocator auto& a, auto&&... args) -{ - void* ptr = a.alloc(layout::of()); - return construct_at(ptr, ASL_FWD(args)...); -} - -template -void alloc_delete(allocator auto& a, T* ptr) -{ - destroy(ptr); - a.dealloc(ptr, layout::of()); -} - -template -constexpr T* alloc_new_default(auto&&... args) -{ - return alloc_new(DefaultAllocator{}, ASL_FWD(args)...); -} - -template -void alloc_delete_default(T* ptr) -{ - alloc_delete(DefaultAllocator{}, ptr); -} - -} // namespace asl +#pragma once + +#include "asl/layout.hpp" +#include "asl/meta.hpp" +#include "asl/memory.hpp" + +namespace asl +{ + +template +concept allocator = moveable && equality_comparable && + requires(T& alloc, layout layout, void* ptr) + { + { alloc.alloc(layout) } -> same_as; + { alloc.realloc(ptr, layout, layout) } -> same_as; + alloc.dealloc(ptr, layout); + }; + +class GlobalHeap +{ +public: + static void* alloc(const layout&); + static void* realloc(void* ptr, const layout& old, const layout& new_layout); + static void dealloc(void* ptr, const layout&); + + constexpr bool operator==(const GlobalHeap&) const { return true; } +}; +static_assert(allocator); + +using DefaultAllocator = GlobalHeap; + +template +T* alloc_new(allocator auto& a, auto&&... args) +{ + void* ptr = a.alloc(layout::of()); + return construct_at(ptr, ASL_FWD(args)...); +} + +template +void alloc_delete(allocator auto& a, T* ptr) +{ + destroy(ptr); + a.dealloc(ptr, layout::of()); +} + +template +constexpr T* alloc_new_default(auto&&... args) +{ + return alloc_new(DefaultAllocator{}, ASL_FWD(args)...); +} + +template +void alloc_delete_default(T* ptr) +{ + alloc_delete(DefaultAllocator{}, ptr); +} + +} // namespace asl -- cgit