Boost logo

Boost Users :

Subject: Re: [Boost-users] [preprocessor] have macro do different things based on structure of its argument
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2011-03-02 16:38:05


> From: eldiener_at_[hidden]
> > MY_MACRO(x) // a single token
> > MY_MACRO((x, y)) // a parenthesized list of two tokens
> > MY_MACRO((x, y, z)) // a parenthesized list of three tokens
> > MY_MACRO(x y) // two tokens
> > MY_MACRO(x y z) // three tokens
> > MY_MACRO(x = y) // three tokens with the second one being something specific
>
> I will assume your examples are numbered from 1 to 6.
>
> In numbers 2 and 3 the parameter is a pp-lib tuple. Normally you would
> have to know in advance how many elements are in a tuple but if your
> compiler supports variadic macros you can use my variadic_macro_data
> library in the sandbox to know how many elements are in the pp-lib tuple
> and then you can subsequently extract any one of them.
>
> Numbers 1,4,5,6 are single elements. There is no way of which I know to
> determine how many space separated sequences of text there are in each
> element or extract any one of them. But there is a way to check whether
> the sequence starts with a given sequence, and you may be able to work
> from there via Lorenzo Caminiti's clever example, which he worked out
> for his Local library:
>
> "NOTE: This is more of a curiosity because for my application I can
> manipulate the storage classifiers using preprocessor metaprogramming.
> In fact, `auto` and `register` are known alphanumeric tokens (i.e.,
> keywords) that always appear at the beginning of the parameter type
> expression so the following macros can be used to manipulate them:
>
> [snip]
>
> REMOVE_AUTO(auto int x) // int x
> REMOVE_AUTO(int x) // int x
>
> ADD_AUTO(auto int x) // auto int x
> ADD_AUTO(int x) // auto int x

Interesting. I'm trying to do something slightly similar. I'm trying to accept both
"typename identifier" and "identifier", and add "auto" (the C++0x kind)
if there is no typename.

So "ADD_AUTO(int x)" would remain "int x", but ADD_AUTO(x)
would become "auto x".

Do you think that's possible?

Thanks,
Nate.

                                               


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