Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-05-13 07:32:39

From: "David Abrahams" <david.abrahams_at_[hidden]>
> Was the feature mentioned here
> ever documented? If
> so, I don't see it. If not it would be really great to get it into the
> documentation on the release candidate branch before we release boost
> 1.28.0...

No, the feature isn't documented yet. It's still labeled "experimental" in
my mind... I'll document it post-release.

> ...continued...
> BTW, the important question I was trying to answer was: if I have such a
> binder, what must the argument to the function which gets the value be?
> std::pair<int,int> x(1,2);
> bind(&std::pair<int,int>::first, _1)(&x); // legal?

Legal, except that &x is an rvalue and cannot be forwarded. The argument
follows the typical mem_fn rules, i.e. can be a pointer, reference, or a
smart pointer with get_pointer defined.

#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <utility>

void noop(std::pair<int, int> *)

int main()
    std::pair<int, int> x(1, 2);
    boost::bind(&std::pair<int, int>::first, _1)(x);

    std::pair<int, int> * p = &x;
    boost::bind(&std::pair<int, int>::first, _1)(p);

    boost::shared_ptr< std::pair<int, int> > p2(&x, noop);
    boost::bind(&std::pair<int, int>::first, _1)(p2);

(BTW why is the Reply-To header broken?)

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