diff --git a/src/lib/opaque-holder.hpp b/src/lib/opaque-holder.hpp index ec8e418ab..4528c8240 100644 --- a/src/lib/opaque-holder.hpp +++ b/src/lib/opaque-holder.hpp @@ -72,6 +72,7 @@ #include "lib/access-casted.hpp" #include "lib/util.hpp" +#include #include #include @@ -614,86 +615,24 @@ namespace lib { /** Abbreviation for placement new */ -#define LIB_InPlaceBuffer_CTOR(_CTOR_CALL_) \ - destroy(); \ - try \ - { \ - static_assert (siz >= sizeof(TY), "InPlaceBuffer to small");\ - \ - return *new(&buf_) _CTOR_CALL_; \ - } \ - catch (...) \ - { \ - placeDefault(); \ - throw; \ - } - - - template + template TY& - create () + create (ARGS&& ...args) { - LIB_InPlaceBuffer_CTOR ( TY() ) + static_assert (siz >= sizeof(TY), "InPlaceBuffer to small"); + + destroy(); + try { + return *new(&buf_) TY (std::forward (args)...); + } + catch (...) + { + placeDefault(); + throw; + } } - template - TY& //___________________________________________ - create (A1& a1) ///< place object of type TY, using 1-arg ctor - { - LIB_InPlaceBuffer_CTOR ( TY(a1) ) - } - - - template< class TY - , typename A1 - , typename A2 - > - TY& //___________________________________________ - create (A1& a1, A2& a2) ///< place object of type TY, using 2-arg ctor - { - LIB_InPlaceBuffer_CTOR ( TY(a1,a2) ) - } - - - template< class TY - , typename A1 - , typename A2 - , typename A3 - > - TY& //___________________________________________ - create (A1& a1, A2& a2, A3& a3) ///< place object of type TY, using 3-arg ctor - { - LIB_InPlaceBuffer_CTOR ( TY(a1,a2,a3) ) - } - - - template< class TY - , typename A1 - , typename A2 - , typename A3 - , typename A4 - > - TY& //___________________________________________ - create (A1& a1, A2& a2, A3& a3, A4& a4) ///< place object of type TY, using 4-arg ctor - { - LIB_InPlaceBuffer_CTOR ( TY(a1,a2,a3,a4) ) - } - - - template< class TY - , typename A1 - , typename A2 - , typename A3 - , typename A4 - , typename A5 - > - TY& //___________________________________________ - create (A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) ///< place object of type TY, using 5-arg ctor - { - LIB_InPlaceBuffer_CTOR ( TY(a1,a2,a3,a4,a5) ) - } - /* === smart-ptr style access === */ diff --git a/src/lib/typed-allocation-manager.hpp b/src/lib/typed-allocation-manager.hpp index a9b2c6f18..036a8aee0 100644 --- a/src/lib/typed-allocation-manager.hpp +++ b/src/lib/typed-allocation-manager.hpp @@ -72,10 +72,10 @@ #include "include/logging.h" +#include #include - namespace lib { using std::shared_ptr; @@ -170,94 +170,31 @@ namespace lib { friend class TypedAllocationManager; }; - + /* ==== build objects with managed allocation ==== */ -#define _EXCEPTION_SAFE_INVOKE(_CTOR_) \ - \ - Slot slot = allocateSlot(); \ - try \ - { \ - return slot.build (new(slot.storage_) _CTOR_ ); \ - } \ - catch(...) \ - { \ - releaseSlot(slot.storage_); \ - throw; \ + template< class XX, typename...ARGS> + shared_ptr + create (ARGS&& ...args) + { + Slot slot = allocateSlot(); + try { + return slot.build (new(slot.storage_) XX (std::forward (args)...) ); + } + catch(...) + { + releaseSlot(slot.storage_); + throw; } - - template< class XX> - shared_ptr //_____________________ - create () ///< invoke default ctor - { - _EXCEPTION_SAFE_INVOKE ( XX() ) } - template< class XX, typename P1> - shared_ptr //___________________ - create (P1& p1) ///< invoke 1-arg ctor - { - _EXCEPTION_SAFE_INVOKE ( XX (p1) ) - } - template< class XX - , typename P1 - , typename P2 - > - shared_ptr //___________________ - create (P1& p1, P2& p2) ///< invoke 2-arg ctor - { - _EXCEPTION_SAFE_INVOKE ( XX (p1,p2) ) - } - template< class XX - , typename P1 - , typename P2 - , typename P3 - > - shared_ptr //___________________ - create (P1& p1, P2& p2, P3& p3) ///< invoke 3-arg ctor - { - _EXCEPTION_SAFE_INVOKE ( XX (p1,p2,p3) ) - } - - - template< class XX - , typename P1 - , typename P2 - , typename P3 - , typename P4 - > - shared_ptr //___________________ - create (P1& p1, P2& p2, P3& p3, P4& p4) ///< invoke 4-arg ctor - { - _EXCEPTION_SAFE_INVOKE ( XX (p1,p2,p3,p4) ) - } - - - template< class XX - , typename P1 - , typename P2 - , typename P3 - , typename P4 - , typename P5 - > - shared_ptr //___________________ - create (P1& p1, P2& p2, P3& p3, P4& p4, P5& p5) ///< invoke 5-arg ctor - { - _EXCEPTION_SAFE_INVOKE ( XX (p1,p2,p3,p4,p5) ) - } - -#undef _EXCEPTION_SAFE_INVOKE - - - - protected: /* ======= Managed Allocation Implementation ========== */ template