Boost logo

Boost :

Subject: Re: [boost] [Config] Support for switching between std:: and boost:: equivalents.
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2015-06-06 08:26:50


On Friday 05 June 2015 21:07:20 Edward Diener wrote:
> On 6/5/2015 6:35 PM, Andrey Semashev wrote:
> >
> > In general, you won't get away with just macros, as autolinking is only
> > present in MSVC & friends. This would also affect build system scripts.
> >
> > Suppose I'm a (Boost) library writer; the library has a compiled part and
> > I'm writing a Makefile/Jamfile. If I'm using these macros, I still have
> > to know when to link and when not to link with Boost libs. This can be
> > rather tricky as not only compiler versions should be checked but also
> > their options; and it also needs to be in sync with Boost.Config. The
> > same happens when I'm a user of a (Boost) library that uses these macros,
> > only it becomes more difficult to be in sync with Boost.Config. My point
> > is that since these macros don't actually abstract me away from the
> > configuration, why would I use them?
>
> They abstract you away from having to write complicated code which
> caters to whether or not a C++ standard library equivalent to a Boost
> library is available or not. They don't relieve the responsibility of a
> built library from naming itself in such a way that those linking with
> the library can do so successfully if auto-linking is not available.

I think you missed my point above. It's not about naming the library, its
about the solution being incomplete to the point when you are not saved much
by using these macros.

I've looked at the headers, and a similar code in a few Boost libraries that
does the same - there's nothing complicated there. I believe that implementing
a similar logic in a Jamfile to link with Boost libraries only when needed
would be much more difficult and error prone.

> The problem goes beyond the use of my macro system. Are we going to give
> library developers the choice of whether they can use the C++ standard
> library equivalent to a Boost library or not ?

My current view on this is if you're writing a C++11 library it's fairly
logical for you to use STL11. No macros are needed for that. If you aim for
C++03 compatibility, you should use STL03 and Boost where STL lacks something.
Admittedly, this approach still has the library interoperability problem but
at least your API and ABI are stable and do not depend on compiler options.

I realize that someone might want to switch to C++11 components when
available, for example, to reduce dependencies on other Boost libraries. But I
believe this should only be done in a way that does not affect API and ABI of
the library.

> > It's more likely that Boost is compiled in one mode and distributed in a
> > standard package (say, with a Linux distro) and I'm building my app
> > locally
> > with that Boost. Most Linux distros build Boost with default compiler
> > options which means C++03. If these macros affect Boost libraries ABI I
> > will no longer be able to build my app in C++11 mode.
>
> The macros don't determine the mode; compiler options do that. I believe
> Boost is going to have to work out anyway, if it has not already done
> so, a difference in final naming between a library built with or without
> C++11/C++14/C++17 support if that library supports building in more than
> one C++ mode.

I think the current solution is to provide ABI that does not depend on C++
mode. This is what I'm doing in Boost.Log, and AFAIR there was a bugfix in
Boost.Filesystem that also followed this direction. I can also remember a fix
in Boost.Range that removed the difference in binary layout of iterator_range
between release and debug builds - not a C++ mode issue, but similar enough.
One may argue that this approach is limiting, and I would agree, but this has
worked best for the downstream so far.

> Arguing that a facility is bad because it makes it easier to use either
> a C++ standard library equivalent to a Boost library or the Boost
> library itself, as you and Peter have done, is counterproductive IMO.

Maybe. That's why I apologized for not being helpful.

I understand your argument - after all C++ allows you to shoot yourself in the
foot, so do your macros. But unlike C++ they don't make it really difficult.
Maybe we just need a documented policy of use of these macros so that they
don't get misused. Maybe we need testing, when the library and tests are
compiled in different C++ modes. I don't know.

> The same problems would exist as soon as anyone decides to use one or
> the other in their code even without my macros. I can't view it as being
> better to only use Boost libraries in Boost library code simply because
> it creates a single variant of a library. Eventually people will become
> tired of not having the ability to use C++ standard library equivalents
> in Boost code, and this will become more so if Boost moves to a more
> modular distribution system. What will you tell people ? That they must
> hard-code whether to use a Boost library or a C++ standard equivalent
> library in their code ? And if the C++ standard library equivalent is
> not available their library must be unusable in that environment ? I
> don't think Boost is going to get very far in that direction.

Some of these questions I've answered above. I'll just add that developers
have always had to find balance between maintainability and usability and I
don't think it'll change any time soon. Personally, for my projects I have
decided that trying to use STL11 opportunistically doesn't worth the hassle.
Even for C++11 projects I still prefer Boost to STL in some cases. But your
mileage may wary, of course.

> I acknowledge the concerns which you have with a built library which can
> be compiled in different C++ modes. My point of view is different in
> that Boost has to face the fact that for any given library XXX it may
> want to use a Boost library in one C++ mode, presumably C++03, and the
> C++ standard equivalent of that Boost library in another C++ mode,
> presumably C++11 or above. For this different naming conventions for
> such a dual mode ( or more ) built library has to be created to
> accomodate the situation. Either that or the library itself must be
> treated under a different name for each mode in which it can be built,
> but that's not a problem which my macro system itself can solve.

Producing different library names for different C++ modes has been discussed
before but I don't quite remember the outcome of that discussion. Clearly, it
has not been implemented.

By the way, Boost is not the only project that attempts to maintain stable ABI
regardless of the C++ mode. libstdc++ is also doing that, for example.


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