Boost logo

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);
                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
Literate Programming tool Interscript

Boost list run by bdawes at, gregod at, cpdaniel at, john at