|
Boost : |
From: Trey Jackson (tjackson_at_[hidden])
Date: 2003-02-20 18:32:02
All,
Using boost 1_29_0, Linux gcc3.2.1.
Just started using boost::bind, like it a lot.
I'm playing around with a little work crew,
which just queues up data, then calls the function
on them later.
bind does a great job of packaging up functions for later use.
is there an analogue for the arguments to those functions?
i.e. a C++ version of
(apply 'fn '(arg1 arg2 arg3))
here's what i can do today
,----------------
| struct X {
| bool f(int a, int b);
| };
|
| X x;
|
| int i = 5;
| int j = 10;
|
| // Can do this today, yay!
| bind(&X::f, &x, _1, j)(i);
|
| // create crew
| work_crew<int> mycrew(bind(&X::f, &x, _1, j));
| // add work
| mycrew.add(9);
| mycrew.add(42);
| mycrew.add(29232);
|
| // do work
| mycrew.dowork(); // calls x.f(9, 10), x.f(42,10), x.f(29232,10)b
`----------------
I'd like to be able to do something like:
,----------------
| work_crew<???> mycrew(bind(&X::f, &x, _1, _2));
|
| mycrew.add( ?? 9 10 ?? );
| mycrew.add( ?? 42 10 ?? );
| mycrew.add( ?? 29232 10 ?? );
|
| // do work
| mycrew.dowork(); // STILL calls x.f(9, 10), x.f(42,10), x.f(29232,10)b
`----------------
Where obviously I have to do something special to package up the
arguments to the function object that's been created.
Is it possible without a huge amount of coding?
Thanks,
TJ
ps.
My crew class is something like this:
template <class DataType, class FunctionType = boost::function1<void, DataType> >
class work_crew {
std::list<DataType> queue_;
typename FunctionType engine_;
public:
work_crew(FunctionType &tocall);
void add(DataType d) { queue_.push_front(d); };
void dowork() { for(iter = queue_.begin(); iter != queue_.end(); ++iter) engine_(*iter);};
};
-- Trey Jackson tjackson_at_[hidden] "The mirror doesn't lie. I *am* getting sexier." -- Dogbert
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk