Template meta programming helpers


Classes

struct   senf::mpl::nil
  Marker class for empty default values etc. More...
struct   senf::mpl::rv< n >
  Return-value type used to implement overload selection. More...
struct   senf::mpl::take_uint< _ >
  Take an arbitrary unsigned integer template argument. More...
struct   senf::mpl::take_int< _ >
  Take an arbitrary integer template argument. More...
struct   senf::mpl::take_class< _ >
  Take an arbitrary type template argument. More...

Defines

#define  SENF_MPL_RV(expr)
  Get return value of overload selector.
#define  SENF_MPL_SLOT_DEF(name, value)
  Define MPL slot.
#define  SENF_MPL_SLOT_SET(name, value)
  Set MPL slot.
#define  SENF_MPL_SLOT_GET(name)
  Get current MPL slot value.

Define Documentation

#define
SENF_MPL_RV ( expr  )

Get return value of overload selector.

Used together with senf::mpl::rv to implement overload selection.

See also:
senf::mpl::rv

Definition at line 128 of file mpl.hh.

#define
SENF_MPL_SLOT_DEF ( name,
value  )

Define MPL slot.

The slot macros SENF_MPL_SLOT_DEF(), SENF_MPL_SLOT_SET() and 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.

struct Foo
{
    // Define SLOT slot named 'accum' initialized to 0
    SENF_MPL_SLOT_DEF(accum, 0);

    // Add 2 to 'accum'
    SENF_MPL_SLOT_SET(accum, SENF_MPL_SLOT_GET(accum) + 2);

    // Multiply 'accum' by 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_SLOT_GET(accum);
};
Of course, it does not make sense to use these macros for simple arithmetic as in the example. The SENF_MPL_SLOT macros allow to define macros which pass information from one macro invocation to the next.
Implementation note:
The implementation is based on __LINE__: We check backwards for a value defined on a previous line. The check is limited to 80 lines backwards.

Definition at line 192 of file mpl.hh.

#define
SENF_MPL_SLOT_GET ( name  )

Get current MPL slot value.

See also:
SENF_MPL_SLOT_DEF()

Definition at line 222 of file mpl.hh.

#define
SENF_MPL_SLOT_SET ( name,
value  )

Set MPL slot.

See also:
SENF_MPL_SLOT_DEF()

Definition at line 213 of file mpl.hh.