From 2cd972bb3eed7886a6b1d0d1b3ead24c8cf3fe4f Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sat, 24 Aug 2024 11:53:39 +0200 Subject: More work --- asl/ptr.hpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 5 deletions(-) (limited to 'asl/ptr.hpp') diff --git a/asl/ptr.hpp b/asl/ptr.hpp index 2d90e7b..9065e74 100644 --- a/asl/ptr.hpp +++ b/asl/ptr.hpp @@ -2,9 +2,33 @@ #include "asl/integers.hpp" #include "asl/meta.hpp" +#include "asl/utility.hpp" namespace asl { + +// @Todo Shitty span, improve this +template +struct span +{ + static constexpr bool kDynamic = kLen < 0; + + using size_type = select_t; + + constexpr span(T* begin, isize_t len) requires kDynamic + : m_begin{begin} + , m_len{len} + {} + + constexpr span(T* begin) requires (!kDynamic) + : m_begin{begin} + , m_len{} + {} + + T* m_begin; + ASL_NO_UNIQUE_ADDRESS size_type m_len; +}; + namespace ptr_internal { @@ -13,23 +37,37 @@ struct void_metadata { using metadata = empty; using pointee = T; + + constexpr auto deref(pointee* ptr) { return ptr; } }; template struct array_metadata {}; -template +template struct array_metadata { using metadata = isize_t; using pointee = T; + + constexpr auto deref(pointee* ptr) + { + return span(ptr, m_len); + } + + isize_t m_len; }; -template +template struct array_metadata { using metadata = empty; using pointee = T[N]; + + constexpr auto deref(pointee* ptr) + { + return span(static_cast(*ptr)); + } }; template @@ -37,20 +75,26 @@ struct object_metadata { using metadata = empty; using pointee = T; + + constexpr auto deref(pointee* ptr) { return ptr; } }; template struct func_metadata { using metadata = empty; - using pointee = tame_t*; + using pointee = tame_t* const; + + constexpr auto deref(pointee* ptr) { return *ptr; } }; template struct ref_metadata { using metadata = empty; - using pointee = un_ref_t*; + using pointee = un_ref_t* const; + + constexpr auto deref(pointee* ptr) { return *ptr; } }; template void_metadata select_ptr_metadata(types); @@ -65,10 +109,25 @@ using metadata = decltype(select_ptr_metadata(types{})); } // namespace ptr_internal template -concept ptr_metadata = requires +concept ptr_metadata = requires (T metadata, typename T::pointee* ptr) { is_object; is_object; + + { metadata.deref(ptr) }; +}; + +template +class ptr +{ + using meta = ptr_internal::metadata; + static_assert(ptr_metadata); + + meta::pointee* m_ptr; + ASL_NO_UNIQUE_ADDRESS meta m_meta; + +public: + }; } // namespace asl -- cgit