By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,907 Members | 1,283 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,907 IT Pros & Developers. It's quick & easy.

Passing templated types as parameter to macro

P: n/a
I unable to pass a template type with two parameters to a very simple
macro with g++ 3.4 (Linux x86):

for example:

#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE(token)

void foo()
{
THIS_IS_A_MACRO(tracked::TrackedBasicType<int>); // this works

THIS_IS_A_MACRO(tracked::TrackedBasicType2<int,cha r>); // this
doesn't

// g++ complains this: macro "THIS_IS_A_MACRO" passed 2 arguments,
but takes just 1

}

Is there a way to pass templatized types (with multiple params) to a
macro definition ?

thanks in advance.

MB

May 24 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ma************@gmail.com wrote:
I unable to pass a template type with two parameters to a very simple
macro with g++ 3.4 (Linux x86):

for example:

#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE(token)

void foo()
{
THIS_IS_A_MACRO(tracked::TrackedBasicType<int>); // this works

THIS_IS_A_MACRO(tracked::TrackedBasicType2<int,cha r>); // this
doesn't

// g++ complains this: macro "THIS_IS_A_MACRO" passed 2 arguments,
but takes just 1

}

Is there a way to pass templatized types (with multiple params) to a
macro definition ?
I'm not sure if it will work, but you could try

#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE((token))

(note the extra set of parentheses around 'token').

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
May 24 '07 #2

P: n/a
Marcus Kwok wrote :
ma************@gmail.com wrote:
>I unable to pass a template type with two parameters to a very simple
macro with g++ 3.4 (Linux x86):

for example:

#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE(token)

void foo()
{
THIS_IS_A_MACRO(tracked::TrackedBasicType<int>); // this works

THIS_IS_A_MACRO(tracked::TrackedBasicType2<int,cha r>); // this
doesn't

// g++ complains this: macro "THIS_IS_A_MACRO" passed 2 arguments,
but takes just 1

}

Is there a way to pass templatized types (with multiple params) to a
macro definition ?

I'm not sure if it will work, but you could try

#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE((token))

(note the extra set of parentheses around 'token').
The error is in using THIS_IS_A_MACRO with 2 parameters, while it
expects one. Changing the "implementation" of THIS_IS_A_MACRO won't
change anything.

- Sylvester
May 24 '07 #3

P: n/a
Sylvester Hesp <s.******@spamoisyn.nlwrote:
Marcus Kwok wrote :
>ma************@gmail.com wrote:
>>I unable to pass a template type with two parameters to a very simple
macro with g++ 3.4 (Linux x86):

for example:

#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE(token)

void foo()
{
THIS_IS_A_MACRO(tracked::TrackedBasicType<int>); // this works

THIS_IS_A_MACRO(tracked::TrackedBasicType2<int,cha r>); // this
doesn't

// g++ complains this: macro "THIS_IS_A_MACRO" passed 2 arguments,
but takes just 1

}

Is there a way to pass templatized types (with multiple params) to a
macro definition ?

I'm not sure if it will work, but you could try

#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE((token))

(note the extra set of parentheses around 'token').

The error is in using THIS_IS_A_MACRO with 2 parameters, while it
expects one. Changing the "implementation" of THIS_IS_A_MACRO won't
change anything.
What about changing the call site to add the extra parentheses there:

THIS_IS_A_MACRO((tracked::TrackedBasicType2<int,ch ar>));

If that works, then you might be able to get more natural syntax by
adding another level of macro indirection. I recall a similar technique
we used in a C course to wrap printf() calls with a macro that expanded
to another macro, so that lint wouldn't complain when we didn't check
the return value, but the exact details escape me at the moment.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
May 24 '07 #4

P: n/a
Marcus Kwok <ri******@gehennom.invalidwrote:
What about changing the call site to add the extra parentheses there:

THIS_IS_A_MACRO((tracked::TrackedBasicType2<int,ch ar>));

If that works, then you might be able to get more natural syntax by
adding another level of macro indirection. I recall a similar technique
we used in a C course to wrap printf() calls with a macro that expanded
to another macro, so that lint wouldn't complain when we didn't check
the return value, but the exact details escape me at the moment.
OK, I was able to find it and I was wrong; the "trick" we used was to
use the double-parentheses so that the variable number of arguments to
printf() could be passed to the second intermediate macro.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
May 24 '07 #5

P: n/a
It works using extra parentheses, thanks !!!!

MB

On May 24, 12:56 pm, ricec...@gehennom.invalid (Marcus Kwok) wrote:
Sylvester Hesp <s.hes...@spamoisyn.nlwrote:
Marcus Kwok wrote :
martin.brod...@gmail.com wrote:
I unable to pass a template type with two parameters to a very simple
macro with g++ 3.4 (Linux x86):
>for example:
>#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE(token)
>void foo()
{
THIS_IS_A_MACRO(tracked::TrackedBasicType<int>); // this works
> THIS_IS_A_MACRO(tracked::TrackedBasicType2<int,cha r>); // this
doesn't
> // g++ complains this: macro "THIS_IS_A_MACRO" passed 2 arguments,
but takes just 1
>}
>Is there a way to pass templatized types (with multiple params) to a
macro definition ?
I'm not sure if it will work, but you could try
#define THIS_IS_A_MACRO(token) BOOST_PP_STRINGIZE((token))
(note the extra set of parentheses around 'token').
The error is in using THIS_IS_A_MACRO with 2 parameters, while it
expects one. Changing the "implementation" of THIS_IS_A_MACRO won't
change anything.

What about changing the call site to add the extra parentheses there:

THIS_IS_A_MACRO((tracked::TrackedBasicType2<int,ch ar>));

If that works, then you might be able to get more natural syntax by
adding another level of macro indirection. I recall a similar technique
we used in a C course to wrap printf() calls with a macro that expanded
to another macro, so that lint wouldn't complain when we didn't check
the return value, but the exact details escape me at the moment.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply

May 24 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.