Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-01-24 16:53:00


----- Original Message -----
From: "Hugo Duncan" <hugoduncan_at_[hidden]>

> I think I have found a problem with boost/mpl/list.hpp
>
> I am including files using BOOST_PP_ITERATE. One of the files
> that I include happens itself to include boost/mpl/list.hpp.

I'm not sure what you mean here. If you are iterating over a file (or
section of a file) with the file-iteration mechanism. That iterated text
should *never* include regular headers. E.g. if '1.hpp' uses the iteration
mechanism to iterate over '2.hpp', and '2.hpp' needs the facilities from
some other file (like <iostream> or anything else at all), '1.hpp' can
include them, *not* '2.hpp'. If you want to separate concerns as much as
possible, you can reference the iterated file as a normal header so it can
include other facilities that are needed:

// 1.hpp

#ifndef ONE_HPP
#define ONE_HPP

#include <boost/preprocessor/iteration/iterate.hpp>

#include "2.hpp" // normal inclusion

#define BOOST_PP_ITERATION_PARAMS_1 \
    (3, (1, 10, "2.hpp")) \
    /**/
??=include BOOST_PP_ITERATE() // not normal at all!

#endif // EOF

--------------------------------------

// 2.hpp

#if !BOOST_PP_IS_ITERATING

// as normal header

    #ifndef TWO_HPP
    #define TWO_HPP

    #include <iostream>
    #include <boost/preprocessor/repetition/repeat.hpp>
    // etc.

    #endif // TWO_HPP

#else

// not normal at all!
// use <iostream> and <../repeat.hpp> facilities...

#endif

> boost/mpl/list.hpp begins
>
> #if !defined(BOOST_PP_IS_ITERATING)
> ///// header body
> #ifndef BOOST_MPL_LIST_HPP_INCLUDED
> #define BOOST_MPL_LIST_HPP_INCLUDED
>
>
> Because I am using BOOST_PP_ITERATE, BOOST_PP_IS_ITERATING is defined,
> and problems occur.
>
> I assume BOOST_PP_IS_ITERATING is checked for logic associated with
> preprocessed file generation.

It is defined when the file-iteration mechanism is iterating over a file.
Its purpose is to distinguish between a normal inclusion and an "iteration"
inclusion so that the same file can iterate over itself. When a file that
is iterated includes other files *during an iteration*,
BOOST_PP_IS_ITERATING is still defined and the other files probably won't
know how to handle it. (<boost/mpl/list.hpp> is one example of this.) The
solution is simply to not include any files during a particular iteration.

Paul Mensonides


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