Boost logo

Boost :

Subject: Re: [boost] Guidence on #pragma once
From: mike.dev_at_[hidden]
Date: 2018-11-25 21:28:49

> -----Original Message-----
> From: Boost <boost-bounces_at_[hidden]> On Behalf Of Robert Ramey via Boost
> In the safe numerics library my *.hpp files start with the following
> boiler plate:
> // MS compatible compilers support #pragma once
> #if defined(_MSC_VER) && (_MSC_VER >= 1020)
> # pragma once
> #endif
> ...
> I would like to replace all this in every file with just
> #pragma once

Whatever you do, there is zero reason to keep both - the include guards and #pragma once.

We prefer #pragma once in our internal libraries and projects, simply for brevity and because
it doesn't require one to come up with any consistent unique naming scheme that has to be
maintained when the file is e.g. moved around.
Also, if a TU does happen to include the (nominally) same header from two different locations
for some wicket reason, there is a very high chance, that those headers have actually a different
version and I welcome a compile-time error in that case which I don't get with include guards
(unless they are versioned themselves).

In any case: I still haven't seen a single case, where #pragma once doesn't work as expected,
but I guess boost libraries are used in so many different environments, that you most likely
will break someone somewhere if you remove the include guards and only rely on #pragma once,
while removing #pragma once and retaining the include guards should be safe.



Boost list run by bdawes at, gregod at, cpdaniel at, john at