Boost logo

Boost :

Subject: Re: [boost] Proposal for #pragma once support
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-06-09 14:19:55


On Tue, Jun 9, 2009 at 11:50 AM, <dherring_at_[hidden]> wrote:

> On Tue, 9 Jun 2009, Zachary Turner wrote:
>
> 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
>>
> ...
>
>> So, I believe that boost compile times can benefit significantly from
>> this.
>>
>> Thoughts?
>>
>
> Could you run benchmarks on gcc? Will my compile times suffer for your
> improvement?
>
> - Daniel
>

It seems someone else in the thread has already run benchmarks on GCC, but
regardless of how the benchmarks did or did not turn out, I can say with
100% certainty that nobody will suffer. That's the exact reason I mentioned
that compilers should be whitelisted based on which ones benefit from
#pragma once, and only use #pragma once for said compilers.

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif

That's all it takes. Everybody benefits. Of course I don't have licenses
for every C++ compiler around, but I'm sure there are other compilres in
which it benefits also. So I would need some assistance from other people
who do have other compilers to help find out which compilers it does offer
an improvement on.

And of course, the default would be to NOT use pragma once, erring on the
side of caution. If you see any downsides to this approach let me know, but
it seems like a win/win for everyone.

To make it even more explicit, there could even be a global macro, which
defaults to undefined, called BOOST_USE_PRAGMA_ONCE. The programmer would
be forced to explicitly declare this macro before including any boost
headers, and if it is enabled, boost would use pragma once.


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