Boost logo

Boost Users :

Subject: Re: [Boost-users] Is there a way for a library to add symbols to the standard headers ?
From: Edward Diener (eldiener_at_[hidden])
Date: 2010-09-01 19:02:59


On 9/1/2010 5:16 PM, Timothy Madden wrote:
> Hello
>
> To write a library to add a POSIX emulation layer on Windows, is there a
> way to add symbols from my library to C/C++ standard library headers,
> without getting into recursive inclusion ?
>
> For example, is there a way to get the 'Additions to fstream' from the
> boost::filesystem library, actually look like they are added to the
> standard <fstream> header ?
>
> I know users can use #include "cstdio" (with quotes instead of brackets)
> throughout a project, in order to later be able to include some local
> version of the header, if the need for it arise during during some
> porting at a later time for example.
>
> However this works for user-level code, while for a library it is not
> that simple any more ...

Why would you want to add functionality to a standard library
header/class as opposed to just creating functionality which uses a
particular standard library class or function, which anyone can do ?

The only reason to do this is if one is trying to correct a deficiency
in some compiler's implementation of a standard library header, but even
that is fraught with difficulty and needs to be done very carefully.
Usually this is done by adding symbols to namespace std, which is
certainly allowed. But adding new things to namespace std which has
nothing to do with the actual standard library is not something to be
recommended, as it will upset end user's expectation of what is in the
standard library as part of the C++ standard.

Perhaps you should rethink your goals for your POSIX emulation layer for
Windows and realize that placing it in your own namespace is better than
adding it to the std namespace in every way. You should not be trying to
confuse end-users as to what is in the std namespace and what is not.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net