Boost logo

Boost Users :

From: Michael Fawcett (michael.fawcett_at_[hidden])
Date: 2008-02-15 10:07:21


On Fri, Feb 15, 2008 at 3:14 AM, Jean-Pierre Bergamin <james_at_[hidden]> wrote:
>
> Could there be a way to provide a function object safe_logical_and that only
> evaluates the second argument if the first one is true?

I've written something like that before as:

// warning, code typed in e-mail
template <typename F0, typename F2>
struct and_
{
   F0 first;
   F1 second;

   and_(F0 f0, F1, f1) : first(f0), second(f1) { }

   bool operator()() const
   {
      return first() && second();
   }
};

but if you needed function arguments that weren't available to be
bound at and_ construction time you'd have to do some more trickery.
This would also scale well using variadic templates.

--Michael Fawcett


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