Boost logo

Boost :

Subject: Re: [boost] Guidence on #pragma once
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2018-11-23 23:54:18

On Fri, Nov 23, 2018 at 3:36 PM 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

It will not have any performance benefits. Besides non-standard, #pragma
once is unreliable because it is not always trivial for a compiler to
detect that it is processing the same file for a second time. My
understanding is that in some cases it might not be possible. Secondly, it
is possible for the same file to appear in multiple places.

You can remove some cruft by deleting the #pragma once. :)

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