Boost logo

Boost :

Subject: Re: [boost] Some statistics about the C++ 11/14 mandatoryBoostlibraries
From: Peter Dimov (lists_at_[hidden])
Date: 2015-05-21 10:22:32


Niall Douglas wrote:

> In AFIO I was not surprised by shared_ptr, but I was quite surprised by my
> use of boost::bind => std::bind which did not convert over identically.
> The fix was trivial, but I still learned I had been sloppy.

There are enough subtle (and pretty much intentional) differences between
boost::bind and std::bind that the two aren't interchangeable. In the past,
when C++11 was the future, I've sometimes said that in a C++11 Boost
boost/bind.hpp will just contain namespace boost { using std::bind; }, but
it can't. This will break a ton of code.

For instance, given these two functions:

void f( int x )
{
    std::cout << "f(" << x << ")\n";
}

void f( int x, int y )
{
    std::cout << "f(" << x << ", " << y << ")\n";
}

then

    boost::bind( f, 1 )();

works, and

    std::bind( f, 1 )();

doesn't. Conversely, for most std::bind implementations, this

    std::bind<void(int)>( f, 1 )();

works (saving you a cast), but the Boost equivalent

    boost::bind<void(int)>( f, 1 )();

doesn't.

In addition, boost::bind supports a few operators, and std::bind doesn't
(although one might argue that it ought to, as it already contains the
necessary plumbing, but given that C++11 has lambdas, nobody decided to
bother.)

Even boost::mem_fn is not completely superseded by std::mem_fn.
boost::mem_fn does get_pointer(sp)->f(...) for smart pointers, whereas
std::mem_fn does (*sp).f(...). For most people this doesn't make much
difference, but there are tricks you could play with get_pointer that would
be broken.


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