On 12/9/07, Bill Baxter <dnewsgroup@billbaxter.com> wrote:
> const int opApply(int delegate(ref const T)) {...}
And "ref const T" seems a bit of an oxymoron anyway.
I can bring it down to eight. You shouldn't have to deal with
invariant classes. These can't really exist in D, since
invarant C = new C;
will fail to compile, and there is no "inew".
But yeah - eight versions of the same function is too much. Is there
any way we can narrow it down to one? (One that actually works, in all
eight cases?)

On 12/9/07, Robert Fraser <fraserofthenight@gmail.com> wrote:
> Janice Caron wrote:
> > invarant C = new C;
> >
> > will fail to compile, and there is no "inew".
>
> invariant C = cast(invariant) new C();
I didn't forget that, I just didn't see the point of it.
What I did forget, though, is invariant structs. Now they do make
sense! And surely opApply has to work for those, too.
So we're back up to twelve again!

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...

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