Boost logo

Boost :

Subject: [boost] Proposal for #pragma once support
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-06-09 11:59:42


I would like to propose conditional support for #pragma once be added to all
header files in boost. This would involve, at the beginning of every header
file, a preprocessor check to determine whether or not the particular
compiler is on a whitelist of known compilers to optimized #pragma once. If
so, #pragma once is used. so, something like this:

#if defined(_MSC_VER) /* || defined(OTHER_PRAGMA_ONCE_ENABLED_COMPILER) ...
*/
#pragma once
#endif

the rest of the header file, including the original #include guard, could be
as normal. to demonstrate the motivation for this, consider the sample on
this page:
http://www.gamearchitect.net/Articles/ExperimentsWithIncludes.html. At the
bottom there is a zip file with a visual studio solution that contains 3
different projects. Each project contains 200 header file, each of which
includes all of the other 199 header files. There is a single cpp file with
a main function which includes all 200 header files. All 3 projects use
internal #include guards. In addition:

Project 'RedundantGuard' - Uses external include guards (wrapping the
invocation of #include itself inside the appropriate guard) as discussed in
the book Large Scale C++ Software Design
Project 'PragmaOnce' - Uses #pragma once
Project 'Nothing' - Uses nothing additional other than the internal include
guards.

Here are the build timings on my machine (Visual Studio 2008 Service Pack 2)

RedundantGuard - 1 second compile + link time
PragmaOnce - 1 second compile + link time
Nothing - 15 seconds compile + link time

In addition I have tested this in the code base of a commercial product I am
working on (~40,000 lines of code). It consists of about 6 different
projects, some of which have dependencies between each other and some which
don't, so that parallel compilation can happen in some instances

RedundantGuard - Not Tested
PragmaOnce - 1 minute, 25 seconds compile + link time
Nothing - 2 minutes, 1 second compile + link time

So, I believe that boost compile times can benefit significantly from this.

Thoughts?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk