On Fri, 27 Apr 2001, Angus Leeming wrote:

> I'm trying to get to grip with functors, but it's a long, hard struggle. Can 
> some C++ guru explain to me why my approach, below, is a pile of poo?
> 
> Many thanks,
> Angus
> 
> 
> 
> // 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 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));

It isn't a function object as far as I can see ;)

e.g. in some other code of mine, a function object looks like this :

/// function object for matching against id
class Message_id_eq : public unary_function<Message, bool> {
        int id_;
        public:
                explicit Message_id_eq(int id) : id_(id) {}
        bool operator()(Message * m) const {
                return m->id() == id_;
        }
};                                                                                     
                                                      

Hope this helps !

john

-- 
"Don't follow leaders, watch your parking meters"
        - The Bob

Reply via email to