
On Mon, Jul 21, 2008 at 9:55 PM, vicente.botet <vicente.botet@wanadoo.fr> wrote:
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; }
Sorry, I'm not explaining myself too well. Yes your example compiles, provided the predicate is an adaptable functor (typedefs argument_type). If the predicate is a raw function then the ptr_fun adaptor is required, but that will ONLY work for a raw pointer. My difficulty is in finding a direct solution that works for all cases. Regards, Rob.