Boost logo

Boost Users :

Subject: Re: [Boost-users] lambda : fabs( x - y )< eps
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-03-10 23:14:42


AMDG

On 03/10/2011 04:40 PM, er wrote:
>
> I'm submitting this in case someone easily spots a less verbose
> representation of fabs( x - y )< eps than the one shown below and
> would like to share it. Using lambda (or variants) only (I know I can
> write my own functor class). Thanks.

How about using the attached cmath.hpp for phoenix?

#include <cmath>
#include <boost/function.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include "cmath.hpp"

int main() {
double eps = 0.000001;
using namespace boost::phoenix::arg_names;
boost::function<bool(double, double)> f = fabs(_1 - _2) < eps;

BOOST_ASSERT( f( 0.0, 0 * eps ) );
BOOST_ASSERT( !f( 0.0, eps ) );
}

In Christ,
Steven Watanabe




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