Boost logo

Boost Users :

From: Michiel Helvensteijn (m.helvensteijn_at_[hidden])
Date: 2008-07-16 19:53:23


Steven Watanabe wrote:

>> But you understand why I'd like the templated version to
>> work. I have other predicates to test
>
> Ok. The compiler can't deduce T in
>
> template <class T>
> function<bool (T)> neg(function<bool (T)> func);
>
> unless the argument is already a boost::function. No implicit conversions
> allowed.

I suspected it was too much to ask for. But I didn't know any alternative.

> template<class F>
> struct not_t {
> typedef bool result_type;
> template<class T>
> bool operator()(const T& t) { return(!f(t)); }
> F f;
> };
>
> template<class F>
> not_t<F> neg(F f) {
> not_t<F> result = { f };
> return(result);
> }

This works as expected! So it's a function object, huh. I haven't used those
before. I changed your solution in two small ways:

* I removed the unused typedef.
* I added some overloads of operator() to handle multiple parameters.

This is a useful feature to have. Thanks for your help!

-- 
Michiel Helvensteijn

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