$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: williamkempf_at_[hidden]
Date: 2001-08-15 20:26:31
--- In boost_at_y..., John Max Skaller <skaller_at_m...> wrote:
> 
> > 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.
For specific uses this works, for a generic concept it's got some 
major short comings.  You can't have multiple conditions/predicates 
or varying actions, etc.  I just don't think you can shorten the 
three lines down any more with out compromising on utility.  In other 
words, another layered object would be fine, but we need the general 
classes and pattern as well.
Bill Kempf