X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2Fmpl.hh;h=5428e1dff73f037613d33c1ed5534c09e1914d8c;hb=28275a1a9075ae42dc29aaadc5bc78e6fa204e26;hp=2983ffecc410d9843d85dbb341ffc5d93a9079bb;hpb=21bad90912447cd2d390112cf2d2a7d383ad8058;p=senf.git
diff --git a/Utils/mpl.hh b/Utils/mpl.hh
index 2983ffe..5428e1d 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"
@@ -35,12 +36,17 @@
namespace senf {
namespace mpl {
- /** \defgroup senfmpl Low-level template meta programming helpers
+ /** \defgroup senfmpl Template meta programming helpers
*/
-# ifndef SENF_MPL_RV_ALIGNMENT
-# define SENF_MPL_RV_ALIGNMENT 16
-# endif
+ /** \brief Marker class for empty default values etc.
+
+ This is like Boosts \c boost::mpl::na just an empty class used as template default argument
+ to mark missing arguments
+
+ \note Don't use this as an empty base class. We may add some informative members to this.
+ */
+ struct nil {};
/** \brief Return-value type used to implement overload selection
@@ -99,8 +105,8 @@ namespace mpl {
never called.
This number is than forwarded as template argument to \c select which is specialized for
- each case. Therefore, choice has a \c frobble() member whereas
- choice has a \c dazzle() member.
+ each case. Therefore, choice\ has a \c frobble() member whereas
+ choice\ has a \c dazzle() member.
\see \ref SENF_MPL_RV
\ingroup senfmpl
@@ -149,29 +155,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 +186,38 @@ 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 Define MPL slot initialized to 0
+
+ This is like \ref SENF_MPL_SLOT_DEF() but initializes the slot to the fixed value 0. The
+ advantage over \ref SENF_MPL_SLOT_DEF() is, that this macro may be called from an include
+ file whereas all the other \\c SENF_MPL_SLOT_ macros must always be called from the relevant
+ file.
+ */
+# define SENF_MPL_SLOT_DEF_ZERO(name) \
+ template \
+ static senf::mpl::rv<0> _SENF_MPL_SLOT_ ## name (_);
- /** \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)
}}