Boost logo

Boost Users :

Subject: Re: [Boost-users] Preprocessor Question
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2009-11-16 11:07:03


2009/11/16 Surya Kiran Gullapalli <suryakiran.gullapalli_at_[hidden]>

> Definition of PP_NARG is here:
>> http://groups.google.com/group/comp.std.c/browse_thread/thread/77ee8c8f92e4a3fb/346fc464319b1ee5
>>
>
> This does not seems to be working, I keep getting the error C4003, not
> enough actual parameters for macro 'PP_ARG_N'
>
> GCC says, PP_ARG_N expects 65 args, where as it is getting only 3. I'm
> kinda lost here .
>

Hm... that's because both branches of BOOST_PP_IF always get evaluated. We
need to evaluate only one of them.

 #define FOO_ARGS(...) \
    BOOST_PP_IF( \
        BOOST_PP_EQUAL(PP_NARG(__VA_ARGS__), 2), \
        (__VA_ARGS__, 0), \
        (__VA_ARGS__))

#define FOO(...) BOOST_PP_EXPAND(FOO_IMPL FOO_ARGS(__VA_ARGS__))

I'm attaching a complete solution.

Roman Perepelitsa.





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