RFC on range design for D2
Fawzi Mohamed
fmohamed at mac.com
Fri Sep 12 08:41:45 PDT 2008
I like the new proposal much more than the first.
I believe you will be able to use it successfully in std.algorithm.
I still would have preferred an operation like a sameHead or
compareHeadPosition (that might or might not return the order, but at
least tests for equality) so that upon request (-debug flag?) one would
be able to make all range operation safe (with overhead) in a generic
way, but it is up to you.
I what I really care about is the following:
I want foreach magic on all objects that support .done and .next, even
if they are not ranges.
foreach is about iteration, iteration needs only .done and .next (a
generator, iterator whatever), and it should work with that.
Do not force the range idea on foreach iteration.
foreach is a language construct, not a library one and should allow for
maximum flexibility.
As extra nicety as each generator/iterator/range returns just one
object I would like to be able to do:
// i counts starting from 1, j iterates on iterJ and in parallel k
iterates on a.all
foreach(i,j,k;1..$,iterJ,a.all){
//...
}
and have it expanded to
Range!(int) r1=1..$;
alias iterJ r2;
typeof(a.all) r3=a.all;
while(!(r1.done || r2.done || r3.done)){
typeof(r1.next) i=r1.next;
typeof(r2.next) j=r2.next;
typeof(r3.next) k=r3.next;
//...
}
Fawzi
More information about the Digitalmars-d-announce
mailing list