How can one achieve what the following code is trying to do?
#include "dir/*"
How can one achieve what the following code is trying to do?
#include "dir/*"
You can't, without running a script beforehand that generates all #include statements.
The preprocessor can only handle one file per #include statement, so it requires an actual #include for every single file you wish to be included in preprocessing.
One way to achieve that is to write a convenience header that includes all the headers you want. Keep in mind that including headers you will not use may unnecessarily increase compilation time.
In bash:
HEADER=all_headers.h
echo "#ifndef __ALL_HEADERS__" > $HEADER
echo "#define __ALL_HEADERS__" >> $HEADER
for file in dir/*.h
do
echo "#include <$file>" >> $HEADER
done
echo "#endif" >> $HEADER
Look at how Boost does this for, say, utility.hpp
.
$ cat /usr/include/boost/utility.hpp
// Boost utility.hpp header file -------------------------------------------//
<snip>
#ifndef BOOST_UTILITY_HPP
#define BOOST_UTILITY_HPP
#include <boost/utility/addressof.hpp>
#include <boost/utility/base_from_member.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/checked_delete.hpp>
#include <boost/next_prior.hpp>
#include <boost/noncopyable.hpp>
#endif // BOOST_UTILITY_HPP
Now you can just use #include <boost/utility.hpp>
.