Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 1999-10-08 11:59:01


Ed Brey wrote:

>> >we could use using declarations to quickly pick up the names:
>> >
>> >#ifdef BOOST_NO_NAMESPACE_FOR_STDC
>> > #include <cstddef>
>> > #include <cstdlib>
>> > #include <cmath>
>> > namespace std {
>> > using ::size_t; using ::ptrdiff_t;
>> > ...
>> >#endif
>>
>> Ed, I think your solution above is a really good one.
>>
>> Typo: the #ifdef should be after rather than before the #includes.
>
>Actually, the #include location is by design, reason being that for
>conforming implementations, the "large compiler vendor" workaround
has
>absolutely zero effect. In particular, libraries should never count
>on config.hpp including any headers; they should merrily assume that
>the implementation is conforming. So if a library uses std::size_t,
>it should include <cstdlib>. If the implementation on which the
>library is compiled happens to be buggy, <cstdlib> will end up
getting
>#included twice, which is fine.
>
>In general, if a translation unit includes library L that needs
>headers A and B, on a conforming compiler we want only headers A and
B
>to be included, since that is what we'd naturally do if all
compilers
>were conferment. Only when working with a buggy compiler do we want
>to fall back to workarounds, which may involve extra includes. This
>is strict adherence to the policy of writing for conferment
compilers,
>with workarounds for buggy compilers taking a non-intrusive back
seat.

Ah! I see now that there are two techniques for using
BOOST_NO_STDC_NAMESPACE:

1) boost/config.hpp #defines (for non-conforming compilers only)
BOOST_NO_STDC_NAMESPACE, and also your code above as written. A
boost header needing cstdlib then simply contains:

   #include <boost/config.hpp>
   #include <cstdlib>

2) boost/config.hpp #defines (for non-conforming compilers only)
BOOST_NO_STDC_NAMESPACE, period. Then it is up to individual boost
headers (if they wish) to supply the workaround:

   #include <boost/config.hpp>
   #include <cstdlib>
   #ifdef BOOST_NO_STDC_NAMESPACE
   # namespace std { using ::size_t; using ::ptrdiff_t; }
   #endif

These techniques can be combined; (1) could be used for the very
commonly used headers such as cstdlib, cstddef, and maybe cstring,
while (2) could be used for the other <c...> headers.

Comments?

--Beman


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