Boost logo

Boost :

Subject: Re: [boost] numeric_cast
From: Tom Tan (ttan_at_[hidden])
Date: 2011-06-24 05:46:34


It seems to me the outer #ifdef works for MSVC as well. What's the extra
benefit of embedding an inner #pragma once in this case?

在 2011-06-24五的 04:22 -0400,boost-request_at_[hidden]写道:
> Message: 1
> Date: Thu, 23 Jun 2011 21:43:02 +0000
> From: "Stephan T. Lavavej" <stl_at_[hidden]>
> To: "boost_at_[hidden]" <boost_at_[hidden]>
> Subject: Re: [boost] numeric_cast
> Message-ID:
>
> Actually, the best thing to do is this:
>
> #ifndef MYPROJECT_MYDIRECTORY_FOOBAR_HPP
> #define MYPROJECT_MYDIRECTORY_FOOBAR_HPP
>
> #ifdef _MSC_VER
> #pragma once
> #endif // _MSC_VER
>
> meow;
>
> #endif // MYPROJECT_MYDIRECTORY_FOOBAR_HPP
>
> This way, all compilers get the portable idempotency guard. Because
it's on the outside, GCC (and possibly other compilers) will magically
recognize it and avoid opening the header file twice. And the #pragma
once for MSVC also instructs it to avoid opening the header file twice,
which can improve build perf and can't hurt.
>
> Stephan T. Lavavej
> Visual C++ Libraries Developer
>


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