Does D have too many features?

Steven Schveighoffer schveiguy at yahoo.com
Mon Apr 30 13:33:51 PDT 2012


On Mon, 30 Apr 2012 15:50:00 -0400, Walter Bright  
<newshound2 at digitalmars.com> wrote:

> I'm surprised nobody has mentioned opApply. That was a good idea at the  
> time, but Ranges are a superior solution. I'd like to see new code not  
> use opApply. It's a dead end, though it'll still be supported for a long  
> time.

I think we've already covered this -- opApply does things that ranges  
could never do.  I think they can both live in harmony.  It's not even  
close to a dead end.  I look at opApply as foreach on a range with a  
stack-allocated context specifically for iteration.  Then of course, you  
can do stack-based traversal, which is not really possible for ranges.

A trivial example:

foreach(dchar d; "longstring") {}

treating "longstring" as a range, you cannot possibly get the performance  
opApply has (although, you have to be able to inline both the opApply call  
and the delegate calls, currently not supported for the above code), as it  
has to decode each dchar *twice*, once for getting d, and once for popping  
it off the front.

-Steve


More information about the Digitalmars-d mailing list