diff --git a/src/lib/several-builder.hpp b/src/lib/several-builder.hpp index 5ba131650..fc546636f 100644 --- a/src/lib/several-builder.hpp +++ b/src/lib/several-builder.hpp @@ -156,6 +156,8 @@ namespace lib { using Fac::Fac; // pass-through ctor const bool isDisposable{false}; ///< memory must be explicitly deallocated + + bool canExpand(size_t){ return false; } Bucket* realloc (Bucket* data, size_t demand) @@ -217,12 +219,12 @@ namespace lib { using lib::meta::is_Subclass; template - struct MemStrategy + struct HandlingStrategy { bool disposable :1 ; bool wild_move :1 ; - MemStrategy (bool unmanaged) + HandlingStrategy (bool unmanaged) : disposable{unmanaged or (is_trivially_destructible_v and is_trivially_destructible_v)} , wild_move{false} @@ -257,7 +259,7 @@ namespace lib { bool canDestroy() { - return disposable + return (disposable and is_trivially_destructible_v) or (is_trivially_destructible_v and is_trivially_destructible_v) or (has_virtual_destructor_v and is_Subclass()) or (is_same_v and is_Subclass()); @@ -267,8 +269,7 @@ namespace lib { bool canDynGrow() { - return is_same_v - or (is_trivially_move_constructible_v and wild_move); + return is_same_v or wild_move; } auto @@ -299,7 +300,7 @@ namespace lib { { using Coll = Several; - MemStrategy memStrategy_{POL::isDisposable}; + HandlingStrategy handling_{POL::isDisposable}; public: SeveralBuilder() = default; @@ -397,31 +398,34 @@ namespace lib { void emplaceElm (ARGS&& ...args) { - if (not memStrategy_.template canDestroy()) + if (not handling_.template canDestroy()) throw err::Invalid{_Fmt{"Unable to handle destructor for element type %s"} % util::typeStr()}; // mark acceptance of trivially movable arbitrary data types - if (not memStrategy_.template markWildMovePossibility()) + if (not handling_.template markWildMovePossibility()) throw err::Invalid{_Fmt{"Unable to trivially move element type %s, " "while other elements in this container are trivially movable."} % util::typeStr()}; - ////////////////////////////////////OOO check here for suitable spread + // ensure sufficient element capacity or the ability to adapt element spread + if (Coll::spread() < sizeof(TY) and not (Coll::empty() or handling_.wild_move)) + throw err::Invalid{_Fmt{"Unable to place element of type %s (size=%d)" + "into container for element size %d."} + % util::typeStr() % sizeof(TY) % Coll::spread()}; - ////////////////////////////////////OOO check here for sufficient space + // ensure sufficient storage or verify the ability to re-allocate + if (not (Coll::hasReserve(sizeof(TY)) + or POL::canExpand(sizeof(TY)) + or handling_.template canDynGrow())) + throw err::Invalid{_Fmt{"Unable to accommodate further element of type %s "} + % util::typeStr()}; size_t elmSiz = sizeof(TY); size_t newCnt = Coll::size()+1; - adjustStorage (newCnt, requiredSpread(elmSiz)); + adjustStorage (newCnt, max (elmSiz, Coll::spread())); Coll::data_->cnt = newCnt; - POL::template createAt (Coll::data_, Coll::size(), forward (args)...); - } - - size_t - requiredSpread (size_t elmSiz) - { - return util::max (Coll::spread(), elmSiz); + POL::template createAt (Coll::data_, newCnt-1, forward (args)...); } }; diff --git a/src/lib/several.hpp b/src/lib/several.hpp index 380e2fd21..e7f600652 100644 --- a/src/lib/several.hpp +++ b/src/lib/several.hpp @@ -188,6 +188,15 @@ namespace lib { return data_? data_->spread : sizeof(I); } + bool + hasReserve (size_t extraSize) const + { + if (extraSize > spread()) + extraSize += (extraSize - spread())*size(); + return data_ + and data_->buffSiz >= size()*spread() + extraSize; + } + private: void discardData() diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index e5e5af37f..f475a5b26 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -82444,6 +82444,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + @@ -82575,6 +82578,33 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + +

+ die grundsätzliche Möglichkeit der Anpassung ist bereits vorher sichergestellt, denn der veranlassende API-call wäre sonst schon per Exception abgebrochen worden +

+ + +
+ +
+
+ + + + + + + @@ -82673,7 +82703,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -82707,15 +82737,28 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + + + + + + + + + + + + + + + + + - - -