|
Boost : |
Subject: Re: [boost] C++03 / C++11 compatibility question for compiled libraries
From: Peter Dimov (lists_at_[hidden])
Date: 2018-02-08 14:20:18
Edward Diener wrote:
> 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.
That's not going to work at all if link compatibility is desired. If you
have
class something
{
private:
CXXD::function<void()> f_;
public:
// ...
};
the layout of `something` changes between C++03 and C++11, which leads to
incredibly nasty things at runtime as objects appear at the wrong address
and the observed behavior makes no sense.
I inadvertently introduced such a problem in Boost.System when I made the
object layout dependent on whether <system_error> was available, to enable
conversions from/to std::error_code. It's not fun at all. (I have since
fixed that, and added tests that link to the library from a forced-03 or
forced-11 main.cpp. Incidentally, the layout of std::string also changes
between 03 and 11, so if such compatibility is desired, you can't use that
either.)
(But there's absolutely no need to use std::function "for std::bind
compatibility". boost::function can store std::bind just fine (and vice
versa.))
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk