
----- Original Message ----- From: "Robert Jones" <robertgbjones@gmail.com> To: <boost@lists.boost.org> Sent: Monday, July 21, 2008 6:01 PM Subject: [boost] [lambda] Writing pass-through 'standard' algorithms
I encountered this difficulty in the context of passing lambda functors, but on reflection I don't the lambda aspect particularly matters.
Consider this templated function
template <typename InputIterator, typename Predicate> inline bool all_if( InputIterator first, InputIterator last, Predicate predicate ) { return std :: find_if( first, last, std :: not1( predicate ) ) == last; }
Obviously the intent is to enquire if all members of a range satisfy the predicate.
Now, as is, this doesn't compile, because it needs ptr_fun() on the predicate, but then a couple of things come up.
What exactly do not compiles? I have not founf ptr_fun on your function. If predicate is a predicate functor this should compile, isn't it? The following compiles: template <typename InputIterator, typename Predicate> inline bool all_if( InputIterator first, InputIterator last, Predicate predicate ) { return std::find_if(first, last, std::not1( predicate ) ) == last; } struct IntGreaterThanThree : public std::unary_function<int, bool> { bool operator() (int x) const { return x > 3; } }; int main() { std::vector<int> L; L.push_back(5); L.push_back(8); L.push_back(4); L.push_back(10); std::cout << "=" << all_if (L.begin(), L.end(), IntGreaterThanThree()) << std::endl; return 0; } Vicente