
On 15 May 2015 at 20:29, Peter Dimov wrote:
Indeed, APIBind is there to ensure that your library X built against boost::function doesn't collide with your library X build against std::function in the same translation unit.
Does this actually work? Because I've trouble visualizing it based on this description.
OK, X built against boost::function has
namespace boost { namespace foo {
template<class R, class... Args> using function = boost::function<R(Args...)>;
} }
and X built against std::function has
namespace boost { namespace foo {
template<class R, class... Args> using function = std::function<R(Args...)>;
} }
Correct.
Why do those two not clash? I'm not seeing it. Perhaps the two 'foo' namespaces are actually different?
Correct: namespace boost { namespace foo { inline namespace ???_boost_??? { template<class R, class... Args> using function = boost::function<R(Args...)>; } } namespace boost { namespace foo { inline namespace ???_std_??? { template<class R, class... Args> using function = std::function<R(Args...)>; } } } The inline namespace is some mangled representation reflecting the different bind in the implementation. In the above boost::foo::function will now conflict if used that way in the same TU. This is why under APIBind you namespace alias an exact version and mangling into your using namespace: namespace user { namespace foo = ::boost::foo::???_std_???; } Or as APIBind does it: namespace user { namespace foo = BOOST_FOO_NAMESPACE; } ... as APIBind lets you reconfigure and reinclude the header for a library arbitrarily.
But if so, does this not lead to a combinatorial explosion when more than one component can use either its Boost or standard version? function, bind, shared_ptr, regex... that's 16 combinations so far.
Correct. This was raised in Q&A in the talk too. I would suggest pruning the combinations in this case to a reasonable subset, though I have a python script which generates the macro boilerplate for you so you don't have to. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/