Boost logo

Boost :

Subject: [boost] Guidence on #pragma once
From: Robert Ramey (ramey_at_[hidden])
Date: 2018-11-23 23:36:20


In the safe numerics library my *.hpp files start with the following
boiler plate:

#ifndef BOOST_NUMERIC_AUTOMATIC_HPP
#define BOOST_NUMERIC_AUTOMATIC_HPP

// 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 https://en.wikipedia.org/wiki/Pragma_once#cite_note-9

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.

Robert Ramey


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