From a141c401f78467bc15f62882fca5d55a007cacbb Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 17 Feb 2025 00:21:48 +0100 Subject: Reorganize everything --- asl/memory.hpp | 137 --------------------------------------------------------- 1 file changed, 137 deletions(-) delete mode 100644 asl/memory.hpp (limited to 'asl/memory.hpp') diff --git a/asl/memory.hpp b/asl/memory.hpp deleted file mode 100644 index 5a73d26..0000000 --- a/asl/memory.hpp +++ /dev/null @@ -1,137 +0,0 @@ -#pragma once - -#include "asl/integers.hpp" -#include "asl/meta.hpp" -#include "asl/layout.hpp" -#include "asl/utility.hpp" - -constexpr void* operator new(size_t, void* ptr) -{ - return ptr; -} - -namespace asl -{ - -constexpr isize_t memcmp(const void* a, const void* b, isize_t size) -{ - return __builtin_memcmp(a, b, static_cast(size)); -} - -constexpr void memcpy(void* dst, const void* src, isize_t size) -{ - __builtin_memcpy(dst, src, static_cast(size)); -} - -inline void memzero(void* dst, isize_t size) -{ - __builtin_memset(dst, 0, static_cast(size)); -} - -constexpr isize_t strlen(const char* s) -{ - return static_cast(__builtin_strlen(s)); -} - -template -constexpr T* construct_at(void* ptr, Args&&... args) - requires constructible_from -{ - return new (ptr) T{ ASL_FWD(args)... }; -} - -template -constexpr void destroy(T* data) -{ - if constexpr (!trivially_destructible) - { - data->~T(); - } -} - -template -constexpr void destroy_n(T* data, isize_t n) -{ - if constexpr (!trivially_destructible) - { - for (isize_t i = 0; i < n; ++i) - { - destroy(data + i); - } - } -} - -template -constexpr void copy_uninit_n(T* to, const T* from, isize_t n) -{ - if constexpr (trivially_copy_constructible) - { - memcpy(to, from, size_of * n); - } - else - { - for (isize_t i = 0; i < n; ++i) - { - // NOLINTNEXTLINE(*-pointer-arithmetic) - construct_at(to + i, from[i]); - } - } -} - -template -constexpr void copy_assign_n(T* to, const T* from, isize_t n) -{ - if constexpr (trivially_copy_constructible) - { - memcpy(to, from, size_of * n); - } - else - { - for (isize_t i = 0; i < n; ++i) - { - // NOLINTNEXTLINE(*-pointer-arithmetic) - to[i] = from[i]; - } - } -} - -template -constexpr void relocate_uninit_n(T* to, T* from, isize_t n) -{ - if constexpr (trivially_move_constructible) - { - static_assert(trivially_destructible); - memcpy(to, from, size_of * n); - } - else - { - for (isize_t i = 0; i < n; ++i) - { - // NOLINTNEXTLINE(*-pointer-arithmetic) - construct_at(to + i, ASL_MOVE(from[i])); - } - destroy_n(from, n); - } -} - -template -constexpr void relocate_assign_n(T* to, T* from, isize_t n) -{ - if constexpr (trivially_move_assignable) - { - static_assert(trivially_destructible); - memcpy(to, from, size_of * n); - } - else - { - for (isize_t i = 0; i < n; ++i) - { - // NOLINTNEXTLINE(*-pointer-arithmetic) - to[i] = ASL_MOVE(from[i]); - } - destroy_n(from, n); - } -} - -} // namespace asl - -- cgit