Boost logo

Boost Users :

From: Âëàäèìèð Êðàñîâñêè (vkrasovsky_at_[hidden])
Date: 2004-07-29 02:15:48


Hello Mattias,

Wednesday, July 28, 2004, 6:19:21 PM, you wrote:

MB> Hello!

MB> I am new to the boost lambda library so this might be a naive question.
MB> Here goes. This is what I want to do:

MB> class Foo {
MB> public:
MB> int bar() { return 42; }
MB> };

MB> int main()
MB> {
MB> std::vector<Foo> v;
MB> v.push_back(Foo());

MB> count_if(v.begin(), v.end(), boost::bind(&Foo::bar, _1) == 42);

MB> return 0;
MB> }

You may try something like this:

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

class Foo {
public:
        int bar() { return 42; }
};

int main(int argc, char* argv[])
{
        std::vector<Foo> v;
        v.push_back(Foo());

        size_t c =
                count_if(
                        v.begin(),
                        v.end(),
                        boost::bind(
                                std::equal_to<int>(),
                                boost::bind(Foo::bar, _1),
                                42
                        )
                );

        return 0;
}

This compiles ok on MS VC7.1, but it doesn't use lambda, only bind.

-- 
Best regards,
 Âëàäèìèð                            mailto:vkrasovsky_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net