From 7eaba3c1b3491da8eeb492189ec0baf6f891bf09 Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 1 Oct 2021 19:08:19 +0100 Subject: [PATCH] Added `aligned_ptr::container_address([const] Self&) -> [const] Self*` to offset the overloaded unary & and avoid need of `std::addressof`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for cpprng's current commit: Future curse − 末凶 --- include/mem.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/mem.h b/include/mem.h index 5fcde1c..f1f9d01 100644 --- a/include/mem.h +++ b/include/mem.h @@ -43,6 +43,13 @@ namespace mem template static inline void dealloc(T* ptr) { H::delete_object(&ptr); if(ptr) _dealloc(reinterpret_cast(ptr)); } + + template + requires (!std::is_same::value) + inline static const aligned_ptr* container_address(const aligned_ptr& ptr) { return aligned_ptr::container_address(ptr); } + template + requires (!std::is_same::value) + inline static aligned_ptr* container_address( aligned_ptr& ptr) { return aligned_ptr::container_address(ptr); } private: static void* _alloc(usize align, usize size); static void _dealloc(void* ptr); @@ -85,6 +92,9 @@ namespace mem inline operator const T&() const { return get(); } inline operator T&() { return get(); } + inline static const aligned_ptr* container_address(const aligned_ptr& ptr) { return ptr._this_addr(); } + inline static aligned_ptr* container_address( aligned_ptr& ptr) { return ptr._this_addr(); } + inline aligned_ptr& operator=(aligned_ptr&& other) { if(ptr) aligned_ptr_util::dealloc(ptr); @@ -94,6 +104,9 @@ namespace mem return *this; } private: + inline aligned_ptr* _this_addr() { return this; } + inline const aligned_ptr* _this_addr() const { return this; } + inline aligned_ptr& operator=(const aligned_ptr& other) { return (*this = other.clone());