From: Jeff Garland (jeff_at_[hidden])
Date: 2007-04-06 12:42:00
Beman Dawes wrote:
> I'll like to challenge Boosters to think about this problem a bit more,
> and I'd love to see someone who understands the challenges take, say,
> Boost.System and demonstrate how it could be packaged for either
> header-only or compiled-library use. The important goal would be to
> abstract what to done into a general set of guidelines (and any
> configuration support needed). In other words, we don't so much need a
> solution for Boost.System as for any Boost library that would benefit
> from a hybrid computation model.
I'd do it, but I just dont' have time right now. Here's the basic details.
BTW, this is detailed in Chapter 10 of Efficient C++ (Bulka/Mayhew) circa 2000
-- and I'm guessing they didn't invent it -- so, this isn't exactly a new
idea. In their case the rational was performance tuning.
Here's the basic idea:
1) in the header, conditionally include the implementation file (eg: .ipp)
2) in the implementation file, conditionally inline methods
3) in the .cpp file include .ipp and turn off the conditional inlining
For system it appears that it's essentially error_code.hpp/cpp we need to
convert. So here's what needs to be done. In error_code.hpp we add something
like this at the near the end of the file:
//make system all inline
Now, in the IPP file you'll need a macro to optionally define inline:
//code to define inline
#define BOOST_INLINE inline
and the methods need to be declared like this:
errno_ed( const error_code & ec )
To be safe at the end of the .ipp you'll probably want this:
Note that in system.cpp code looks like there's some namespace scope const
arrays and things that probably need to be turned into enums or in general
cleaned up for header only use.
So the result is that when someone does
#def BOOST_USE_OS_NATIVE_HEADERS_INLINE 1
the effect is all inlined code -- they don't need to link the library.
Now the error_code.cpp effectively just includes the .ipp with the macro
undefined. So it builds the functions into the library because BOOST_INLINE
resolves to an empty string.
So, for those that just use the usual:
they will need to link the library.
That's the essence of the technique...I'm sure someone with an hour or 2 to
goof around with it could implement it on system.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk