help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Macro: COMMA (again), unable to tokenize


From: tthunder
Subject: Macro: COMMA (again), unable to tokenize
Date: 17 Apr 2007 00:32:39 -0700
User-agent: G2/1.0

Hi!

Please check the following code. My aim is to write a macro, which is
able to do explicit template instantiation.

NOTE: The example is basic, of course. The original code has much more
lines, so the usage of #define is really important for me.


*************

#define COMMA ,

#define EXP_INST_COMMON(x) \
     template class x;

#define EXP_INST_SPECIFIC(x, y) \
     template class somefunc< x >( y ); \
     EXP_INST_COMMON(x)

/* .... */

EXP_INST_2(someClass<int COMMA double>, long)

*************

I could construct a more meaningful example. However, the code would
only get confusing.

The problem in this is example is, that EXP_INST_COMMON will be called
with two argument, because the COMMA is resolved before.

I found a solution for other compilers (MSVC, Borland C++):

*************

#define EXP_INST_SPECIFIC(x, y) \
     template class somefunc< x >( y ); \
     EXP_INST_COMMON( ##x## )

*************

Somehow, "x" is considered as token there, and "," can be passed as
token again. I don't know exactly, but it works.

However, g++ is trying to tokenize "x" with "(" and ")". This is not a
valid token, so g++ throws an error. I know, that this behavior is
correct, but the sad thing is, that I have no working solution any
more :(

Using the other workaround (using parenthesis instead of COMMA)
doesn't work for this code:

EXP_INST_2((someClass<int COMMA double>), long)

would expand to:

template class (someClass<int COMMA double>);

C++ compiler do not like that ;)

There MUST be a solution... please help!

Greetings,
Kirsten



reply via email to

[Prev in Thread] Current Thread [Next in Thread]