|
Boost Users : |
From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-10-06 07:11:23
Server Levent Yilmaz wrote:
> Hi all,
>
> Please take a look as this trivial example of file iteration:
[... code]
>
> Perhaps not so obvious many (wasn't to me), that
>
> #define BOOST_PP_FILENAME_1 __FILE__
>
> doesn't work.
Yes, because it /always/ expands to the current file (also in the file
loaded with #include BOOST_PP_ITERATE()).
> One has to specify (kind of like hardcode) the file's name
> in there.. Is there some, possibly contrived, way to achieve automation
> of this?
#include <boost/preprocessor/slot/slot.hpp>
#define MIN 0
#define MAX 9
#ifndef RESET_DONE
# define BOOST_PP_VALUE MIN
# include BOOST_PP_ASSIGN_SLOT(1)
# define RESET_DONE
#endif
*****
* BOOST_PP_SLOT(1) *
*****
#if BOOST_PP_SLOT(1) < MAX
# define BOOST_PP_VALUE BOOST_PP_SLOT(1)+1
# include BOOST_PP_ASSIGN_SLOT(1)
# include __FILE__
#else
# undef RESET_DONE
#endif
Please note this code has several limitations, however:
1. The #include __FILE__ part is not handled correctly by all preprocessors.
2. You might want to partially unroll the iteration not to hit internal
limits too easily.
> PS: What an AMAZING library this Boost.Preprocessor is!?
See its successor to be SHOCKED :-)
http://sf.net/projects/chaos-pp
Regards,
Tobias
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