
12 Mar
2007
12 Mar
'07
7:15 a.m.
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)); // Why doesn't this compile ... std::for_each(from.begin(), from.end(), if_then((_1 ->* &sample::odd) == false, std::cout << _1)); // ... but this does? Isn't it the same? std::for_each(from.begin(), from.end(), if_then(bind(&sample::odd, _1) == false, std::cout << _1)); Thanks in advance for any explanation which helps me to understand lamba expressions better, Boris