Boost logo

Boost :

Subject: Re: [boost] Guidence on #pragma once
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2018-11-24 01:01:35

On Sat, Nov 24, 2018 at 2:36 AM Robert Ramey via Boost
<boost_at_[hidden]> wrote:
> 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
> according to
> this should be possible while supporting almost all which claim to be
> C++ 14 conformant. The exception noted is C++ for Cray.
> I realize that strictly speaking I shouldn't do this. But it would
> instantaneously remove some cruft from my code as long as the occasional
> error from repeating the same include guard text in multiple files. It
> might have some performance benefits and some other repercussions
> related to pre-compiled headers. Who knows what else. It would be
> interesting to know what others might have to say about this.

There is BOOST_HAS_PRAGMA_ONCE in Boost.Config if you want to use the
pragma. It should be noted though that most more or less recent
compilers already recognize include guards and implement the same kind
of optimizations that were provided by `#pragma once` before. And
since `#pragma once` is non-standard and not reliable, there's little
reason to keep using it, especially if you're targeting newer
compilers supporting C++14. So if you want to simplify the code, keep
the include guards and drop the pragma.

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