Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-01-29 16:13:12


----- Original Message -----
From: "Hugo Duncan" <hugoduncan_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, January 29, 2003 12:23 PM
Subject: [boost] BOOST_PP_XX_INCCLUDE

> On Mon, 27 Jan 2003 12:42:14 -0800, "Paul Mensonides" <pmenso57_at_[hidden]>
wrote:
>
> > #define BOOST_PP_HEADERS \
> > (...), /* i.e. "no path" */ \
> > (iostream)(fstream)(vector)(string) \
> > (map)(cstdlib)(sstream) \
> > /**/
> >
> > ??=include BOOST_PP_ANGLED_INCLUDE()
> >
> > ....effectively does this:
> >
> > #include <iostream>
> > #include <fstream>
> > #include <vector>
> > #include <string>
> > #include <map>
> > #include <cstdlib>
> > #include <sstream>
>
> Looks good to me.

Does anyone else have any comments about what they'd like out of such a
mechanism?

> I would like to take a file that uses BOOST_PP_HEADERS, say
>
> > #define BOOST_PP_HEADERS \
> > (...), /* i.e. "no path" */ \
> > (iostream)(fstream)(vector)(string) \
> > (map)(cstdlib)(sstream) \
> > /**/
> >
> > ??=include BOOST_PP_ANGLED_INCLUDE()
>
> and preprocess it to generate the file that says
>
> > #include <iostream>
> > #include <fstream>
> > #include <vector>
> > #include <string>
> > #include <map>
> > #include <cstdlib>
> > #include <sstream>

Ah, you mean _without_ actually including the files? Well, for obvious reasons,
this can't be done without a double preprocessor pass, but it is possible. To
make such a file, you'd have to write the #include directive manually, something
like:

#include <boost/preprocessor/iteration/local.hpp>
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/seq/size.hpp>

#define HASH #
#define HEADERS \
    (iostream)(fstream)(vector)(string) \
    (map)(cstdlib)(sstream) \
    /**/

#define BOOST_PP_LOCAL_LIMITS \
    (0, BOOST_PP_SEQ_SIZE(HEADERS) - 1) \
    /**/

#define BOOST_PP_LOCAL_MACRO(n) \
    HASH include <BOOST_PP_SEQ_ELEM(n, HEADERS)> \
    /**/

#include BOOST_PP_LOCAL_ITERATE()

#undef HASH
#undef HEADERS

Preprocessing this will output a set of include directives:

# include <iostream>
# include <fstream>
# include <vector>
# include <string>
# include <map>
# include <cstdlib>
# include <sstream>

However, you may have problems with the pound-sign (#), so you may have to do
something more ridiculous like defining HASH like this:

#define HASH % ## :

%: is the digraph for '#' and prevents it from being a macro expansion
operator--i.e. stringizing. Of course, whatever uses the resulting file must be
able to handle digraphs. I'm not sure if this is a good solution or not, it is
dangerously close to being undefined behavior--if it isn't already. It seems to
me that it would be easier to just write it by hand, or use a small program to
write it out for you. I don't know, just some thoughts.

> > You can simply make a source file that includes all the files that you want
> > to pre-preprocess (if that is what your getting at), run it through your
> > compiler's preprocessor, and then include the result file.
>
> I don't think bjam supports just running the preprocessor, but as you say
> the poblem is more tricky; I would like to stop preprocessing at a certain
> include depth.

This I can't do without compiler support.

> > ....but this is outside the scope of the pp-lib can automate because it
> > requires a separate build step to produce the preprocessor equivalent of a
> > "pre-compiled header."
>
> I didn't mean to imply it was within scope. I know MPL does preprocessing
> using python, but I don't know how reuseable that code is, so I was
> just hunting for tips, suggestions and pointers.
>
> Thanks for your help. Look forward to seeing BOOST_PP_INCLUDE when you have
time.

I'll write up a copy and send it to you directly to try out.

Paul Mensonides


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