|
Boost : |
From: John Max Skaller (skaller_at_[hidden])
Date: 2001-08-15 20:17:28
> Well, the preferred method shortens the pattern a little:
>
> {
> mutex::scoped_lock lock(m);
> cv.wait(lock, pred);
> action();
> }
>
> It's not really possibly to shorten things beyond this.
Well, you can write:
template<class Action, class Pred> struct caction
{
void run() {
mutax.scope_lock lock(m);
cv.wait(lock, pred);
action();
}
caction(mutex &m_a, Pred const &pred_a, Action &action_a)
: m(m_a), pred(pred_a), action(action_a) { run(); }
mutex &m;
Pred const &pred;
Action &action;
};
mutex m; ..
Pred pred(..);
Action action(..);
cation<Action, Pred>(m, pred, action);
Of course, the templatisation is basically useless due to the lack
of nested function closures, which force you to declare the types
Pred and Action out of line (instead of defining inline anonymous
functions like you would in a functional programming language).
But then, by this argument, STL is basically rendered useless
by lack of core language support, so YMMV.
-- John (Max) Skaller, mailto:skaller_at_[hidden] 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 New generation programming language Felix http://felix.sourceforge.net Literate Programming tool Interscript http://Interscript.sourceforge.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk