|
Boost : |
From: Vesa Karvonen (vesa.karvonen_at_[hidden])
Date: 2001-05-21 07:54:58
[Replying to my own post.]
From: "Vesa Karvonen" <vesa.karvonen_at_[hidden]>
> Treating the first element as a special case is one way to solve the
problem
> of creating lists. It has the advantage that the enumeration macro
> implementation is slightly simpler. On the other hand, the user then needs
> to implement both the general and the special case macros.
[...]
> However, INC and DEC don't solve the problem of having to use a special
case
> for the first or last element.
Actually, these statements of mine aren't quite that conclusive anymore,
because BOOST_IF(c,THEN,ELSE) makes it possible to avoid the special case
for the first element.
In particular, BOOST_IF now makes it possible to implement a conditional
comma:
#define BOOST_COND_COMMA_FUN(i)\
BOOST_IF(i,BOOST_COMMA_FUN,BOOST_EMPTY_FUN)(i)
This means that the user doesn't have to treat the first element as a
special case:
static const int
integers_from_1_to_100[] =
{
#define ELEMENT(i) BOOST_COND_COMMA_FUN(i) BOOST_INC(i)
BOOST_REPT(100, ELEMENT)
#undef ELEMENT
};
BOOST_IF implementation:
#define BOOST_IF(c,T,E) BOOST_IF##c(T,E)
#define BOOST_IF0(T,E) E
#define BOOST_IF1(T,E) T
#define BOOST_IF2(T,E) T
// ...
#define BOOST_IF256(T,E) T
Open questions:
- Are IF, DEC and INC robust enough for production use?
- Is LIST() now redundant?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk