summaryrefslogtreecommitdiff
path: root/asl/memory.hpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-17 00:21:48 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-17 22:29:50 +0100
commita141c401f78467bc15f62882fca5d55a007cacbb (patch)
tree908ac71a8640f78f45d22c6808c5fa6e373000fa /asl/memory.hpp
parentcb77cbe9ce4cddad6a460aa190ff70f0c13e4703 (diff)
Reorganize everything
Diffstat (limited to 'asl/memory.hpp')
-rw-r--r--asl/memory.hpp137
1 files changed, 0 insertions, 137 deletions
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_t>(size));
-}
-
-constexpr void memcpy(void* dst, const void* src, isize_t size)
-{
- __builtin_memcpy(dst, src, static_cast<size_t>(size));
-}
-
-inline void memzero(void* dst, isize_t size)
-{
- __builtin_memset(dst, 0, static_cast<size_t>(size));
-}
-
-constexpr isize_t strlen(const char* s)
-{
- return static_cast<isize_t>(__builtin_strlen(s));
-}
-
-template<typename T, typename... Args>
-constexpr T* construct_at(void* ptr, Args&&... args)
- requires constructible_from<T, Args&&...>
-{
- return new (ptr) T{ ASL_FWD(args)... };
-}
-
-template<typename T>
-constexpr void destroy(T* data)
-{
- if constexpr (!trivially_destructible<T>)
- {
- data->~T();
- }
-}
-
-template<typename T>
-constexpr void destroy_n(T* data, isize_t n)
-{
- if constexpr (!trivially_destructible<T>)
- {
- for (isize_t i = 0; i < n; ++i)
- {
- destroy(data + i);
- }
- }
-}
-
-template<copy_constructible T>
-constexpr void copy_uninit_n(T* to, const T* from, isize_t n)
-{
- if constexpr (trivially_copy_constructible<T>)
- {
- memcpy(to, from, size_of<T> * n);
- }
- else
- {
- for (isize_t i = 0; i < n; ++i)
- {
- // NOLINTNEXTLINE(*-pointer-arithmetic)
- construct_at<T>(to + i, from[i]);
- }
- }
-}
-
-template<copy_assignable T>
-constexpr void copy_assign_n(T* to, const T* from, isize_t n)
-{
- if constexpr (trivially_copy_constructible<T>)
- {
- memcpy(to, from, size_of<T> * n);
- }
- else
- {
- for (isize_t i = 0; i < n; ++i)
- {
- // NOLINTNEXTLINE(*-pointer-arithmetic)
- to[i] = from[i];
- }
- }
-}
-
-template<move_constructible T>
-constexpr void relocate_uninit_n(T* to, T* from, isize_t n)
-{
- if constexpr (trivially_move_constructible<T>)
- {
- static_assert(trivially_destructible<T>);
- memcpy(to, from, size_of<T> * n);
- }
- else
- {
- for (isize_t i = 0; i < n; ++i)
- {
- // NOLINTNEXTLINE(*-pointer-arithmetic)
- construct_at<T>(to + i, ASL_MOVE(from[i]));
- }
- destroy_n(from, n);
- }
-}
-
-template<move_assignable T>
-constexpr void relocate_assign_n(T* to, T* from, isize_t n)
-{
- if constexpr (trivially_move_assignable<T>)
- {
- static_assert(trivially_destructible<T>);
- memcpy(to, from, size_of<T> * 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
-