[Parameter] Adding arguments to pack through macro?
Hi, I guess that the subject line isn't even technically correct. What I'd like to do is to implement something like the following: #define FOO(x) MyNamedParamFn(x, d = 3, e = 4) Where e.g. "FOO((a = 0, b = 1));" would expand to the equivalent of: MyNamedParamFn(a = 0, b= 1, d = 3, e = 4); Is this possible? / Johan
"Johan Nilsson"
Hi,
I guess that the subject line isn't even technically correct. What I'd like to do is to implement something like the following:
#define FOO(x) MyNamedParamFn(x, d = 3, e = 4)
Where e.g.
"FOO((a = 0, b = 1));"
would expand to the equivalent of:
MyNamedParamFn(a = 0, b= 1, d = 3, e = 4);
Is this possible?
Not with a C++03 preprocessor, because there's no way to "peel apart" a comma-separated list like (a = 0, b = 1) without knowing how many elements are in it. With a C99/C++0x preprocessor, you could do it. -- Dave Abrahams Boost Consulting www.boost-consulting.com
"David Abrahams"
"Johan Nilsson"
writes: Hi,
I guess that the subject line isn't even technically correct. What I'd like to do is to implement something like the following:
#define FOO(x) MyNamedParamFn(x, d = 3, e = 4)
Where e.g.
"FOO((a = 0, b = 1));"
would expand to the equivalent of:
MyNamedParamFn(a = 0, b= 1, d = 3, e = 4);
Is this possible?
Not with a C++03 preprocessor, because there's no way to "peel apart" a comma-separated list like (a = 0, b = 1) without knowing how many elements are in it. With a C99/C++0x preprocessor, you could do it.
What is possible, though, is something like: FOO_2(a = 0, b = 1) or FOO((a = 0)(b = 1)) Regards, Arkadiy
Johan Nilsson wrote:
Hi,
I guess that the subject line isn't even technically correct. What I'd like to do is to implement something like the following:
#define FOO(x) MyNamedParamFn(x, d = 3, e = 4)
Where e.g.
"FOO((a = 0, b = 1));"
would expand to the equivalent of:
MyNamedParamFn(a = 0, b= 1, d = 3, e = 4);
Is this possible?
What others failed to mention is that you can do this *without* macros. For example: template <typename ArgPack> void MyNamedParamFn(ArgPack args) { //... } template <typename ArgPack> void Foo(ArgPack args) { MyNamedParamFn((args, d = 3, e = 4)); } Foo((a = 0, b = 1)); HTH. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - grafikrobot/yahoo
Rene Rivera wrote:
Johan Nilsson wrote:
Hi,
I guess that the subject line isn't even technically correct. What I'd like to do is to implement something like the following:
#define FOO(x) MyNamedParamFn(x, d = 3, e = 4)
Where e.g.
"FOO((a = 0, b = 1));"
would expand to the equivalent of:
MyNamedParamFn(a = 0, b= 1, d = 3, e = 4);
Is this possible?
What others failed to mention is that you can do this *without* macros. For example:
Actually, I need to use macros as the additional parameters actually are "line = __LINE__, file = __FILE__". Nevertheless you helped me work around the problem: #define FOO(x) MyNamedParamFn_with_named_params((x, line = __LINE__, file = __FILE__)) The above makes it work (well, at least it compiles for the time being). However I guess that this approach kind of defeats the purpose of using the BOOST_PARAMETER_(MEM)FUN macros for defining the method ... must think about that. Now if I only could get rid of those ugly double parenthesises in the call to "FOO" - guess I'll just have to wait for preprocessor variadic args support for that ... Thanks! // Johan
participants (4)
-
Arkadiy Vertleyb
-
David Abrahams
-
Johan Nilsson
-
Rene Rivera