Boost logo

Boost :

Subject: [boost] C++03 / C++11 compatibility question for compiled libraries
From: Raffi Enficiaud (raffi.enficiaud_at_[hidden])
Date: 2018-02-08 08:50:07

Dear list,

I have a technical question I do not know how to address, and I would
like to know how people deal with this.

To put things in the background: boost.test uses heavily boost::function
and boost::bind, however I would like to use in some circumstances
std::function and std::bind, which are, for instance, variadic.

Boost.test is compiled with b2. I believe if the user does not pass
additional parameters to the build, the default is to use whatever is
provided in the Jamfile, that compiles the static and shared libraries
in C++03 mode.

If the user of boost.test compiles in C++03, it is ok if the library is
used in a C++11 project. The other way is obviously not true.

Now, in the headers of boost.test, I can detect for the compiler
version, and depending on the language settings, activate an API that is
OTOH, if I do not want users to be confused, this API should be header
only. But this hardly work in practice, as the C++03 and C++11 APIs are
usually not separable.


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);

    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?
* 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?
* is there any better option? All the other options I see are even worse.


Boost list run by bdawes at, gregod at, cpdaniel at, john at