Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-04-16 14:07:50


From: "Sean Parent" <sparent_at_[hidden]>
> One feature that I think is missing from functional (and bind) is the
> ability to deal with a pointer or reference to a data member.
>
> The behavior should be similar to binding to a pointer to a member
function
> - it generates a functor that given an object returns the value of the
> member.
>
> One example use would be doing a lookup on an array of pairs of an int and
a
> float:
>
> find_if(first, last,
> compose_f_gx(bind(equal_to<int>(), value, _1),
> mem_ref(&pair<int, float>::first));

This feature is supported by the version of mem_fn (and bind) in the CVS:

#include <boost/bind.hpp>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;
using namespace boost;

vector< pair<int, float> > v;

int main()
{
    int value = 5;
    find_if(v.begin(), v.end(), bind(equal_to<int>(), value, bind(&pair<int,
float>::first, _1)));
}


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