Is it possible to include a sequence of files: file1,file2,file3
in a preprocessor loop?
#include <boost/preprocessor/iteration/local.hpp>
#include <boost/preprocessor/cat.hpp>
// needed whitespace here----*
#define BOOST_PP_LOCAL_LIMITS (1, 3)
#define GENERATE_FILE_NAME(n) \
BOOST_PP_STRINGIZE( BOOST_PP_CAT( file , n) ) \
/**/
#define BOOST_PP_LOCAL_MACRO(n) \
#include GENERATE_FILE_NAME(n) \
and then using it with:
#include BOOST_PP_LOCAL_ITERATE()
should expand to
BOOST_PP_LOCAL_MACRO(1) --> includes file1
BOOST_PP_LOCAL_MACRO(2) --> includes file2
BOOST_PP_LOCAL_MACRO(3) --> includes file3
Unfortunately the above does not work because of the #include GENERATE_FILE_NAME(n)
in a macro which does not expand...
Is this even possible?
Comment:
I posted this question because I was wondering if this is even possible. I have solved my problem by including just one file which was generated from all files file1 file2 file3
. I came across this, because sometimes one might generate big include file sequences (which should not be merged, just because of readability) and I was unsure how to include all those without writing explicitly all file names, so I thought about preprocessor loops, which is of course uglier then my solution so far :-), but its fancier :-)
This works with g++:
Having a directory preprocessor in the include path and this include_range.h:
You can include a range of files (file2, file3, file4):
Limitation: The files are in the include path.