Prettier iterator implementations in D?
Reiner Pope
reiner.pope at REMOVE.THIS.gmail.com
Fri Oct 20 01:50:06 PDT 2006
The proposal looks good (as long as it creates no syntactical
ambiguities) but if we had variadic template parameters (see
http://www.generic-programming.org/~dgregor/cpp/variadic-templates.html
for a good version for C++) then you could do it much more easily with
templates:
template IterFunc(type ...)
{
alias int delegate(type ...) IterFunc;
}
and then you could just declare your iterators:
int opApply(IterFunc!(int) dg)
The best thing about this is you can easily modify it:
template IndexedIterFunc(type ...)
{
alias int delegate(size_t index, type ...) IndexedIterFunc;
}
or if the return status was instead the first function parameter (to
allow for return values, not void):
template NewIterFunc(retVal, type ...)
{
alias retVal delegate(out int status, type ...) NewIterFunc;
}
Unfortunately, this wouldn't handle 'inout' parameters, since you can't
instantiate a template with an inout parameter...
Cheers,
Reiner
More information about the Digitalmars-d
mailing list