|
Boost Users : |
From: misiu (misiu75_at_[hidden])
Date: 2007-03-12 04:48:33
Hello,
Could you please tell me how to compare two boost::function objects
packet with boost::ref. I have container which has boost::function
elements and to add elements is not a problem but to remove particular
one I don't know how to do that (compare two boost:ref-s). The problem
is shown in the code below.
Regards,
Bartek
//code
#include <iostream>
#include <list>
#include <boost/ref.hpp>
#include <boost/function.hpp>
struct test{
int a;
void operator() (int aa)
{ a += aa; }
};
struct function_list {
std::list<boost::function<void (int v)> > fun_list;
void add(boost::function<void (int v)> fun)
{
fun_list.push_back(fun);
}
void remove(boost::function<void (int v)> fun)
{
std::list<boost::function<void (int v)> >::iterator iter;
//HOW TO IMPLEMETN THIS FIND_IF?
//std::find_if(fun_list.begin(), fun_list.end(), MISSING_PART);
if(iter != fun_list.end())
fun_list.erase(iter);
}
};
int main(int argc, char **argv) {
test a, b;
function_list f;
f.add(boost::ref(a));
f.add(boost::ref(b));
//DOES NOT WORK
f.remove(boost::ref(a));
}
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