From 0e2ca6ee1ce557f190075b0445044825d7e086b7 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 6 Jun 2024 21:13:50 +0200 Subject: [PATCH] =?UTF-8?q?Library:=20consider=20to=20align=20this=20with?= =?UTF-8?q?=20the=20=C2=BBFactory=C2=AB=20concept?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit even while at first sight only a ''deleter instance'' is required, it seems prudent to rearrange the code in accordance to the prospective Allocator / Object Factory concept, and rather try to incorporate the specifics of the memory layout into this generic view, thereby abstracting the actual allocator away. This can be achieved by using a standard-allocator for `std::byte` as the base allocator and treat each individual element allocator as a specialised cross-allocator (assuming that this cross adaptation is actually trivial in almost all cases) --- src/lib/several-builder.hpp | 32 ++++++++++++++++++++------------ wiki/thinkPad.ichthyo.mm | 12 +++++++++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/lib/several-builder.hpp b/src/lib/several-builder.hpp index 4da1e1e12..8c3309a0e 100644 --- a/src/lib/several-builder.hpp +++ b/src/lib/several-builder.hpp @@ -73,36 +73,44 @@ namespace lib { - template - struct DeleterTrampoline + template class ALO> + struct ElementFactory + : private ALO { - using Allo = std::allocator; + using Allo = ALO; using AlloT = std::allocator_traits; + Allo& baseAllocator() { return *this; } + template - static auto + auto adaptAllocator() { using XAllo = typename AlloT::template rebind_alloc; if constexpr (std::is_constructible_v) - return XAllo{Allo()}; + return XAllo{baseAllocator()}; else return XAllo{}; } - static void + ElementFactory (Allo allo = Allo{}) + : Allo{std::move (allo)} + { } + + template + void destroy (ArrayBucket* bucket, size_t size) { - Allo allo{}; + REQUIRE (bucket); + using ElmAlloT = typename AlloT::template rebind_traits; + auto elmAllo = adaptAllocator(); for (size_t i=0; isubscript(i)); + ElmAlloT::destroy (elmAllo, & bucket->subscript(i)); size_t storageBytes = sizeof(ArrayBucket) - sizeof(ArrayBucket::storage) - + size * sizeof(E); + + size * bucket->spread; - using BAlloT = typename AlloT::template rebind_traits; - auto bAllo = adaptAllocator(); - BAlloT::deallocate (bAllo, bucket, storageBytes); + AlloT::deallocate (baseAllocator(), bucket, storageBytes); }; }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index d0c69aaba..6d8fab0e4 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -81975,6 +81975,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + @@ -82231,7 +82236,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -82251,6 +82256,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + +