opApply Vs. Ranges: What should take precedence?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Nov 16 06:29:37 PST 2009
On Mon, 16 Nov 2009 09:12:52 -0500, dsimcha <dsimcha at yahoo.com> wrote:
> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>> My Tree implementation iterates over all the
>> elements without recursion.
>
> Yes, but looking at your implementation, you have parent pointers, which
> are
> necessary anyhow for RB trees. This makes it easier. If you aren't
> using an RB
> tree, storing parent pointers counts as an inefficiency. So does
> requiring a heap
> allocation for an explicit stack every time a range object is created.
Ah yes, you are right. Good point. A range is impossible on such a
container without an allocated stack.
>> To answer the original question -- opApply should be chosen, and this is
>> not debatable. There is only *one* purpose for opApply -- to hook onto
>> foreach. If you defined both opApply and equivalent range functions and
>> range functions where chosen first, opApply would be wasted code.
>
> Agreed. I'm starting to think that this is enough of a slam-dunk to go
> in Bugzilla.
You mean opApply is not preferred? If so, it definitely should go in
bugzilla. When I see it, I'll vote it up.
-Steve
More information about the Digitalmars-d
mailing list