Boost logo

Boost Users :

From: Andry (andry_at_[hidden])
Date: 2007-11-08 14:22:25


Hello boost-users,

  You can download sources here:
  https://sourceforge.net/project/showfiles.php?group_id=198908&package_id=243070&release_id=552700

  Main idea of this update is to add new macros
  BOOST_PP_MACRO_IF/BOOST_PP_MACRO_IIF to use BOOST_PP_IF/BOOST_PP_IIF
  more complex when i need to pass in multiple arguments like what:

///////////////////////////////////////////////////////////////////////////////
//The same as BOOST_PP_IDENTITY, but different
#define MY_PP_EVAL1(x1) x1
#define MY_PP_EVAL2(x1,x2) x1,x2
#define MY_PP_EVAL3(x1,x2,x3) x1,x2,x3
#define MY_PP_EVAL4(x1,x2,x3,x4) x1,x2,x3,x4
#define MY_PP_EVAL5(x1,x2,x3,x4,x5) x1,x2,x3,x4,x5
#define MY_PP_EVAL6(x1,x2,x3,x4,x5,x6) x1,x2,x3,x4,x5,x6

#define n 0 //basically is argument of another macro

// if n == 0 -> //1,2;
// if n != 0 -> //1,2,3;
BOOST_PP_MACRO_IF(n,
  (1,2,3),
  (1,2),
  MY_PP_EVAL3,
  MY_PP_EVAL2);

//More complex usage
// if n == 0 -> //1,2;
// if n == 1 -> //-1,0,1,2,3;
// if n > 1 -> //-1,0,1,2,3,4;
BOOST_PP_MACRO_IF(n,
  (-1,0,
    BOOST_PP_MACRO_IF(BOOST_PP_GREATER(n,1),
      (1,2,3,4),
      (1,2,3),
      MY_PP_EVAL4,
      MY_PP_EVAL3)),
  (1,2),
  BOOST_PP_IF(BOOST_PP_GREATER(n,1),
    MY_PP_EVAL6,
    MY_PP_EVAL5),
  MY_PP_EVAL2);
///////////////////////////////////////////////////////////////////////////////

  I uses it to properly generate template classes implementations.

  PS:
  This is slightly different than BOOST_PP_IF(n, BOOST_PP_IDENTITY(x), BOOST_PP_EMPTY)()
  cause x can have multiple values and used as an expression to subsequent
  macro.
  

-- 
Best regards,
 Andry                          mailto:andry_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net