|
Boost Users : |
From: Boris (boriss_at_[hidden])
Date: 2007-03-12 09:48:52
On Mon, 12 Mar 2007 15:21:33 +0200, Boris <boriss_at_[hidden]> wrote:
> struct sample
> {
> int i;
> sample(int i) : i(i) { }
> bool odd() { return i % 2; }
> };
>
> template <class T, class U>
> std::basic_ostream<T, U> &operator<<(std::basic_ostream<T, U>& ostr,
> sample s) { return ostr << s.i; }
>
> std::vector<sample> from;
> std::vector<sample> to;
>
> from.push_back(sample(1));
> from.push_back(sample(2));
> from.push_back(sample(3));
>
> std::for_each(from.begin(), from.end(), if_then(bind(&sample::odd, _1) ==
> false, bind(&std::vector<sample>::push_back, to, _1)));
>
> VC++ 8 displays dozens of error messages with the first one:
>
> error C2665: 'boost::lambda::function_adaptor<Func>::apply' : none of the
> 2 overloads could convert all the argument types
>
> Can anyone tell me how I need to change the lambda expression?
As usual I found the answer immediately after having sent the question -
it must be &to:
std::for_each(from.begin(), from.end(), if_then(bind(&sample::odd, _1) ==
false, bind(&std::vector<sample>::push_back, &to, _1)));
Boris
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