curiousexplorer
curiousexplorer

Reputation: 1237

Include all of a template library in a file

Off late I have had too use some template libraries like Boost and Thrust (for CUDA) in some of my coding work.

For using a certain feature of the Boost library, one has to include the appropriate header.e.g. for boost::lexical_cast I have to use boost/lexical_cast.hpp. It is tiring to keep including the appropriate header for every new feature of Boost / Thrust which I use for my projects.

Is there any "shortcut" to tell the pre-processor to include all the header files stored under the boost library, so that I need not bother about which header file to include?

I am using GCC under Ubuntu.

Upvotes: 1

Views: 139

Answers (2)

Kerrek SB
Kerrek SB

Reputation: 477040

You could simply make a mother-of-all header file like so:

for i in $(find /usr/include/boost/); do echo "#include <"${i/"/usr/include/"/}">"; done > master_header.hpp

Now you can add that and use precompiled headers (you may need an overnight compilation to make the PCH). You should also pass -Wl,-as-needed to the linker to avoid including unneeded libraries.

As @sbi says, this isn't advisable in the least, but since you asked... sometimes the best remedy against finding something "tiresome" is to see how much worse it could be!

Upvotes: 2

sbi
sbi

Reputation: 224079

You don't want that. You want to include as little as possible. Compile times are abysmal in C++ as it is. Start to include everything everywhere and it is going to get worse even.

I have been working in a project where compilation on a decent single core CPU of the time took 50mins, linking 5-10mins. This hurts big time, if you're doing template stuff deep down in the foundations.

Boost comes with a bunch of stuff (like the MPL) that stretches the compiler to its utmost limits. It would be insane to include this stuff everywhere (except for a five-cpp-files kind of project).

Upvotes: 6

Related Questions