Boost logo

Boost :

From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-07-21 17:07:16


On Mon, Jul 21, 2008 at 9:55 PM, vicente.botet <vicente.botet_at_[hidden]>
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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk