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:
>> >
>> > #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
>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
>#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
>to be included, since that is what we'd naturally do if all
>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
>with workarounds for buggy compilers taking a non-intrusive back

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

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>
   # namespace std { using ::size_t; using ::ptrdiff_t; }

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.



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