views:

160

answers:

4

How can one achieve what the following code is trying to do?

#include "dir/*"
+6  A: 

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.

Jordan Lewis
+7  A: 

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.

Space_C0wb0y
+7  A: 

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
el.pescado
+2  A: 

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>.

ezpz
Yeah this is the current way I'm doing it. I guess I'll just keep doing it this way because I don't want to get fancy in bash as the other answer suggests. Thanks guys, just seems weird that java can do this with a *.
@user137790: The fact that Java provides this mechanism is indeed convenient. But `C++` will **never** choose convenience over efficency; and doing this is precisely **not** efficient. It would allow you to save some keystrokes at the cost of having a much longer compilation time. Which one do you think pays more in the long term ?
ereOn