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-10 17:00:30

On 02/10/18 18:43, Peter Dimov via Boost wrote:
> But, if you really wanted to know, libstdc++ in a situation like the
> above (when the function has to be virtual because it's f.ex. specified
> that way by the standard) does something like the following:
> #if cpp11
> virtual int __f( boost::function<int ()> const& F ) = 0;
> virtual int f( std::function<int ()> const& F ) = 0;
> #else
> virtual int f( boost::function<int ()> const& F ) = 0;
> virtual int __f( std::function<int ()> const& F ) = 0;
> #endif
> except of course we don't have std::function in C++03 mode, so even
> declaring __f will be a problem.

If you rely on the particular algorithm of vftable slot allocation,
declaring is not a problem - you can declare pretty much whatever
virtual function. It's not going to be called anyway and its sole
purpose is to reserve a particular slot.

libstdc++, though, has the luxury of knowing the slot allocation
algorithm, as well as binary layout of its own components (e.g.
std::string vs. std::__cxx11::string), so it can do stuff like that and
even better (e.g. it can actually transparently support both string
types, where needed). In an external generic library like Boost, this is
a pretty risky thing to do. Just always using ABI-stable types in the
link interface seems more preferable.

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