|
Boost : |
Subject: Re: [boost] C++03 / C++11 compatibility question for compiled libraries
From: Edward Diener (eldiener_at_[hidden])
Date: 2018-02-08 14:03:18
On 2/8/2018 3:50 AM, Raffi Enficiaud via Boost wrote:
> 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
> C++11.
> 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.
>
> 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
>
> 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?
> * 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.
As far as which library to use, depending on the compiler/version
available, either boost or std, of two very similar libraries, this is
what my Cxx_dual library (https://github.com/eldiener/cxx_dual) is all
about. But others did not like it preferring instead to roll their own
solution or more simply to use Boost at all times because it is
available. I naturally prefer my own solution but of course I am biased.
>
> Thanks,
> Raffi
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk