|
Boost Users : |
Subject: Re: [Boost-users] Tips on implementing a function queue with unique queue items (compare function problem)
From: Peter Åberg (aberg_at_[hidden])
Date: 2009-05-14 09:22:16
Excellent, spot on, thanks gurus :-)
/Peter Åberg
Steven Watanabe wrote:
> If the caller of push knows the type of the function object,
> then you can template the push function.
>
> template<class F>
> void push(const F& f) {
> if(std::find_if(queue.begin(), queue.end(), f == _1) != queue.end()) {
> queue.push_back(item);
> }
> }
>
> This is going to be pretty inefficient because of the linear search,
> but the same idea applies if you want to store the function objects
> in a data structure that supports faster lookup.
>
> In Christ,
> Steven Watanabe
>
>
Nat Goodspeed Wrote:
> You're right that we can't compare two boost::function objects, but it
> *is* permitted to compare a boost::function with an rvalue that could
> initialize it. If you make your push() method a template accepting an
> argument of arbitrary type, presumably you could compare each existing
> item with that new value before storing it into the deque.
>
>
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