On 6/18/07, Roman Perepelitsa <roman.perepelitsa@db.com> wrote:
Tobias Schwinger <tschwinger <at> isonews2.com> writes:

> Yep, here's another dirty trick :
>
>      #include <boost/preprocessor/detail/is_unary.hpp>
>
>      #define SPECIAL (whatever)
>      #define IS_SPECIAL BOOST_PP_IS_UNARY
>
>      IS_SPECIAL(a)         // 0
>      IS_SPECIAL(b)         // 0
>      IS_SPECIAL(SPECIAL)   // 1
>
> It isn't entirely portable to older preprocessors (that's why this code
> lives in preprocessor/detail) but should work with latest versions of
> the widely-used compilers.

This also works:

#include <boost/preprocessor/facilities/is_empty.hpp>
#include <boost/preprocessor/empty.hpp>

#define SPECIAL
#define IS_SPECIAL(x) BOOST_PP_IS_EMPTY(BOOST_PP_EMPTY() x)


This is great. I am really surprised that it works in a comma separated argument list, and that you can pass around a funny array (4,  (a1, a2, , a3) ), and work on it as expected.

There is very slight usage problem though. An input such as  ( int, double&, , char* ) where the second comma is a typo, is a valid expression and produces a syntactically correct prototype (see my previous post where I am using this IS_SPECIAL macro), and goes unnoticed, until crashing miserably in run time!

L.

--
Server Levent Yilmaz
Mechanical Engineering
University of Pittsburgh