简体   繁体   中英

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

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM