X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2Fmpl.hh;h=ba600835869550878313fec6a1093ddd664a286e;hb=9bfe0b87be0926193b5baf13865cf045f0de0b0d;hp=2983ffecc410d9843d85dbb341ffc5d93a9079bb;hpb=21bad90912447cd2d390112cf2d2a7d383ad8058;p=senf.git diff --git a/Utils/mpl.hh b/Utils/mpl.hh index 2983ffe..ba60083 100644 --- a/Utils/mpl.hh +++ b/Utils/mpl.hh @@ -27,6 +27,7 @@ #define HH_mpl_ 1 // Custom includes +#include "../config.hh" //#include "mpl.mpp" #include "mpl.ih" @@ -38,10 +39,6 @@ namespace mpl { /** \defgroup senfmpl Low-level template meta programming helpers */ -# ifndef SENF_MPL_RV_ALIGNMENT -# define SENF_MPL_RV_ALIGNMENT 16 -# endif - /** \brief Return-value type used to implement overload selection The senf::mpl::rv type is used together with \ref SENF_MPL_RV() to select template @@ -149,29 +146,29 @@ namespace mpl { */ template struct take_class {}; - /** \brief Define 'previous value' slot + /** \brief Define MPL slot - The 'previous value' macros \ref SENF_MPL_PREVV_DEF(), \ref SENF_MPL_PREVV_SET() and \ref - SENF_MPL_PREVV_GET() provide a facility to get the last unsigned integer value assigned to + The slot macros \ref SENF_MPL_SLOT_DEF(), \ref SENF_MPL_SLOT_SET() and \ref + SENF_MPL_SLOT_GET() provide a facility to get the last unsigned integer value assigned to the slot before the current point in the current class. \code struct Foo { - // Define PREVV slot named 'accum' initialized to 0 - SENF_MPL_PREVV_DEF(accum, 0); + // Define SLOT slot named 'accum' initialized to 0 + SENF_MPL_SLOT_DEF(accum, 0); // Add 2 to 'accum' - SENF_MPL_PREVV_SET(accum, SENF_MPL_PREVV_GET(accum) + 2); + SENF_MPL_SLOT_SET(accum, SENF_MPL_SLOT_GET(accum) + 2); // Multiply 'accum' by 3 - SENF_MPL_PREVV_SET(accum, SENF_MPL_PREVV_GET(accum) * 3); + SENF_MPL_SLOT_SET(accum, SENF_MPL_SLOT_GET(accum) * 3); // Define the result as a constant expression. result is now 6 - static unsigned result = SENF_MPL_PREVV_GET(accum); + static unsigned result = SENF_MPL_SLOT_GET(accum); }; \endcode Of course, it does not make sense to use these macros for simple arithmetic as in the - example. The SENF_MPL_PREVV macros allow to define macros which pass information from one + example. The SENF_MPL_SLOT macros allow to define macros which pass information from one macro invocation to the next. \implementation The implementation is based on __LINE__: We check backwards for a value @@ -180,26 +177,27 @@ namespace mpl { \ingroup senfmpl \hideinitializer */ -# define SENF_MPL_PREVV_DEF(name,value) \ - template \ - static senf::mpl::rv<0> _SENF_MPL_PREVV_ ## name (senf::mpl::rv<_> *); \ - SENF_MPL_PREVV_SET(name,value) +# define SENF_MPL_SLOT_DEF(name,value) \ + template \ + static senf::mpl::rv<0> _SENF_MPL_SLOT_ ## name (_); \ + SENF_MPL_SLOT_SET(name,value) - /** \brief Set 'prevision value' slot - \see \ref SENF_MPL_PREVV_DEF() + /** \brief Set MPL slot + \see \ref SENF_MPL_SLOT_DEF() \ingroup senfmpl \hideinitializer */ -# define SENF_MPL_PREVV_SET(name,value) \ - static senf::mpl::rv _SENF_MPL_PREVV_ ## name (senf::mpl::rv<__LINE__>*) +# define SENF_MPL_SLOT_SET(name,value) \ + static senf::mpl::rv \ + _SENF_MPL_SLOT_ ## name (senf::mpl::take_int<__LINE__>) - /** \brief Get current 'previous value' slot value - \see \ref SENF_MPL_PREVV_DEF() + /** \brief Get current MPL slot value + \see \ref SENF_MPL_SLOT_DEF() \ingroup senfmpl \hideinitializer */ -# define SENF_MPL_PREVV_GET(name) \ - SENF_MPL_PREVV_I_GET(name) +# define SENF_MPL_SLOT_GET(name) \ + SENF_MPL_SLOT_I_GET(name) }}