Boost logo

Boost :

Subject: Re: [boost] For Boost PP: IF_NONEMPTY(), IS_NONEMPTY
From: Daniel James (dnljms_at_[hidden])
Date: 2012-05-08 13:12:32


On 8 May 2012 10:24, Daniel Santos <danielfsantos_at_[hidden]> wrote:
> I came up with some macros the other day trying to solve a kernel
> problem and I haven't seen them anywhere else and if I found one, I sure
> would have stolen it. :)  I used this to have a single function-like
> macro service different numbers of parameters, essentially adding
> "optional parameter" support so I didn't have to have different version
> of the macro.
>
> IF_NONEMPTY(test, result) expands to result if test is non-empty, empty
> otherwise.
> IS_NONEMPTY(arg) expands to 0 if arg is empty, 0x1 if it isn't.
> OPT_OFFSETOF(type, member) isn't very useful in C++, but it is an
> example of how the above can be used. It expands to a compiler-time
> constant that is the offset of the member in the struct or union type,
> unless member isn't specified, in which case it's zero.

There's BOOST_PP_IS_EMPTY in
<boost/preprocessor/facilities/is_empty.hpp> although it isn't
publicized as it won't work on some preprocessors. I haven't look
closely enough to see how it compares.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk