$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] Question in usage of boost::bind
From: Alan M. Carroll (amc_at_[hidden])
Date: 2009-02-02 14:45:33
1) find_if expects a unary functor returning bool. You are passing a binary functor. _1 will be the element in the vector, but what did you think would be passed for _2?
2) CompareByVal should either be static or not have the pointer argument. There's no need to pass "this" by hand. The first argument to the bind of a method is an explicit "this" but the method is just a method, it is not aware that it has been called from Boost.bind.
At 12:29 PM 2/2/2009, you wrote:
>Below is an example that fails to compile. I have a vector of pointers to a 
>templated class and I need to use find_if. My understanding of boost::bind. is 
>that the first argument, when binding member function, is an explicit "this" 
>pointer,
>that should be A* in my case. 
>
>Any help in explaining what I am doing wrong will be greatly appreciated.
>
>template<typename T> class A
>{
>        T _val;
>public:
>        A(T val) : _val(val){};
>        T Val() {return _val;}
>
>        bool CompareByVal(A<T>* a, int iType, T ofval)
>        {
>                return ( (a != NULL) && (iType == 1) && (a->Val() == ofval) );
>        }
>};
>
>int _tmain(int argc, _TCHAR* argv[])
>{
>        std::vector<A<int>*>  a;
>
>        std::find_if (a.begin(), 
>                       a.end(), 
>                       boost::bind(&A<int>::CompareByVal, _1, _2, 1,1));
>}
>
>
>
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://listarchives.boost.org/mailman/listinfo.cgi/boost-users