Boost logo

Boost Users :

Subject: [Boost-users] lambda : fabs( x - y )< eps
From: er (er.ci.2020_at_[hidden])
Date: 2011-03-10 19:40:52


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.

#include <cmath>
#include <boost/function.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/numeric/conversion/bounds.hpp>

typedef boost::function<double(double)> f1_;
typedef boost::function<double(double, double)> f2_;
typedef boost::function<bool(double)> g_;

double eps = boost::numeric::bounds<double>::smallest();
f2_ f2 = lambda::bind( f1_( fabs ), lambda::_1 - lambda::_2 ) ;
g_ g = ( eps > lambda::_1 );

BOOST_ASSERT( lambda::bind( g, lambda::bind( f2, lambda::_1, lambda::_2
) )( 0.0, 0 * eps ) );
BOOST_ASSERT( !lambda::bind( g, lambda::bind( f2, lambda::_1, lambda::_2
) )( 0.0, eps ) );


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