evolution(#967): simplify by variadic arguments

This commit is contained in:
Fischlurch 2016-02-06 22:17:48 +01:00
parent a7cd8996aa
commit 9515e45723
2 changed files with 28 additions and 152 deletions

View file

@ -72,6 +72,7 @@
#include "lib/access-casted.hpp"
#include "lib/util.hpp"
#include <utility>
#include <type_traits>
#include <boost/noncopyable.hpp>
@ -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<class TY>
template<class TY, typename...ARGS>
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> (args)...);
}
catch (...)
{
placeDefault();
throw;
}
}
template<class TY, typename A1>
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 === */

View file

@ -72,10 +72,10 @@
#include "include/logging.h"
#include <utility>
#include <memory>
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<XX> slot = allocateSlot<XX>(); \
try \
{ \
return slot.build (new(slot.storage_) _CTOR_ ); \
} \
catch(...) \
{ \
releaseSlot<XX>(slot.storage_); \
throw; \
template< class XX, typename...ARGS>
shared_ptr<XX>
create (ARGS&& ...args)
{
Slot<XX> slot = allocateSlot<XX>();
try {
return slot.build (new(slot.storage_) XX (std::forward<ARGS> (args)...) );
}
catch(...)
{
releaseSlot<XX>(slot.storage_);
throw;
}
template< class XX>
shared_ptr<XX> //_____________________
create () ///< invoke default ctor
{
_EXCEPTION_SAFE_INVOKE ( XX() )
}
template< class XX, typename P1>
shared_ptr<XX> //___________________
create (P1& p1) ///< invoke 1-arg ctor
{
_EXCEPTION_SAFE_INVOKE ( XX (p1) )
}
template< class XX
, typename P1
, typename P2
>
shared_ptr<XX> //___________________
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<XX> //___________________
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<XX> //___________________
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<XX> //___________________
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<class XX>