DMD 0.170 release
Sean Kelly
sean at f4.ca
Tue Oct 17 21:18:39 PDT 2006
Walter Bright wrote:
>
> So I've been interested in having D algorithms and collections not need
> iterator types at all. I've been experimenting with doing STL's
> algorithms in D, and it became clear that to make them complete, reverse
> iteration was necessary. foreach handles forward iteration, and opIndex
> handles random access. Various ways of doing reverse traversal without
> core support always seemed to involve creating dummy classes and other
> hackish stuff. Promoting it to a supported statement makes it pretty
> clean for the user to understand and use.
>
> Essentially, I think foreach_reverse is the missing piece to be able to
> implement all of STL's algorithms code for D.
I think I agree, but for the sake of argument, how would D handle 'find'
operations on sequences that don't support opIndex? At some point, a
generalizable bookmark is almost necessary for a faithful implementation
of some C++ algorithms. Also, many of these algorithms also require
iteration across two sequences simultaneously, which doesn't map very
cleanly into foreach. Consider a substring-style find operation
(std::search), for example, where both the pattern and target types do
not support opIndex or opSlice. I might argue that it's a bit silly or
unrealistic to desire such an operation, but the C++ algorithm library
does support it.
Sean
More information about the Digitalmars-d-announce
mailing list