> // I have some data:
> vector<double> somedata = ...;
> 
> // References to some of this data are placed in a list...
> typedef vector<double>::iterator BinItem;
> list<BinItem> bl = ...;

[I asssume you know that vector<>::iterators can be invalidated by certain
circumstances like growing the vector or deleteing an item before the one
pointed to by the iterator - you dont' do that here anyway...]
 
> // I want to search this list to find if it contains data of a particular 
> value, +- some tolerance value:
> double const tol = 1.0e-08;
> double const desired_value = ...;
> 
> find(bl.begin(), bl.end(), CompareWithinTolerance(desired_value, tolerance));
> 
> // My question is, is there a better way to define the functor than this?
> // Let's ignore the "make it generic" arguments for now. I'm trying to
> // understand how these things work.
> namespace {
>       struct CompareWithinTolerance {
>               CompareWithinTolerance(double const & dv, double t)
>                       : desired_value(dv), tol(t) {}
>               
>               double desired_value;
>               double tol;

You need an

      bool operator()(double a) const {
         return (desired_value - a) < tol && (a - desired_value) < tol;
      }

here, which will called with every item of your vector.

Andre'

-- 
Andr� P�nitz ............................................. [EMAIL PROTECTED]

Reply via email to