Boost logo

Boost :

Subject: Re: [boost] C++03 / C++11 compatibility question for compiled libraries
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2018-02-08 09:20:19


On 02/08/18 11:50, Raffi Enficiaud via Boost wrote:
>
> Say:
>
> struct test_case {
>
> // compiled member function
> test_case(boost::function<void ()> function_to_test);
>
> #if Cpp11
> // std::function variant to ensure compatibility with std::bind
> test_case(std::function<void ()> function_to_test);
> #endif

boost::function should already be compatible with std::bind.

> private:
> boost::function<void ()> m_function_to_test;
> };
>
> This API is obviously not good at all, and for having the slightest
> chance to make this work, the 2 APIs C++11 vs C++03 should be mutually
> exclusive. This also produces 2 different incompatible shared/static
> libraries, which is even more confusing for the user as the compiler
> options should be transitively passed to the user's code, or the user
> should be aware of which library to link with.
>
> So, the questions are:
> * how do other boost developers deal with this?

In Boost.Log, I maintain linking ABI always compatible with C++03. For
example, I convert rvalue references to lvalue references in the header
and call a special internal function from the library that assumes move
semantics.

The same is possible with library components, although it may incur more
overhead. In case of boost/std::function, I would use boost::function or
even a custom function wrapper internally (the latter is useful to
remove the dependency on Boost.Function). I don't see any advantage of
using std::function.

> * what is your experience on users in terms of compilation+linking? are
> usually people aware of this problem and they compile in C++11 all the
> code including boost?

There is a large class of use cases where the user links against Boost
that is built by someone else. In Linux, it is typical to rely on the
Boost version shipped with distro. On Windows, I presume, some users
prefer our pre-built binaries. So the use case when the headers and the
library are used with different C++ version settings are real and a good
library should account for that.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk