Boost logo

Boost :

Subject: [boost] preprocessor programming challenge
From: Eric Niebler (eric_at_[hidden])
Date: 2011-09-22 16:23:28


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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk