preprocessor programming challenge

I have a PP interface such as the following: #define MACRO(x) \ typedef x type; \ typedef x::nested nested; struct D { struct nested {}; }; It is intended to be used as follows: struct foo { MACRO(D) }; Now the problem comes when x is a dependent type, because "typedef x::nested" needs a "typename" in there. I would like to additionally support the following syntax (or something like it): template<class DD> struct bar { MACRO(typename DD) }; The above doesn't work as is because "typedef typename DD type;" is ill-formed (although msvc eats it). Constraints are i/ the interface must be backwards compatible to avoid breaking existing clients, ii/ it should be done with PP only. No templates should be instantiated here, and iii/ it should be standard C++03. No PP variadics. Is this possible? I think not, but my PP-foo is weak. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Le 22/09/2011 22:23, Eric Niebler a écrit :
Is this possible? I think not, but my PP-foo is weak.
We have a REMOVE_TYPENAME macro in nt2 that may fit the bill: https://github.com/MetaScale/nt2/blob/master/modules/boost/dispatch/include/... Feel free to reuse etc ... if it actually fits your need ;)

On 9/22/2011 2:06 PM, Joel Falcou wrote:
Le 22/09/2011 22:23, Eric Niebler a écrit :
Is this possible? I think not, but my PP-foo is weak.
We have a REMOVE_TYPENAME macro in nt2 that may fit the bill:
https://github.com/MetaScale/nt2/blob/master/modules/boost/dispatch/include/...
Feel free to reuse etc ... if it actually fits your need ;)
Wow, I have NO idea how it works, but work it does! I'm very glad I asked. It will please you to know that I'll be using this to fix <https://svn.boost.org/trac/boost/ticket/4723>, which you filed a year ago. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
Eric Niebler
-
Joel Falcou