Any chance to call Tango as Extended Standard Library
Sergey Gromov
snake.scaly at gmail.com
Mon Jan 19 15:11:15 PST 2009
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_;
}
With ranges:
struct progressUpdater(Collection)
{
this(Collection c)
{
collection_ = c;
}
typeof(collection_.head) head()
{
return collection_.head;
}
void next()
{
globalOnProgress();
collection_.next();
}
bool empty()
{
return collection_.empty;
}
private Collection collection_;
}
Cannot see anything impossible with both.
More information about the Digitalmars-d
mailing list