Sergey Gromov wrote:
Mon, 19 Jan 2009 06:15:06 -0800, Andrei Alexandrescu wrote:
Michel Fortin wrote:
Other possible things involves a rudimentary profiler (checking for the
elapsed time at each loop iteration), or a progress monitoring template
(notifying another thread of the progress of a particular task).
foreach (task; progessUpdater(timeProfiler(listOfTasks)))
{ ... }
You can't compose iteration based on opApply. How would progessUpdater
and timeProfiler look like? This example pretty much transforms your
argument into mine :o).
I think "can't" is a bit strong a statement. Let's see:
With opApply:
class progressUpdater(Collection)
{
this(Collection c)
{
collection_ = c;
}
int opApply(int delegate(ref ElementType!(Collection)) dg)
{
composed_ = dg;
return collection_.opApply(&fancifier);
}
private:
int fancifier(ref ElementType!(Collection) el)
{
globalOnProgress();
return composed_(el);
}
Collection collection_;
int delegate(ref ElementType!(Collection)) composed_;
}
I see. Very ingenious! Reversed flow of control all the way. Thanks.
Andrei