2009/11/16 Surya Kiran Gullapalli <suryakiran.gullapalli@gmail.com>
Hello all,I'm trying to come up with a solution for the following problem.
I've a macro with three arguments, but if the third is not given, it should be assumed as '0'. Something on the lines of default arguments for functions.
I'm using VS2005, and g++ 4.4.x so i can use Variadic macros, but I'm unable to come up with a solution. Is there any way i can achieve this using Boost.Preprocessor ?
I tried using BOOST_PP_IF but unable to proceed further. Any Ideas ?
#define FOO_IMPL(a, b, c) /* Definition of your macro. 3 arguments. */
// Expands to FOO_IMPL(a, b, c) if called with 3 arguments.
// Expands to FOO_IMPL(a, b, 0) if called with 2 arguments.
// En error if called with some other number of arguments.
#define FOO(...) \
BOOST_PP_IF( \
BOOST_PP_EQUAL(PP_NARG(__VA_ARGS__), 2), \
FOO_IMPL(__VA_ARGS__, 0), \
FOO_IMPL(__VA_ARGS__))
Roman Perepelitsa.