opApply and const

Daniel Keep daniel.keep.lists at gmail.com
Sun Dec 9 18:42:48 PST 2007



Bill Baxter wrote:
> Daniel Keep wrote:
>> My apologies.  It *does* actually support arbitrary opApply()s.  What
>> probably *doesn't* support are types with more than one opApply.  Can we
>> get a list of overloads with D 2.0 yet?
> 
> I like it (no surprise since I also like Python).
> How about reverse?  Can you cook up a reversed() template that would use
> an opApplyReverse if it exists or else forward iterate into a buffer and
> reverse iterate over that?  Or maybe creating a big temp buffer silently
> isn't such a hot idea...

Well, this is how Python does it, I believe.  The position there appears
to be: better to be possible and inefficient than not possible at all.

Really, I think it's somewhat surprising that D doesn't have *any*
iteration tools whatsoever.  If I weren't already so busy with other
things, I'd be tempted to write some myself.  And there's always the
chance that downs has written stuff already (that no one else can read
without screaming in pain.)  ;)

Still, I think one of the biggest hurdles to writing a good iterator
toolkit is how opApply is implemented in D.  Because of the callback
design, you can't do anything with resumable iterators, you can't do
multiple iterations in lockstep... it's a bit of a pity that opApply
is so firmly entrenched in the language.  Oh well; I suppose there's
always D 3.0.  :)

	-- Daniel



More information about the Digitalmars-d mailing list