|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-01-29 15:35:15
On Tuesday 29 January 2002 03:06 pm, you wrote:
> FWIW, I've solved this 'precompiled header' problem in my own copy of the
> bind library by replacing the global variables with inline functions:
> That is, I did this:
[snip cod]e
> But unfortunately, such a change, even it if were appropriate, would break
> existing code.
> However, it might help you to get through until a definitive solution is
> found.
>
> BTW, I did the same with 'ignore' in the tuples library.
Here's my proposed solution: give Boost three additional macros:
BOOST_NAMESPACE_VARIABLE: placed before any namespace-level variable to give
it the appropriate linkage.
BOOST_BEGIN_NAMESPACE_VARIABLES: placed before the declaration of
namespace-level variables
BOOST_END_NAMESPACE_VARIABLES: placed after the declaration of
namespace-level variables.
For bind, we would have something like:
BOOST_BEGIN_NAMESPACE_VARIABLES
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<1> _1;
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<2> _2;
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<3> _3;
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<4> _4;
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<5> _5;
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<6> _6;
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<7> _7;
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<8> _8;
BOOST_NAMESPACE_VARIABLE boost::_bi::arg<9> _9;
BOOST_END_NAMESPACE_VARIABLES
Then we have a user-level variable that defines the current mode we are in:
- standalone mode, where we can use an anonymous namespace for the
variables and no linkage is necessary. Therefore we have the following
defines:
#define BOOST_BEGIN_NAMESPACE_VARIABLES namespace {
#define BOOST_END_NAMESPACE_VARIABLES }
#define BOOST_NAMESPACE_VARIABLE
- header mode, where we declare all of these external:
#define BOOST_BEGIN_NAMESPACE_VARIABLES
#define BOOST_END_NAMESPACE_VARIABLES
#define BOOST_NAMESPACE_VARIABLE extern
- object file mode, where we declare the actual instances
#define BOOST_BEGIN_NAMESPACE_VARIABLES
#define BOOST_END_NAMESPACE_VARIABLES
#define BOOST_NAMESPACE_VARIABLE
Finally, we provide a "variable definitions" file that #includes all of the
headers in Boost using the object file mode. The user can then use header
mode for their program, and add the variable definitions file to their
project/makefile to get the required definitions.
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk